Files
terraform-aws-eks/aws_auth.tf
Sergiu Plotnicu 461cf5482e Support for Mixed Instances ASG in worker_groups_launch_template variable (#468)
* Create ASG tags via for - utility from terraform 12

* Updated support for mixed ASG in worker_groups_launch_template variable

* Updated launch_template example to include spot and mixed ASG with worker_groups_launch_template variable

* Removed old config

* Removed workers_launch_template_mixed.tf file, added support for mixed/spot in workers_launch_template variable

* Updated examples/spot_instances/main.tf with Mixed Spot and ondemand instances

* Removed launch_template_mixed from relevant files

* Updated README.md file

* Removed workers_launch_template.tf.bkp

* Fixed case with null on_demand_allocation_strategy and Spot allocation

* Fixed workers_launch_template.tf, covered spot instances via Launch Template
2019-09-13 16:50:59 +02:00

87 lines
2.6 KiB
HCL

resource "local_file" "config_map_aws_auth" {
count = var.write_aws_auth_config ? 1 : 0
content = data.template_file.config_map_aws_auth.rendered
filename = "${var.config_output_path}config-map-aws-auth_${var.cluster_name}.yaml"
}
resource "null_resource" "update_config_map_aws_auth" {
count = var.manage_aws_auth ? 1 : 0
depends_on = [aws_eks_cluster.this]
provisioner "local-exec" {
working_dir = path.module
command = <<EOS
for i in `seq 1 10`; do \
echo "${null_resource.update_config_map_aws_auth[0].triggers.kube_config_map_rendered}" > kube_config.yaml & \
echo "${null_resource.update_config_map_aws_auth[0].triggers.config_map_rendered}" > aws_auth_configmap.yaml & \
kubectl apply -f aws_auth_configmap.yaml --kubeconfig kube_config.yaml && break || \
sleep 10; \
done; \
rm aws_auth_configmap.yaml kube_config.yaml;
EOS
interpreter = var.local_exec_interpreter
}
triggers = {
kube_config_map_rendered = data.template_file.kubeconfig.rendered
config_map_rendered = data.template_file.config_map_aws_auth.rendered
endpoint = aws_eks_cluster.this.endpoint
}
}
data "aws_caller_identity" "current" {
}
data "template_file" "launch_template_worker_role_arns" {
count = local.worker_group_launch_template_count
template = file("${path.module}/templates/worker-role.tpl")
vars = {
worker_role_arn = "arn:aws:iam::${data.aws_caller_identity.current.account_id}:role/${element(
coalescelist(
aws_iam_instance_profile.workers_launch_template.*.role,
data.aws_iam_instance_profile.custom_worker_group_launch_template_iam_instance_profile.*.role_name,
),
count.index,
)}"
}
}
data "template_file" "worker_role_arns" {
count = local.worker_group_count
template = file("${path.module}/templates/worker-role.tpl")
vars = {
worker_role_arn = "arn:aws:iam::${data.aws_caller_identity.current.account_id}:role/${element(
coalescelist(
aws_iam_instance_profile.workers.*.role,
data.aws_iam_instance_profile.custom_worker_group_iam_instance_profile.*.role_name,
[""]
),
count.index,
)}"
}
}
data "template_file" "config_map_aws_auth" {
template = file("${path.module}/templates/config-map-aws-auth.yaml.tpl")
vars = {
worker_role_arn = join(
"",
distinct(
concat(
data.template_file.launch_template_worker_role_arns.*.rendered,
data.template_file.worker_role_arns.*.rendered,
),
),
)
map_users = yamlencode(var.map_users),
map_roles = yamlencode(var.map_roles),
map_accounts = yamlencode(var.map_accounts)
}
}