Skip to content

Commit

Permalink
Added update aws auth configmap when manage_aws_auth set false case
Browse files Browse the repository at this point in the history
and `write_aws_auth_config` variable for not create the aws_auth files option
  • Loading branch information
yutachaos committed Dec 27, 2018
1 parent 3fc7cd8 commit 0779391
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ MIT Licensed. See [LICENSE](https://github.com/terraform-aws-modules/terraform-a
| worker\_security\_group\_id | If provided, all workers will be attached to this security group. If not given, a security group will be created with necessary ingres/egress to work with the EKS cluster. | string | `` | no |
| worker\_sg\_ingress\_from\_port | Minimum port number from which pods will accept communication. Must be changed to a lower value if some pods in your cluster will expose a port lower than 1025 (e.g. 22, 80, or 443). | string | `1025` | no |
| workers\_group\_defaults | Override default values for target groups. See workers_group_defaults_defaults in locals.tf for valid keys. | map | `{}` | no |
| write\_aws\_auth\_config | Whether to write the aws-auth configmap file. | string | `true` | no |
| write\_kubeconfig | Whether to write a Kubectl config file containing the cluster configuration. Saved to `config_output_path`. | string | `true` | no |
## Outputs
Expand Down
19 changes: 16 additions & 3 deletions aws_auth.tf
Original file line number Diff line number Diff line change
@@ -1,19 +1,32 @@
resource "local_file" "config_map_aws_auth" {
content = "${data.template_file.config_map_aws_auth.rendered}"
filename = "${var.config_output_path}config-map-aws-auth_${var.cluster_name}.yaml"
count = "${var.manage_aws_auth ? 1 : 0}"
count = "${var.write_aws_auth_config ? 1 : 0}"
}

resource "null_resource" "update_config_map_aws_auth" {
depends_on = ["aws_eks_cluster.this"]

provisioner "local-exec" {
command = "for i in {1..5}; do kubectl apply -f ${var.config_output_path}config-map-aws-auth_${var.cluster_name}.yaml --kubeconfig ${var.config_output_path}kubeconfig_${var.cluster_name} && break || sleep 10; done"
working_dir = "${path.module}"

command = <<EOS
mkfifo aws_auth_configmap kube_config & \
for i in {1..5}; do \
echo "${null_resource.update_config_map_aws_auth.triggers.kube_config_map_rendered}" > kube_config & \
echo "${null_resource.update_config_map_aws_auth.triggers.config_map_rendered}" > aws_auth_configmap & \
kubectl apply -f aws_auth_configmap --kubeconfig kube_config && break || \
sleep 10; \
done; \
rm -f aws_auth_configmap kube_config;
EOS

interpreter = ["${var.local_exec_interpreter}"]
}

triggers {
config_map_rendered = "${data.template_file.config_map_aws_auth.rendered}"
kube_config_map_rendered = "${data.template_file.kubeconfig.rendered}"
config_map_rendered = "${data.template_file.config_map_aws_auth.rendered}"
}

count = "${var.manage_aws_auth ? 1 : 0}"
Expand Down
7 changes: 6 additions & 1 deletion variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ variable "write_kubeconfig" {
}

variable "manage_aws_auth" {
description = "Whether to write and apply the aws-auth configmap file."
description = "Whether to apply the aws-auth configmap file."
default = true
}

variable "write_aws_auth_config" {
description = "Whether to write the aws-auth configmap file."
default = true
}

Expand Down

0 comments on commit 0779391

Please sign in to comment.