Skip to content

Commit 905d9f0

Browse files
sanjeevgirimax-rocket-internet
authored andcommitted
Configurable local exec command for waiting until cluster is healthy (#701)
* Configurable local exec command for waiting until cluster is healthy * readme * line feeds * format * fix readme * fix readme * Configurable local exec command for waiting until cluster is healthy (#1) * Configurable local exec command for waiting until cluster is healthy * readme * line feeds * format * fix readme * fix readme * change log * Configurable local exec wait 4 cluster op (#2) * Configurable local exec command for waiting until cluster is healthy * readme * line feeds * format * fix readme * fix readme * change log * changelog (#3) * Changelog (#4) * changelog * changelog * simplify wait_for_cluster command * readme * no op for manage auth false * formatting * docs? not sure * linter * specify dependency to wait for cluster more accurately
1 parent 317b948 commit 905d9f0

File tree

5 files changed

+20
-10
lines changed

5 files changed

+20
-10
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ project adheres to [Semantic Versioning](http://semver.org/).
99

1010
## [[v8.?.?](https://github.com/terraform-aws-modules/terraform-aws-eks/compare/v8.1.0...HEAD)] - YYYY-MM-DD]
1111

12-
- Write your awesome change here (by @you)
12+
- Include ability to configure custom os-specific command for waiting until kube cluster is healthy (@sanjeevgiri)
1313

1414
# History
1515

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,6 @@ MIT Licensed. See [LICENSE](https://github.com/terraform-aws-modules/terraform-a
174174
| kubeconfig_aws_authenticator_command_args | Default arguments passed to the authenticator command. Defaults to [token -i $cluster_name]. | list(string) | `[]` | no |
175175
| kubeconfig_aws_authenticator_env_variables | Environment variables that should be used when executing the authenticator. e.g. { AWS_PROFILE = "eks"}. | map(string) | `{}` | no |
176176
| kubeconfig_name | Override the default name used for items kubeconfig. | string | `""` | no |
177-
| local_exec_interpreter | Command to run for local-exec resources. Must be a shell-style interpreter. If you are on Windows Git Bash is a good choice. | list(string) | `[ "/bin/sh", "-c" ]` | no |
178177
| manage_aws_auth | Whether to apply the aws-auth configmap file. | string | `"true"` | no |
179178
| manage_cluster_iam_resources | Whether to let the module manage cluster IAM resources. If set to false, cluster_iam_role_name must be specified. | bool | `"true"` | no |
180179
| manage_worker_autoscaling_policy | Whether to let the module manage the cluster autoscaling iam policy. | bool | `"true"` | no |
@@ -188,6 +187,7 @@ MIT Licensed. See [LICENSE](https://github.com/terraform-aws-modules/terraform-a
188187
| subnets | A list of subnets to place the EKS cluster and workers within. | list(string) | n/a | yes |
189188
| tags | A map of tags to add to all resources. | map(string) | `{}` | no |
190189
| vpc_id | VPC where the cluster and workers will be deployed. | string | n/a | yes |
190+
| 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 | `"until curl -k -s $ENDPOINT/healthz \u003e/dev/null; do sleep 4; done"` | no |
191191
| worker_additional_security_group_ids | A list of additional security group ids to attach to worker instances | list(string) | `[]` | no |
192192
| 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 |
193193
| 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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ data "template_file" "node_group_arns" {
5050
}
5151

5252
resource "kubernetes_config_map" "aws_auth" {
53-
depends_on = [aws_eks_cluster.this]
5453
count = var.create_eks && var.manage_aws_auth ? 1 : 0
54+
depends_on = [null_resource.wait_for_cluster[0]]
5555

5656
metadata {
5757
name = "aws-auth"

cluster.tf

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,20 @@ resource "aws_eks_cluster" "this" {
3232
aws_iam_role_policy_attachment.cluster_AmazonEKSServicePolicy,
3333
aws_cloudwatch_log_group.this
3434
]
35+
}
36+
37+
resource "null_resource" "wait_for_cluster" {
38+
count = var.manage_aws_auth ? 1 : 0
39+
40+
depends_on = [
41+
aws_eks_cluster.this[0]
42+
]
43+
3544
provisioner "local-exec" {
36-
command = <<EOT
37-
until curl -k -s ${aws_eks_cluster.this[0].endpoint}/healthz >/dev/null; do sleep 4; done
38-
EOT
45+
command = var.wait_for_cluster_cmd
46+
environment = {
47+
ENDPOINT = aws_eks_cluster.this[0].endpoint
48+
}
3949
}
4050
}
4151

variables.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,10 @@ variable "cluster_delete_timeout" {
198198
default = "15m"
199199
}
200200

201-
variable "local_exec_interpreter" {
202-
description = "Command to run for local-exec resources. Must be a shell-style interpreter. If you are on Windows Git Bash is a good choice."
203-
type = list(string)
204-
default = ["/bin/sh", "-c"]
201+
variable "wait_for_cluster_cmd" {
202+
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"
203+
type = string
204+
default = "until curl -k -s $ENDPOINT/healthz >/dev/null; do sleep 4; done"
205205
}
206206

207207
variable "worker_create_initial_lifecycle_hooks" {

0 commit comments

Comments
 (0)