From 0adb5b0d2cc15853d9eb8c832c90239fde41e376 Mon Sep 17 00:00:00 2001 From: gowri padmaja s <48469089+gowripadmajas@users.noreply.github.com> Date: Thu, 23 Jun 2022 14:25:41 +0800 Subject: [PATCH 1/6] Feature/add irssa (#1) * updated with irsa * cleaned up * updated the boolean condition for eks SA annotations * simplified Annotation attachment to SA * removed data.tf * updated variable alignment --- CHANGELOG.md | 2 +- kubernetes_cluster_role_binding.tf | 2 +- kubernetes_namespace.tf | 2 +- kubernetes_secret.tf | 2 +- kubernetes_service_account.tf | 8 ++++---- variables.tf | 5 +++++ 6 files changed, 13 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 36ffdc4..d415f3a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,4 +9,4 @@ BREAKING CHANGES: * Variable `agent_disable_update` is now `agent_auto_update` which defaults to minor and must be one of *disabled*, *minor*, or *patch* (#7) IMPROVEMENTS: -* [Example usage](examples/default/) added to the examples/default directory (#7) \ No newline at end of file +* [Example usage](examples/default/) added to the examples/default directory (#7) diff --git a/kubernetes_cluster_role_binding.tf b/kubernetes_cluster_role_binding.tf index 4a29100..dff8cbb 100644 --- a/kubernetes_cluster_role_binding.tf +++ b/kubernetes_cluster_role_binding.tf @@ -21,4 +21,4 @@ resource "kubernetes_cluster_role_binding" "tfc_agent_cluster_role_binding" { name = kubernetes_service_account.tfc_agent_service_account[0].metadata[0].name namespace = var.namespace } -} \ No newline at end of file +} diff --git a/kubernetes_namespace.tf b/kubernetes_namespace.tf index bb99e50..ccb11fc 100644 --- a/kubernetes_namespace.tf +++ b/kubernetes_namespace.tf @@ -10,4 +10,4 @@ resource "kubernetes_namespace" "tfc_agent_namespace" { name = var.namespace } -} \ No newline at end of file +} diff --git a/kubernetes_secret.tf b/kubernetes_secret.tf index 63ddb21..7c34a1c 100644 --- a/kubernetes_secret.tf +++ b/kubernetes_secret.tf @@ -13,4 +13,4 @@ resource "kubernetes_secret" "tfc_agent_token" { data = { "token" = var.agent_token } -} \ No newline at end of file +} diff --git a/kubernetes_service_account.tf b/kubernetes_service_account.tf index 582b81c..90fc399 100644 --- a/kubernetes_service_account.tf +++ b/kubernetes_service_account.tf @@ -7,8 +7,8 @@ resource "kubernetes_service_account" "tfc_agent_service_account" { "app.kubernetes.io/module-version" = local.module-version "app.kubernetes.io/managed-by" = "terraform" } - - name = "terraform-cloud-agent" - namespace = var.create_namespace ? kubernetes_namespace.tfc_agent_namespace[0].metadata[0].name : var.namespace + name = "terraform-cloud-agent" + namespace = var.create_namespace ? kubernetes_namespace.tfc_agent_namespace[0].metadata[0].name : var.namespace + annotations = var.annotations } -} \ No newline at end of file +} diff --git a/variables.tf b/variables.tf index 6dd5e9c..d4324e3 100644 --- a/variables.tf +++ b/variables.tf @@ -102,3 +102,8 @@ variable "tfc_url" { description = "The Terraform Cloud endpoint. Must be changed if using Terraform Enterprise." } +variable "annotations" { + description = "Add annotations for service accounts" + type = map(string) + default = {} +} From 4b784b55aa3cafbebb1855ec80e2debeef375461 Mon Sep 17 00:00:00 2001 From: gowripadmajas Date: Mon, 27 Jun 2022 12:56:43 +0800 Subject: [PATCH 2/6] update Readme and update variable name --- README.md | 1 + kubernetes_service_account.tf | 2 +- variables.tf | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index f08d046..1293bfa 100644 --- a/README.md +++ b/README.md @@ -68,6 +68,7 @@ No modules. | [requests\_cpu](#input\_requests\_cpu) | CPU requests. | `string` | `"500m"` | no | | [requests\_memory](#input\_requests\_memory) | Memory requests. | `string` | `"250Mi"` | no | | [tfc\_url](#input\_tfc\_url) | The Terraform Cloud endpoint. Must be changed if using Terraform Enterprise. | `string` | `"https://app.terraform.io"` | no | +| [service\_account\_annotations](#input\_service\_account\_annotations) | Can add annotations for IAM roles on the service accounts (irsa) or other annotations for K8's | `map(string)` | `{}` | no | ## Outputs diff --git a/kubernetes_service_account.tf b/kubernetes_service_account.tf index 90fc399..ee08802 100644 --- a/kubernetes_service_account.tf +++ b/kubernetes_service_account.tf @@ -9,6 +9,6 @@ resource "kubernetes_service_account" "tfc_agent_service_account" { } name = "terraform-cloud-agent" namespace = var.create_namespace ? kubernetes_namespace.tfc_agent_namespace[0].metadata[0].name : var.namespace - annotations = var.annotations + annotations = var.service_account_annotations } } diff --git a/variables.tf b/variables.tf index d4324e3..db26396 100644 --- a/variables.tf +++ b/variables.tf @@ -102,8 +102,8 @@ variable "tfc_url" { description = "The Terraform Cloud endpoint. Must be changed if using Terraform Enterprise." } -variable "annotations" { - description = "Add annotations for service accounts" +variable "service_account_annotations" { + description = "Add annotations for IAM roles on the service accounts (irsa)" type = map(string) default = {} } From f5cfe73c6b015035271305b80f160b3c2bcd6896 Mon Sep 17 00:00:00 2001 From: niroz89 Date: Tue, 16 Aug 2022 02:38:45 +0800 Subject: [PATCH 3/6] Update to Readme --- README.md | 4 ++-- variables.tf | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 1293bfa..24c22e0 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ provider "kubernetes" {} module "terraform-cloud-agent-kubernetes" { source = "redeux/terraform-cloud-agent/kubernetes" - version = "0.1.0" + version = "~> 1.0.1" namespace = "terraform-cloud-agent" create_namespace = true @@ -67,8 +67,8 @@ No modules. | [namespace](#input\_namespace) | The namespace to deploy the agent into. Unless create\_namespace is true, the namespace must already exist. | `string` | n/a | yes | | [requests\_cpu](#input\_requests\_cpu) | CPU requests. | `string` | `"500m"` | no | | [requests\_memory](#input\_requests\_memory) | Memory requests. | `string` | `"250Mi"` | no | +| [service\_account\_annotations](#input\_service\_account\_annotations) | Annotations to add to the Kubernetes service account. Can be used to annotate the IRSA. | `map(string)` | `{}` | no | | [tfc\_url](#input\_tfc\_url) | The Terraform Cloud endpoint. Must be changed if using Terraform Enterprise. | `string` | `"https://app.terraform.io"` | no | -| [service\_account\_annotations](#input\_service\_account\_annotations) | Can add annotations for IAM roles on the service accounts (irsa) or other annotations for K8's | `map(string)` | `{}` | no | ## Outputs diff --git a/variables.tf b/variables.tf index db26396..53bfdad 100644 --- a/variables.tf +++ b/variables.tf @@ -103,7 +103,7 @@ variable "tfc_url" { } variable "service_account_annotations" { - description = "Add annotations for IAM roles on the service accounts (irsa)" + description = "Annotations to add to the Kubernetes service account. Can be used to annotate the IRSA." type = map(string) default = {} } From 41bb15f0fd465475221de339ff233e23e11448a0 Mon Sep 17 00:00:00 2001 From: niroz89 Date: Wed, 17 Aug 2022 02:19:43 +0800 Subject: [PATCH 4/6] Introduce variable for service account name, follow variable attributes ordering similar as upstream --- kubernetes_service_account.tf | 6 +++--- variables.tf | 8 +++++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/kubernetes_service_account.tf b/kubernetes_service_account.tf index ee08802..9ae25ae 100644 --- a/kubernetes_service_account.tf +++ b/kubernetes_service_account.tf @@ -3,12 +3,12 @@ resource "kubernetes_service_account" "tfc_agent_service_account" { metadata { labels = { - "app.kubernetes.io/name" = "terraform-cloud-agent" + "app.kubernetes.io/name" = var.service_account_name "app.kubernetes.io/module-version" = local.module-version "app.kubernetes.io/managed-by" = "terraform" } - name = "terraform-cloud-agent" + name = var.service_account_name namespace = var.create_namespace ? kubernetes_namespace.tfc_agent_namespace[0].metadata[0].name : var.namespace - annotations = var.service_account_annotations + annotations = var.service_account_annotations } } diff --git a/variables.tf b/variables.tf index 53bfdad..90a763b 100644 --- a/variables.tf +++ b/variables.tf @@ -102,8 +102,14 @@ variable "tfc_url" { description = "The Terraform Cloud endpoint. Must be changed if using Terraform Enterprise." } +variable "service_account_name" { + type = string + default = "terraform-cloud-agent" + description = "Name of the service account." +} + variable "service_account_annotations" { - description = "Annotations to add to the Kubernetes service account. Can be used to annotate the IRSA." type = map(string) default = {} + description = "Annotations to add to the Kubernetes service account. Can be used to annotate the IRSA." } From 8088fd737fd4314d7ee2dca364d90472c6201580 Mon Sep 17 00:00:00 2001 From: niroz89 Date: Wed, 17 Aug 2022 02:20:06 +0800 Subject: [PATCH 5/6] Generate Readme --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 24c22e0..3cb0853 100644 --- a/README.md +++ b/README.md @@ -68,6 +68,7 @@ No modules. | [requests\_cpu](#input\_requests\_cpu) | CPU requests. | `string` | `"500m"` | no | | [requests\_memory](#input\_requests\_memory) | Memory requests. | `string` | `"250Mi"` | no | | [service\_account\_annotations](#input\_service\_account\_annotations) | Annotations to add to the Kubernetes service account. Can be used to annotate the IRSA. | `map(string)` | `{}` | no | +| [service\_account\_name](#input\_service\_account\_name) | Name of the service account. | `string` | `"terraform-cloud-agent"` | no | | [tfc\_url](#input\_tfc\_url) | The Terraform Cloud endpoint. Must be changed if using Terraform Enterprise. | `string` | `"https://app.terraform.io"` | no | ## Outputs From dd48a5a3f959204eb5f4b0d439a6f16b535d6d64 Mon Sep 17 00:00:00 2001 From: niroz89 Date: Wed, 17 Aug 2022 13:43:03 +0800 Subject: [PATCH 6/6] Do not alter the app name --- kubernetes_service_account.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kubernetes_service_account.tf b/kubernetes_service_account.tf index 9ae25ae..64dc07f 100644 --- a/kubernetes_service_account.tf +++ b/kubernetes_service_account.tf @@ -3,7 +3,7 @@ resource "kubernetes_service_account" "tfc_agent_service_account" { metadata { labels = { - "app.kubernetes.io/name" = var.service_account_name + "app.kubernetes.io/name" = "terraform-cloud-agent" "app.kubernetes.io/module-version" = local.module-version "app.kubernetes.io/managed-by" = "terraform" }