Skip to content

Commit ecbfdec

Browse files
Merge pull request #7 from jverce/remove-deprecated-function-calls
Refactor usage of deprecated `list` function
2 parents d770fbf + fbb60dc commit ecbfdec

File tree

10 files changed

+149
-47
lines changed

10 files changed

+149
-47
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.1.0
3+
rev: v3.4.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.31.0
20+
rev: v1.50.0
2121
hooks:
2222
- id: terraform_fmt
2323
- id: terraform_docs

.terraform.lock.hcl

Lines changed: 58 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.tflint.hcl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
config {
2-
deep_check = false
32
ignore_module = {}
43
varfile = []
54
}

README.md

Lines changed: 42 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -117,52 +117,72 @@ Here's the gist of using it directly from github.
117117

118118
| Name | Version |
119119
|------|---------|
120-
| terraform | >= 0.12 |
121-
| helm | >= 1.2 |
122-
| kubernetes | >= 1.11.0 |
120+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.12 |
121+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.0 |
122+
| <a name="requirement_helm"></a> [helm](#requirement\_helm) | >= 1.2 |
123+
| <a name="requirement_kubernetes"></a> [kubernetes](#requirement\_kubernetes) | >= 1.11.0 |
123124

124125
## Providers
125126

126127
| Name | Version |
127128
|------|---------|
128-
| aws | n/a |
129-
| helm | >= 1.2 |
130-
| kubernetes | >= 1.11.0 |
129+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 3.0 |
130+
| <a name="provider_helm"></a> [helm](#provider\_helm) | >= 1.2 |
131+
| <a name="provider_kubernetes"></a> [kubernetes](#provider\_kubernetes) | >= 1.11.0 |
132+
133+
## Modules
134+
135+
No modules.
136+
137+
## Resources
138+
139+
| Name | Type |
140+
|------|------|
141+
| [aws_iam_role.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role) | resource |
142+
| [aws_iam_role_policy.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy) | resource |
143+
| [helm_release.this](https://registry.terraform.io/providers/hashicorp/helm/latest/docs/resources/release) | resource |
144+
| [kubernetes_namespace.this](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/namespace) | resource |
145+
| [aws_caller_identity.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) | data source |
146+
| [aws_iam_policy_document.assume_role](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
147+
| [aws_iam_policy_document.policy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
148+
| [kubernetes_namespace.this](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/data-sources/namespace) | data source |
131149

132150
## Inputs
133151

134152
| Name | Description | Type | Default | Required |
135153
|------|-------------|------|---------|:--------:|
136-
| app | A Release is an instance of a chart running in a Kubernetes cluster. | `map` | `{}` | no |
137-
| app\_deploy | Whether or not to deploy app | `bool` | `true` | no |
138-
| bucket | Backup and Restore bucket. | `string` | n/a | yes |
139-
| cluster\_name | Cluster name. | `string` | n/a | yes |
140-
| description | Namespace description | `string` | `"velero-back-up-and-restore"` | no |
141-
| iam\_deploy | Whether or not to deploy iam role | `bool` | `true` | no |
142-
| iam\_role\_name | Name of the Velero IAM role | `string` | `""` | no |
143-
| name | Namespace name | `string` | `"velero"` | no |
144-
| namespace\_deploy | Whether or not to deploy namespace | `bool` | `false` | no |
145-
| openid\_connect\_provider\_uri | OpenID Connect Provider for EKS to enable IRSA. | `string` | n/a | yes |
146-
| repository | VMware Tanzu repository for Helm repos. | `string` | `"https://vmware-tanzu.github.io/helm-charts"` | no |
147-
| tags | A mapping of tags to assign to the object. | `map` | `{}` | no |
148-
| values | List of values in raw yaml to pass to helm. Values will be merged. | `list(string)` | n/a | yes |
154+
| <a name="input_app"></a> [app](#input\_app) | A Release is an instance of a chart running in a Kubernetes cluster. | `map(any)` | `{}` | no |
155+
| <a name="input_app_deploy"></a> [app\_deploy](#input\_app\_deploy) | Whether or not to deploy app | `bool` | `true` | no |
156+
| <a name="input_bucket"></a> [bucket](#input\_bucket) | Backup and Restore bucket. | `string` | n/a | yes |
157+
| <a name="input_cluster_name"></a> [cluster\_name](#input\_cluster\_name) | Cluster name. | `string` | n/a | yes |
158+
| <a name="input_description"></a> [description](#input\_description) | Namespace description | `string` | `"velero-back-up-and-restore"` | no |
159+
| <a name="input_iam_deploy"></a> [iam\_deploy](#input\_iam\_deploy) | whther or not to deploy iam role | `bool` | `true` | no |
160+
| <a name="input_iam_role_name"></a> [iam\_role\_name](#input\_iam\_role\_name) | Name of the Velero IAM role | `string` | `""` | no |
161+
| <a name="input_name"></a> [name](#input\_name) | Installation name | `string` | `"velero"` | no |
162+
| <a name="input_namespace_deploy"></a> [namespace\_deploy](#input\_namespace\_deploy) | Whether or not to deploy namespace | `bool` | `false` | no |
163+
| <a name="input_namespace_name"></a> [namespace\_name](#input\_namespace\_name) | Kubernetes namespace name | `string` | `null` | no |
164+
| <a name="input_openid_connect_provider_uri"></a> [openid\_connect\_provider\_uri](#input\_openid\_connect\_provider\_uri) | OpenID Connect Provider for EKS to enable IRSA. | `string` | n/a | yes |
165+
| <a name="input_repository"></a> [repository](#input\_repository) | VMware Tanzu repository for Helm repos. | `string` | `"https://vmware-tanzu.github.io/helm-charts"` | no |
166+
| <a name="input_tags"></a> [tags](#input\_tags) | A mapping of tags to assign to the object. | `map(any)` | `{}` | no |
167+
| <a name="input_values"></a> [values](#input\_values) | List of values in raw yaml to pass to helm. Values will be merged. | `list(string)` | n/a | yes |
149168

150169
## Outputs
151170

152171
| Name | Description |
153172
|------|-------------|
154-
| namespace\_name | Namespace name |
155-
173+
| <a name="output_namespace_name"></a> [namespace\_name](#output\_namespace\_name) | Namespace name |
156174
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
157175

158176
## Commands
159177

160178
<!-- START makefile-doc -->
161179
```
162-
$ make help
180+
$ make help
181+
make[1]: Entering directory '/home/jay/dev/altitude-sports/terraform-kubernetes-velero'
163182
hooks Commit hooks setup
164183
validate Validate with pre-commit hooks
165184
changelog Update changelog
185+
make[1]: Leaving directory '/home/jay/dev/altitude-sports/terraform-kubernetes-velero'
166186
```
167187
<!-- END makefile-doc -->
168188

iam.tf

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
data aws_iam_policy_document assume_role {
1+
data "aws_iam_policy_document" "assume_role" {
22
statement {
33
sid = "serviceaccount"
44

@@ -22,7 +22,7 @@ data aws_iam_policy_document assume_role {
2222
}
2323
}
2424

25-
data aws_iam_policy_document policy {
25+
data "aws_iam_policy_document" "policy" {
2626
statement {
2727
sid = "ec2"
2828

@@ -61,9 +61,9 @@ data aws_iam_policy_document policy {
6161
}
6262
}
6363

64-
resource aws_iam_role this {
65-
count = var.iam_deploy ? 1 : 0
66-
name = var.iam_role_name == "" ? format("%s-%s", var.cluster_name, var.name) : var.iam_role_name
64+
resource "aws_iam_role" "this" {
65+
count = var.iam_deploy ? 1 : 0
66+
name = var.iam_role_name == "" ? format("%s-%s", var.cluster_name, var.name) : var.iam_role_name
6767

6868
assume_role_policy = data.aws_iam_policy_document.assume_role.json
6969
tags = merge(var.tags,
@@ -73,7 +73,7 @@ resource aws_iam_role this {
7373
)
7474
}
7575

76-
resource aws_iam_role_policy this {
76+
resource "aws_iam_role_policy" "this" {
7777
count = var.iam_deploy ? 1 : 0
7878
name = format("%s-%s", var.cluster_name, var.name)
7979
role = element(aws_iam_role.this.*.id, 0)

locals.tf

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
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
2+
namespace_name = coalesce(var.namespace_name, var.name)
3+
namespace = data.kubernetes_namespace.this.metadata[0].name
4+
account_id = data.aws_caller_identity.current.account_id
45
}

main.tf

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,29 @@
1-
resource kubernetes_namespace this {
1+
resource "kubernetes_namespace" "this" {
22
count = var.namespace_deploy ? 1 : 0
33

44
metadata {
5-
name = var.name
5+
name = local.namespace_name
66

77
labels = {
8-
name = var.name
8+
name = local.namespace_name
99
description = var.description
1010
}
1111
}
1212
}
1313

14-
resource helm_release this {
14+
# Retrieving this data will ensure that the target Kubernetes namespace exists
15+
# before proceeding.
16+
data "kubernetes_namespace" "this" {
17+
metadata {
18+
name = local.namespace_name
19+
}
20+
21+
depends_on = [
22+
kubernetes_namespace.this,
23+
]
24+
}
25+
26+
resource "helm_release" "this" {
1527
count = var.app_deploy ? 1 : 0
1628

1729
name = var.name
@@ -26,12 +38,12 @@ resource helm_release this {
2638
lint = lookup(var.app, "lint", true)
2739
version = lookup(var.app, "version", "2.13.2")
2840

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-
))
41+
values = concat(
42+
var.values,
43+
tolist([
44+
templatefile("${path.module}/value_templates/serviceaccount.template.yaml", {
45+
EKS_ROLE_ARN = aws_iam_role.this[0].arn
46+
}),
47+
]),
48+
)
3749
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
serviceAccount:
2+
server:
3+
create: true
4+
annotations:
5+
eks.amazonaws.com/role-arn: '${EKS_ROLE_ARN}'

variables.tf

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,13 @@ variable "iam_deploy" {
2323

2424
variable "name" {
2525
default = "velero"
26-
description = "Namespace name"
26+
description = "Installation name"
27+
type = string
28+
}
29+
30+
variable "namespace_name" {
31+
default = null
32+
description = "Kubernetes namespace name"
2733
type = string
2834
}
2935

versions.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ terraform {
22
required_version = ">= 0.12"
33

44
required_providers {
5-
kubernetes = ">= 1.11.0"
5+
aws = ">= 3.0"
66
helm = ">= 1.2"
7+
kubernetes = ">= 1.11.0"
78
}
89
}

0 commit comments

Comments
 (0)