Skip to content

Commit 8139404

Browse files
velero is working on eks with web identity setup
1 parent c92ea1f commit 8139404

File tree

9 files changed

+280
-32
lines changed

9 files changed

+280
-32
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v3.0.1
3+
rev: v3.1.0
44
hooks:
55
- id: check-added-large-files
66
args: ['--maxkb=500']
@@ -17,7 +17,7 @@ repos:
1717
- id: detect-aws-credentials
1818
args: ['--allow-missing-credentials']
1919
- repo: git://github.com/antonbabenko/pre-commit-terraform
20-
rev: v1.30.0
20+
rev: v1.31.0
2121
hooks:
2222
- id: terraform_fmt
2323
- id: terraform_docs

README.md

Lines changed: 86 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,44 @@
1-
# Module Blueprint
2-
3-
Terraform module blueprint
4-
5-
![](https://github.com/terraform-module/terraform-module-blueprint/workflows/release/badge.svg)
6-
![](https://github.com/terraform-module/terraform-module-blueprint/workflows/commit-check/badge.svg)
7-
![](https://github.com/terraform-module/terraform-module-blueprint/workflows/labeler/badge.svg)
8-
9-
[![](https://img.shields.io/github/license/terraform-module/terraform-module-blueprint)](https://github.com/terraform-module/terraform-module-blueprint)
10-
![](https://img.shields.io/github/v/tag/terraform-module/terraform-module-blueprint)
11-
![](https://img.shields.io/issues/github/terraform-module/terraform-module-blueprint)
12-
![](https://img.shields.io/github/issues/terraform-module/terraform-module-blueprint)
13-
![](https://img.shields.io/github/issues-closed/terraform-module/terraform-module-blueprint)
14-
[![](https://img.shields.io/github/languages/code-size/terraform-module/terraform-module-blueprint)](https://github.com/terraform-module/terraform-module-blueprint)
15-
[![](https://img.shields.io/github/repo-size/terraform-module/terraform-module-blueprint)](https://github.com/terraform-module/terraform-module-blueprint)
16-
![](https://img.shields.io/github/languages/top/terraform-module/terraform-module-blueprint?color=green&logo=terraform&logoColor=blue)
17-
![](https://img.shields.io/github/commit-activity/m/terraform-module/terraform-module-blueprint)
18-
![](https://img.shields.io/github/contributors/terraform-module/terraform-module-blueprint)
19-
![](https://img.shields.io/github/last-commit/terraform-module/terraform-module-blueprint)
20-
[![Maintenance](https://img.shields.io/badge/Maintenu%3F-oui-green.svg)](https://GitHub.com/terraform-module/terraform-module-blueprint/graphs/commit-activity)
21-
[![GitHub forks](https://img.shields.io/github/forks/terraform-module/terraform-module-blueprint.svg?style=social&label=Fork)](https://github.com/terraform-module/terraform-module-blueprint)
1+
# Velero installation on AWS EKS Kubernetes
2+
3+
![](https://github.com/terraform-module/terraform-kubernetes-velero/workflows/release/badge.svg)
4+
![](https://github.com/terraform-module/terraform-kubernetes-velero/workflows/commit-check/badge.svg)
5+
![](https://github.com/terraform-module/terraform-kubernetes-velero/workflows/labeler/badge.svg)
6+
7+
[![](https://img.shields.io/github/license/terraform-module/terraform-kubernetes-velero)](https://github.com/terraform-module/terraform-kubernetes-velero)
8+
![](https://img.shields.io/github/v/tag/terraform-module/terraform-kubernetes-velero)
9+
![](https://img.shields.io/issues/github/terraform-module/terraform-kubernetes-velero)
10+
![](https://img.shields.io/github/issues/terraform-module/terraform-kubernetes-velero)
11+
![](https://img.shields.io/github/issues-closed/terraform-module/terraform-kubernetes-velero)
12+
[![](https://img.shields.io/github/languages/code-size/terraform-module/terraform-kubernetes-velero)](https://github.com/terraform-module/terraform-kubernetes-velero)
13+
[![](https://img.shields.io/github/repo-size/terraform-module/terraform-kubernetes-velero)](https://github.com/terraform-module/terraform-kubernetes-velero)
14+
![](https://img.shields.io/github/languages/top/terraform-module/terraform-kubernetes-velero?color=green&logo=terraform&logoColor=blue)
15+
![](https://img.shields.io/github/commit-activity/m/terraform-module/terraform-kubernetes-velero)
16+
![](https://img.shields.io/github/contributors/terraform-module/terraform-kubernetes-velero)
17+
![](https://img.shields.io/github/last-commit/terraform-module/terraform-kubernetes-velero)
18+
[![Maintenance](https://img.shields.io/badge/Maintenu%3F-oui-green.svg)](https://GitHub.com/terraform-module/terraform-kubernetes-velero/graphs/commit-activity)
19+
[![GitHub forks](https://img.shields.io/github/forks/terraform-module/terraform-kubernetes-velero.svg?style=social&label=Fork)](https://github.com/terraform-module/terraform-kubernetes-velero)
20+
21+
## References
22+
23+
- [Velero Providers](https://velero.io/docs/master/supported-providers/)
24+
- [Velero BackupStorage](https://velero.io/docs/master/api-types/backupstoragelocation/)
25+
- [Velero Basic Install](https://velero.io/docs/v1.4/basic-install/)
26+
- [Velero Daily Backup/Disaster Recovery](https://velero.io/docs/v1.4/disaster-case/)
27+
- [Velero Cluster Migration](https://velero.io/docs/v1.4/migration-case/)
28+
- [Velero AWS Plugin](https://github.com/vmware-tanzu/velero-plugin-for-aws)
29+
30+
- [Chart installation](https://github.com/vmware-tanzu/helm-charts/blob/master/charts/velero/README.md)
31+
- [Velero Helm Chart](https://github.com/vmware-tanzu/velero)
32+
- [AWS Setup](https://github.com/vmware-tanzu/velero-plugin-for-aws#setup)
33+
- [AWS CSI Driver](https://docs.aws.amazon.com/eks/latest/userguide/ebs-csi.html)
34+
- [Cassandra Example](https://velero.io/blog/velero-v1-1-stateful-backup-vsphere/)
35+
36+
## Installation
37+
38+
```sh
39+
$ brew install velero
40+
$ helm repo add vmware-tanzu https://vmware-tanzu.github.io/helm-charts
41+
```
2242

2343
## Documentation
2444

@@ -39,7 +59,45 @@ Here's the gist of using it directly from github.
3959
## Module Variables
4060

4161
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
42-
Error: no lines in file
62+
## Requirements
63+
64+
| Name | Version |
65+
|------|---------|
66+
| terraform | >= 0.12 |
67+
| helm | >= 1.2 |
68+
| kubernetes | >= 1.11.0 |
69+
70+
## Providers
71+
72+
| Name | Version |
73+
|------|---------|
74+
| aws | n/a |
75+
| helm | >= 1.2 |
76+
| kubernetes | >= 1.11.0 |
77+
78+
## Inputs
79+
80+
| Name | Description | Type | Default | Required |
81+
|------|-------------|------|---------|:--------:|
82+
| app\_deploy | whther or not to deploy app | `bool` | `true` | no |
83+
| bucket | Backup and Restore bucket. | `string` | n/a | yes |
84+
| cluster\_name | Cluster name. | `string` | n/a | yes |
85+
| description | Namespace description | `string` | `"velero-back-up-and-restore"` | no |
86+
| name | namespace name | `string` | `"velero"` | no |
87+
| namespace\_deploy | whther or not to deploy namespace | `bool` | `false` | no |
88+
| openid\_connect\_provider\_uri | OpenID Connect Provider for EKS to enable IRSA. | `string` | n/a | yes |
89+
| repository | VMware Tanzu repository for Helm repos. | `string` | `"https://vmware-tanzu.github.io/helm-charts"` | no |
90+
| tags | A mapping of tags to assign to the object. | `map` | `{}` | no |
91+
| values | List of values in raw yaml to pass to helm. Values will be merged. | `list(string)` | n/a | yes |
92+
| vars | A Release is an instance of a chart running in a Kubernetes cluster. | `map` | `{}` | no |
93+
94+
## Outputs
95+
96+
| Name | Description |
97+
|------|-------------|
98+
| namespace | Namespace name |
99+
| namespace\_name | Namespace name |
100+
43101
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
44102

45103
## Commands
@@ -72,10 +130,14 @@ Submit a pull request
72130

73131
# Authors
74132

75-
Currently maintained by [Ivan Katliarchuk](https://github.com/ivankatliarchuk) and these [awesome contributors](https://github.com/terraform-module/terraform-module-blueprint/graphs/contributors).
133+
Currently maintained by [Ivan Katliarchuk](https://github.com/ivankatliarchuk) and these [awesome contributors](https://github.com/terraform-module/terraform-kubernetes-velero/graphs/contributors).
76134

77135
[![ForTheBadge uses-git](http://ForTheBadge.com/images/badges/uses-git.svg)](https://GitHub.com/)
78136

79137
## Terraform Registry
80138

81-
- [Module](https://registry.terraform.io/modules/terraform-module/todo/aws)
139+
- [Module](https://registry.terraform.io/modules/terraform-module/kubernetes-velero/aws)
140+
141+
## TODO
142+
143+
- [ ] Kiam support

data.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
data "aws_caller_identity" "current" {}

iam.tf

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
data aws_iam_policy_document assume_role {
2+
statement {
3+
sid = "serviceaccount"
4+
5+
actions = [
6+
"sts:AssumeRoleWithWebIdentity",
7+
]
8+
9+
principals {
10+
type = "Federated"
11+
identifiers = ["arn:aws:iam::${local.account_id}:oidc-provider/${var.openid_connect_provider_uri}"]
12+
}
13+
14+
condition {
15+
test = "StringEquals"
16+
variable = "${var.openid_connect_provider_uri}:sub"
17+
18+
values = [
19+
"system:serviceaccount:${local.namespace}:velero-server",
20+
]
21+
}
22+
}
23+
}
24+
25+
data aws_iam_policy_document policy {
26+
statement {
27+
sid = "ec2"
28+
29+
actions = [
30+
"ec2:DescribeVolumes",
31+
"ec2:DescribeSnapshots",
32+
"ec2:CreateTags",
33+
"ec2:CreateVolume",
34+
"ec2:CreateSnapshot",
35+
"ec2:DeleteSnapshot",
36+
]
37+
38+
resources = ["*", ]
39+
}
40+
statement {
41+
sid = "s3list"
42+
43+
actions = [
44+
"s3:ListBucket",
45+
]
46+
47+
resources = ["arn:aws:s3:::${var.bucket}", ]
48+
}
49+
50+
statement {
51+
sid = "s3backup"
52+
53+
actions = [
54+
"s3:GetObject",
55+
"s3:DeleteObject",
56+
"s3:PutObject",
57+
"s3:AbortMultipartUpload",
58+
"s3:ListMultipartUploadParts"
59+
]
60+
resources = ["arn:aws:s3:::${var.bucket}/velero/*", ]
61+
}
62+
}
63+
64+
resource aws_iam_role this {
65+
name = format("%s-%s", var.cluster_name, var.name)
66+
assume_role_policy = data.aws_iam_policy_document.assume_role.json
67+
tags = merge(var.tags,
68+
{ Attached = var.name },
69+
{ ServiceAccountName = var.name },
70+
{ ServiceAccountNameSpace = local.namespace },
71+
)
72+
}
73+
74+
resource aws_iam_role_policy this {
75+
name = format("%s-%s", var.cluster_name, var.name)
76+
role = aws_iam_role.this.id
77+
policy = data.aws_iam_policy_document.policy.json
78+
}

locals.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
locals {
2+
namespace = element(concat([for entry in kubernetes_namespace.this : entry.id], list("")), 0)
3+
account_id = data.aws_caller_identity.current.account_id
4+
}

main.tf

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
resource kubernetes_namespace this {
2+
count = var.namespace_deploy ? 1 : 0
3+
4+
metadata {
5+
name = var.name
6+
7+
labels = {
8+
name = var.name
9+
description = var.description
10+
}
11+
}
12+
}
13+
14+
resource helm_release this {
15+
count = var.app_deploy ? 1 : 0
16+
17+
name = var.name
18+
chart = var.name
19+
namespace = local.namespace
20+
repository = var.repository
21+
22+
force_update = lookup(var.vars, "force_update", true)
23+
wait = lookup(var.vars, "wait", true)
24+
recreate_pods = lookup(var.vars, "recreate_pods", true)
25+
max_history = lookup(var.vars, "max_history", 0)
26+
lint = lookup(var.vars, "lint", true)
27+
version = lookup(var.vars, "version", "2.12.0")
28+
29+
values = concat(var.values, list(<<EOF
30+
serviceAccount:
31+
server:
32+
create: true
33+
annotations:
34+
eks.amazonaws.com/role-arn: "${aws_iam_role.this.arn}"
35+
EOF
36+
))
37+
}

outputs.tf

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
output "used" {
2-
description = "used value"
3-
value = var.variable
1+
output "namespace" {
2+
value = kubernetes_namespace.this[0].metadata[0].name
3+
description = "Namespace name"
4+
}
5+
6+
output "namespace_name" {
7+
value = local.namespace
8+
description = "Namespace name"
49
}

variables.tf

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,61 @@
1-
variable "variable" {
2-
default = "variable"
3-
description = "defaul,description,type"
1+
variable "cluster_name" {
2+
description = "Cluster name."
3+
type = string
4+
}
5+
6+
variable "namespace_deploy" {
7+
default = false
8+
description = "whther or not to deploy namespace"
9+
type = bool
10+
}
11+
12+
variable "app_deploy" {
13+
default = true
14+
description = "whther or not to deploy app"
15+
type = bool
16+
}
17+
18+
variable "name" {
19+
default = "velero"
20+
description = "namespace name"
21+
type = string
22+
}
23+
24+
variable "description" {
25+
default = "velero-back-up-and-restore"
26+
description = "Namespace description"
27+
type = string
28+
}
29+
30+
variable "openid_connect_provider_uri" {
31+
description = "OpenID Connect Provider for EKS to enable IRSA."
32+
type = string
33+
}
34+
35+
variable "tags" {
36+
default = {}
37+
description = "A mapping of tags to assign to the object."
38+
type = map
39+
}
40+
41+
variable "repository" {
42+
default = "https://vmware-tanzu.github.io/helm-charts"
43+
description = "VMware Tanzu repository for Helm repos."
44+
type = string
45+
}
46+
47+
variable "values" {
48+
description = "List of values in raw yaml to pass to helm. Values will be merged."
49+
type = list(string)
50+
}
51+
52+
variable "vars" {
53+
description = "A Release is an instance of a chart running in a Kubernetes cluster."
54+
type = map
55+
default = {}
56+
}
57+
58+
variable "bucket" {
59+
description = "Backup and Restore bucket."
460
type = string
561
}

versions.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
terraform {
22
required_version = ">= 0.12"
3+
4+
required_providers {
5+
kubernetes = ">= 1.11.0"
6+
helm = ">= 1.2"
7+
}
38
}

0 commit comments

Comments
 (0)