Files
terraform-aws-eks/aws_auth.tf
Matthew Caya cd7e56c821 Fixed issue with 'workers_group_defaults_defaults.iam_role_id' and added explicit depends_on for 'update_config_map_aws_auth' (#147)
* fix worker default 'iam_role_id' dependency

* Add explicit depends_on to eks cluster for 'update_config_map_aws_auth'
2018-10-09 10:38:00 +02:00

73 lines
2.5 KiB
HCL

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}"
}
resource "null_resource" "update_config_map_aws_auth" {
depends_on = ["aws_eks_cluster.this"]
provisioner "local-exec" {
command = "kubectl apply -f ${var.config_output_path}config-map-aws-auth_${var.cluster_name}.yaml --kubeconfig ${var.config_output_path}kubeconfig_${var.cluster_name}"
}
triggers {
config_map_rendered = "${data.template_file.config_map_aws_auth.rendered}"
}
count = "${var.manage_aws_auth ? 1 : 0}"
}
data "aws_caller_identity" "current" {}
data "template_file" "worker_role_arns" {
count = "${var.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(aws_iam_instance_profile.workers.*.role, 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(data.template_file.worker_role_arns.*.rendered))}"
map_users = "${join("", data.template_file.map_users.*.rendered)}"
map_roles = "${join("", data.template_file.map_roles.*.rendered)}"
map_accounts = "${join("", data.template_file.map_accounts.*.rendered)}"
}
}
data "template_file" "map_users" {
count = "${length(var.map_users)}"
template = "${file("${path.module}/templates/config-map-aws-auth-map_users.yaml.tpl")}"
vars {
user_arn = "${lookup(var.map_users[count.index], "user_arn")}"
username = "${lookup(var.map_users[count.index], "username")}"
group = "${lookup(var.map_users[count.index], "group")}"
}
}
data "template_file" "map_roles" {
count = "${length(var.map_roles)}"
template = "${file("${path.module}/templates/config-map-aws-auth-map_roles.yaml.tpl")}"
vars {
role_arn = "${lookup(var.map_roles[count.index], "role_arn")}"
username = "${lookup(var.map_roles[count.index], "username")}"
group = "${lookup(var.map_roles[count.index], "group")}"
}
}
data "template_file" "map_accounts" {
count = "${length(var.map_accounts)}"
template = "${file("${path.module}/templates/config-map-aws-auth-map_accounts.yaml.tpl")}"
vars {
account_number = "${element(var.map_accounts, count.index)}"
}
}