Skip to content

Commit ccdab4a

Browse files
authored
Update EKS basic components (cloudposse/terraform-aws-components#509)
1 parent 98cee58 commit ccdab4a

File tree

7 files changed

+110
-112
lines changed

7 files changed

+110
-112
lines changed

src/README.md

Lines changed: 46 additions & 40 deletions
Large diffs are not rendered by default.

src/default.auto.tfvars

Lines changed: 0 additions & 26 deletions
This file was deleted.

src/main.tf

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,23 @@ data "aws_partition" "current" {
77
count = local.enabled ? 1 : 0
88
}
99

10-
resource "kubernetes_namespace" "default" {
11-
count = local.enabled && var.create_namespace ? 1 : 0
12-
13-
metadata {
14-
name = var.kubernetes_namespace
15-
16-
labels = module.this.tags
17-
}
18-
}
19-
2010
module "cert_manager" {
2111
source = "cloudposse/helm-release/aws"
22-
version = "0.5.0"
23-
24-
name = "" # avoids hitting length restrictions on IAM Role names
25-
chart = var.cert_manager_chart
26-
repository = var.cert_manager_repository
27-
description = var.cert_manager_description
28-
chart_version = var.cert_manager_chart_version
29-
kubernetes_namespace = join("", kubernetes_namespace.default.*.id)
30-
create_namespace = false
31-
wait = var.wait
32-
atomic = var.atomic
33-
cleanup_on_fail = var.cleanup_on_fail
34-
timeout = var.timeout
12+
version = "0.7.0"
13+
14+
name = "" # avoids hitting length restrictions on IAM Role names
15+
chart = var.cert_manager_chart
16+
repository = var.cert_manager_repository
17+
description = var.cert_manager_description
18+
chart_version = var.cert_manager_chart_version
19+
wait = var.wait || var.letsencrypt_enabled || var.cert_manager_issuer_selfsigned_enabled
20+
atomic = var.atomic
21+
cleanup_on_fail = var.cleanup_on_fail
22+
timeout = var.timeout
23+
24+
create_namespace_with_kubernetes = var.create_namespace
25+
kubernetes_namespace = var.kubernetes_namespace
26+
kubernetes_namespace_labels = merge(module.this.tags, { name = var.kubernetes_namespace })
3527

3628
# Only install IAM role if letsencrypt_enabled is true
3729
iam_role_enabled = var.letsencrypt_enabled
@@ -113,9 +105,10 @@ module "cert_manager" {
113105
context = module.this.context
114106
}
115107

108+
116109
module "cert_manager_issuer" {
117110
source = "cloudposse/helm-release/aws"
118-
version = "0.5.0"
111+
version = "0.7.0"
119112

120113
# Only install the issuer if either letsencrypt_installed or selfsigned_installed is true
121114
enabled = local.enabled && (var.letsencrypt_enabled || var.cert_manager_issuer_selfsigned_enabled)
@@ -125,15 +118,15 @@ module "cert_manager_issuer" {
125118
repository = var.cert_manager_issuer_repository
126119
description = var.cert_manager_issuer_description
127120
chart_version = var.cert_manager_issuer_chart_version
128-
kubernetes_namespace = join("", kubernetes_namespace.default.*.id)
121+
kubernetes_namespace = var.kubernetes_namespace
129122
create_namespace = false
130123
wait = var.wait
131124
atomic = var.atomic
132125
cleanup_on_fail = var.cleanup_on_fail
133126
timeout = var.timeout
134127

135-
# Only install IAM role if letsencrypt_enabled is true
136-
iam_role_enabled = var.letsencrypt_enabled
128+
# IAM role will be created by the cert-manager module above, if needed. Do not create a duplicate here.
129+
iam_role_enabled = false
137130
eks_cluster_oidc_issuer_url = replace(module.eks.outputs.eks_cluster_identity_oidc_issuer, "https://", "")
138131

139132
# NOTE: Use with the local chart

src/provider-helm.tf

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
#
33
# This file is a drop-in to provide a helm provider.
44
#
5+
# It depends on 2 standard Cloud Posse data source modules to be already
6+
# defined in the same component:
7+
#
8+
# 1. module.iam_roles to provide the AWS profile or Role ARN to use to access the cluster
9+
# 2. module.eks to provide the EKS cluster information
10+
#
511
# All the following variables are just about configuring the Kubernetes provider
612
# to be able to modify EKS cluster. The reason there are so many options is
713
# because at various times, each one of them has had problems, so we give you a choice.
@@ -100,9 +106,11 @@ locals {
100106
"--role-arn", local.kube_exec_auth_role_arn
101107
] : []
102108

103-
certificate_authority_data = module.eks.outputs.eks_cluster_certificate_authority_data
104-
eks_cluster_id = module.eks.outputs.eks_cluster_id
105-
eks_cluster_endpoint = module.eks.outputs.eks_cluster_endpoint
109+
# Provide dummy configuration for the case where the EKS cluster is not available.
110+
certificate_authority_data = try(module.eks.outputs.eks_cluster_certificate_authority_data, "")
111+
# Use coalesce+try to handle both the case where the output is missing and the case where it is empty.
112+
eks_cluster_id = coalesce(try(module.eks.outputs.eks_cluster_id, ""), "missing")
113+
eks_cluster_endpoint = try(module.eks.outputs.eks_cluster_endpoint, "")
106114
}
107115

108116
data "aws_eks_cluster_auth" "eks" {
@@ -114,14 +122,14 @@ provider "helm" {
114122
kubernetes {
115123
host = local.eks_cluster_endpoint
116124
cluster_ca_certificate = base64decode(local.certificate_authority_data)
117-
token = local.kube_data_auth_enabled ? data.aws_eks_cluster_auth.eks[0].token : null
125+
token = local.kube_data_auth_enabled ? one(data.aws_eks_cluster_auth.eks[*].token) : null
118126
# The Kubernetes provider will use information from KUBECONFIG if it exists, but if the default cluster
119127
# in KUBECONFIG is some other cluster, this will cause problems, so we override it always.
120128
config_path = local.kubeconfig_file_enabled ? var.kubeconfig_file : ""
121129
config_context = var.kubeconfig_context
122130

123131
dynamic "exec" {
124-
for_each = local.kube_exec_auth_enabled ? ["exec"] : []
132+
for_each = local.kube_exec_auth_enabled && length(local.certificate_authority_data) > 0 ? ["exec"] : []
125133
content {
126134
api_version = local.kubeconfig_exec_auth_api_version
127135
command = "aws"
@@ -132,21 +140,21 @@ provider "helm" {
132140
}
133141
}
134142
experiments {
135-
manifest = var.helm_manifest_experiment_enabled
143+
manifest = var.helm_manifest_experiment_enabled && module.this.enabled
136144
}
137145
}
138146

139147
provider "kubernetes" {
140148
host = local.eks_cluster_endpoint
141149
cluster_ca_certificate = base64decode(local.certificate_authority_data)
142-
token = local.kube_data_auth_enabled ? data.aws_eks_cluster_auth.eks[0].token : null
150+
token = local.kube_data_auth_enabled ? one(data.aws_eks_cluster_auth.eks[*].token) : null
143151
# The Kubernetes provider will use information from KUBECONFIG if it exists, but if the default cluster
144152
# in KUBECONFIG is some other cluster, this will cause problems, so we override it always.
145153
config_path = local.kubeconfig_file_enabled ? var.kubeconfig_file : ""
146154
config_context = var.kubeconfig_context
147155

148156
dynamic "exec" {
149-
for_each = local.kube_exec_auth_enabled ? ["exec"] : []
157+
for_each = local.kube_exec_auth_enabled && length(local.certificate_authority_data) > 0 ? ["exec"] : []
150158
content {
151159
api_version = local.kubeconfig_exec_auth_api_version
152160
command = "aws"

src/remote-state.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module "eks" {
22
source = "cloudposse/stack-config/yaml//modules/remote-state"
3-
version = "0.22.4"
3+
version = "1.3.1"
44

55
component = var.eks_component_name
66

@@ -9,7 +9,7 @@ module "eks" {
99

1010
module "dns_gbl_delegated" {
1111
source = "cloudposse/stack-config/yaml//modules/remote-state"
12-
version = "0.22.4"
12+
version = "1.3.1"
1313

1414
component = "dns-delegated"
1515
environment = "gbl"

src/variables.tf

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,13 @@ variable "cert_manager_description" {
2222
variable "cert_manager_chart" {
2323
type = string
2424
description = "Chart name to be installed. The chart name can be local path, a URL to a chart, or the name of the chart if `repository` is specified. It is also possible to use the `<repository>/<chart>` format here if you are running Terraform on a system that the repository has been added to with `helm repo add` but this is not recommended."
25+
default = "cert-manager"
2526
}
2627

2728
variable "cert_manager_repository" {
2829
type = string
2930
description = "Repository URL where to locate the requested chart."
30-
default = null
31+
default = "https://charts.jetstack.io"
3132
}
3233

3334
variable "cert_manager_chart_version" {
@@ -48,12 +49,22 @@ variable "cert_manager_resources" {
4849
})
4950
})
5051
description = "The cpu and memory of the cert manager's limits and requests."
52+
default = {
53+
limits = {
54+
cpu = "200m"
55+
memory = "256Mi"
56+
}
57+
requests = {
58+
cpu = "100m"
59+
memory = "128Mi"
60+
}
61+
}
5162
}
5263

5364
variable "cart_manager_rbac_enabled" {
5465
type = bool
55-
default = true
5666
description = "Service Account for pods."
67+
default = true
5768
}
5869

5970
variable "cert_manager_metrics_enabled" {
@@ -79,6 +90,7 @@ variable "cert_manager_issuer_description" {
7990
variable "cert_manager_issuer_chart" {
8091
type = string
8192
description = "Chart name to be installed. The chart name can be local path, a URL to a chart, or the name of the chart if `repository` is specified. It is also possible to use the `<repository>/<chart>` format here if you are running Terraform on a system that the repository has been added to with `helm repo add` but this is not recommended."
93+
default = "./cert-manager-issuer/"
8294
}
8395

8496
variable "cert_manager_issuer_repository" {
@@ -112,13 +124,14 @@ variable "cert_manager_issuer_values" {
112124

113125
variable "create_namespace" {
114126
type = bool
115-
description = "Create the namespace if it does not yet exist. Defaults to `false`."
116-
default = null
127+
description = "Create the namespace if it does not yet exist. Defaults to `true`."
128+
default = true
117129
}
118130

119131
variable "kubernetes_namespace" {
120132
type = string
121133
description = "The namespace to install the release into."
134+
default = "cert-manager"
122135
}
123136

124137
variable "timeout" {
@@ -129,20 +142,20 @@ variable "timeout" {
129142

130143
variable "cleanup_on_fail" {
131144
type = bool
132-
description = "Allow deletion of new resources created in this upgrade when upgrade fails."
145+
description = "If `true`, resources created in this deploy will be deleted when deploy fails. Highly recommended to prevent cert-manager from getting into a wedeged state."
133146
default = true
134147
}
135148

136149
variable "atomic" {
137150
type = bool
138-
description = "If set, installation process purges chart on fail. The wait flag will be set automatically if atomic is used."
151+
description = "If `true`, if any part of the installation process fails, all parts are treated as failed. Highly recommended to prevent cert-manager from getting into a wedged state. The wait flag will be set automatically if atomic is used."
139152
default = true
140153
}
141154

142155
variable "wait" {
143156
type = bool
144-
description = "Will wait until all resources are in a ready state before marking the release as successful. It will wait for as long as `timeout`. Defaults to `true`."
145-
default = null
157+
description = "Set `true` to wait until all resources are in a ready state before marking the release as successful. Ignored if provisioning Issuers. It will wait for as long as `timeout`. Defaults to `true`."
158+
default = true
146159
}
147160

148161
variable "eks_component_name" {

src/versions.tf

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@ terraform {
44
required_providers {
55
aws = {
66
source = "hashicorp/aws"
7-
version = "~> 4.0"
7+
version = ">= 4.9.0"
88
}
99
helm = {
1010
source = "hashicorp/helm"
1111
version = ">= 2.0"
1212
}
13+
kubernetes = {
14+
source = "hashicorp/kubernetes"
15+
version = ">= 2.14.0"
16+
}
1317
}
1418
}

0 commit comments

Comments
 (0)