Skip to content

Commit 57e5cbd

Browse files
author
BARRY Thierno Ibrahima (Canal Plus Prestataire)
committed
feat: Use http datasource instead of local-exec for waiting cluster
1 parent 5db15e3 commit 57e5cbd

File tree

6 files changed

+12
-36
lines changed

6 files changed

+12
-36
lines changed

README.md

+2-5
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@ MIT Licensed. See [LICENSE](https://github.com/terraform-aws-modules/terraform-a
148148
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.35.0 |
149149
| <a name="requirement_kubernetes"></a> [kubernetes](#requirement\_kubernetes) | >= 1.11.1 |
150150
| <a name="requirement_local"></a> [local](#requirement\_local) | >= 1.4 |
151-
| <a name="requirement_null"></a> [null](#requirement\_null) | >= 2.1 |
152151
| <a name="requirement_random"></a> [random](#requirement\_random) | >= 2.1 |
153152
| <a name="requirement_template"></a> [template](#requirement\_template) | >= 2.1 |
154153

@@ -157,9 +156,9 @@ MIT Licensed. See [LICENSE](https://github.com/terraform-aws-modules/terraform-a
157156
| Name | Version |
158157
|------|---------|
159158
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 3.35.0 |
159+
| <a name="provider_http"></a> [http](#provider\_http) | n/a |
160160
| <a name="provider_kubernetes"></a> [kubernetes](#provider\_kubernetes) | >= 1.11.1 |
161161
| <a name="provider_local"></a> [local](#provider\_local) | >= 1.4 |
162-
| <a name="provider_null"></a> [null](#provider\_null) | >= 2.1 |
163162
| <a name="provider_random"></a> [random](#provider\_random) | >= 2.1 |
164163
| <a name="provider_template"></a> [template](#provider\_template) | >= 2.1 |
165164

@@ -208,7 +207,6 @@ MIT Licensed. See [LICENSE](https://github.com/terraform-aws-modules/terraform-a
208207
| [aws_security_group_rule.workers_ingress_self](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group_rule) | resource |
209208
| [kubernetes_config_map.aws_auth](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/config_map) | resource |
210209
| [local_file.kubeconfig](https://registry.terraform.io/providers/hashicorp/local/latest/docs/resources/file) | resource |
211-
| [null_resource.wait_for_cluster](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource |
212210
| [random_pet.workers](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/pet) | resource |
213211
| [random_pet.workers_launch_template](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/pet) | resource |
214212
| [aws_ami.eks_worker](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/ami) | data source |
@@ -221,6 +219,7 @@ MIT Licensed. See [LICENSE](https://github.com/terraform-aws-modules/terraform-a
221219
| [aws_iam_policy_document.workers_assume_role_policy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
222220
| [aws_iam_role.custom_cluster_iam_role](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_role) | data source |
223221
| [aws_partition.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/partition) | data source |
222+
| [http_http.wait_for_cluster](https://registry.terraform.io/providers/hashicorp/http/latest/docs/data-sources/http) | data source |
224223
| [template_file.launch_template_userdata](https://registry.terraform.io/providers/hashicorp/template/latest/docs/data-sources/file) | data source |
225224
| [template_file.userdata](https://registry.terraform.io/providers/hashicorp/template/latest/docs/data-sources/file) | data source |
226225

@@ -273,8 +272,6 @@ MIT Licensed. See [LICENSE](https://github.com/terraform-aws-modules/terraform-a
273272
| <a name="input_subnets"></a> [subnets](#input\_subnets) | A list of subnets to place the EKS cluster and workers within. | `list(string)` | n/a | yes |
274273
| <a name="input_tags"></a> [tags](#input\_tags) | A map of tags to add to all resources. Tags added to launch configuration or templates override these values for ASG Tags only. | `map(string)` | `{}` | no |
275274
| <a name="input_vpc_id"></a> [vpc\_id](#input\_vpc\_id) | VPC where the cluster and workers will be deployed. | `string` | n/a | yes |
276-
| <a name="input_wait_for_cluster_cmd"></a> [wait\_for\_cluster\_cmd](#input\_wait\_for\_cluster\_cmd) | Custom local-exec command to execute for determining if the eks cluster is healthy. Cluster endpoint will be available as an environment variable called ENDPOINT | `string` | `"for i in `seq 1 60`; do if `command -v wget > /dev/null`; then wget --no-check-certificate -O - -q $ENDPOINT/healthz >/dev/null && exit 0 || true; else curl -k -s $ENDPOINT/healthz >/dev/null && exit 0 || true;fi; sleep 5; done; echo TIMEOUT && exit 1"` | no |
277-
| <a name="input_wait_for_cluster_interpreter"></a> [wait\_for\_cluster\_interpreter](#input\_wait\_for\_cluster\_interpreter) | Custom local-exec command line interpreter for the command to determining if the eks cluster is healthy. | `list(string)` | <pre>[<br> "/bin/sh",<br> "-c"<br>]</pre> | no |
278275
| <a name="input_worker_additional_security_group_ids"></a> [worker\_additional\_security\_group\_ids](#input\_worker\_additional\_security\_group\_ids) | A list of additional security group ids to attach to worker instances | `list(string)` | `[]` | no |
279276
| <a name="input_worker_ami_name_filter"></a> [worker\_ami\_name\_filter](#input\_worker\_ami\_name\_filter) | Name filter for AWS EKS worker AMI. If not provided, the latest official AMI for the specified 'cluster\_version' is used. | `string` | `""` | no |
280277
| <a name="input_worker_ami_name_filter_windows"></a> [worker\_ami\_name\_filter\_windows](#input\_worker\_ami\_name\_filter\_windows) | Name filter for AWS EKS Windows worker AMI. If not provided, the latest official AMI for the specified 'cluster\_version' is used. | `string` | `""` | no |

aws_auth.tf

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,15 @@ locals {
6464

6565
resource "kubernetes_config_map" "aws_auth" {
6666
count = var.create_eks && var.manage_aws_auth ? 1 : 0
67-
depends_on = [null_resource.wait_for_cluster[0]]
67+
depends_on = [data.http.wait_for_cluster[0]]
6868

6969
metadata {
7070
name = "aws-auth"
7171
namespace = "kube-system"
7272
labels = merge(
7373
{
7474
"app.kubernetes.io/managed-by" = "Terraform"
75-
# / are replaced by . because label validator fails in this lib
75+
# / are replaced by . because label validator fails in this lib
7676
# https://github.com/kubernetes/apimachinery/blob/1bdd76d09076d4dc0362456e59c8f551f5f24a72/pkg/util/validation/validation.go#L166
7777
"terraform.io/module" = "terraform-aws-modules.eks.aws"
7878
},

cluster.tf

+4-15
Original file line numberDiff line numberDiff line change
@@ -64,21 +64,10 @@ resource "aws_security_group_rule" "cluster_private_access" {
6464
}
6565

6666

67-
resource "null_resource" "wait_for_cluster" {
68-
count = var.create_eks && var.manage_aws_auth ? 1 : 0
69-
70-
depends_on = [
71-
aws_eks_cluster.this,
72-
aws_security_group_rule.cluster_private_access,
73-
]
74-
75-
provisioner "local-exec" {
76-
command = var.wait_for_cluster_cmd
77-
interpreter = var.wait_for_cluster_interpreter
78-
environment = {
79-
ENDPOINT = aws_eks_cluster.this[0].endpoint
80-
}
81-
}
67+
data "http" "wait_for_cluster" {
68+
count = var.create_eks && var.manage_aws_auth ? 1 : 0
69+
url = format("%s/healthz", aws_eks_cluster.this[0].endpoint)
70+
ca_certificate = base64decode(coalescelist(aws_eks_cluster.this[*].certificate_authority[0].data, [""])[0])
8271
}
8372

8473
resource "aws_security_group" "cluster" {

outputs.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ output "cluster_id" {
33
value = element(concat(aws_eks_cluster.this.*.id, [""]), 0)
44
# So that calling plans wait for the cluster to be available before attempting
55
# to use it. They will not need to duplicate this null_resource
6-
depends_on = [null_resource.wait_for_cluster]
6+
depends_on = [data.http.wait_for_cluster]
77
}
88

99
output "cluster_arn" {

variables.tf

-12
Original file line numberDiff line numberDiff line change
@@ -205,18 +205,6 @@ variable "cluster_delete_timeout" {
205205
default = "15m"
206206
}
207207

208-
variable "wait_for_cluster_cmd" {
209-
description = "Custom local-exec command to execute for determining if the eks cluster is healthy. Cluster endpoint will be available as an environment variable called ENDPOINT"
210-
type = string
211-
default = "for i in `seq 1 60`; do if `command -v wget > /dev/null`; then wget --no-check-certificate -O - -q $ENDPOINT/healthz >/dev/null && exit 0 || true; else curl -k -s $ENDPOINT/healthz >/dev/null && exit 0 || true;fi; sleep 5; done; echo TIMEOUT && exit 1"
212-
}
213-
214-
variable "wait_for_cluster_interpreter" {
215-
description = "Custom local-exec command line interpreter for the command to determining if the eks cluster is healthy."
216-
type = list(string)
217-
default = ["/bin/sh", "-c"]
218-
}
219-
220208
variable "cluster_create_security_group" {
221209
description = "Whether to create a security group for the cluster or attach the cluster to `cluster_security_group_id`."
222210
type = bool

versions.tf

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ terraform {
44
required_providers {
55
aws = ">= 3.35.0"
66
local = ">= 1.4"
7-
null = ">= 2.1"
87
template = ">= 2.1"
98
random = ">= 2.1"
109
kubernetes = ">= 1.11.1"
10+
http = {
11+
source = "terraform-aws-modules/http"
12+
}
1113
}
1214
}

0 commit comments

Comments
 (0)