mirror of
https://github.com/ysoftdevs/terraform-aws-eks.git
synced 2026-03-24 10:21:08 +01:00
Upgrade to terraform 0.12 (#394)
* run terraform upgrade tool * fix post upgrade TODOs * use strict typing for variables * upgrade examples, point them at VPC module tf 0.12 PR * remove unnecessary `coalesce()` calls coalesce(lookup(map, key, ""), default) -> lookup(map, key, default) * Fix autoscaling_enabled broken (#1) * always set a value for tags, fix coalescelist calls * always set a value for these tags * fix tag value * fix tag value * default element available * added default value * added a general default without this default - TF is throwing an error when running a destroy * Fix CI * Change vpc module back to `terraform-aws-modules/vpc/aws` in example * Update CHANGELOG.md * Change type of variable `cluster_log_retention_in_days` to number * Remove `xx_count` variables * Actual lists instead of strings with commas * Remove `xx_count` variable from docs * Replace element with list indexing * Change variable `worker_group_tags` to a attribute of worker_group * Fix workers_launch_template_mixed tags * Change override_instance_type_x variables to list. * Update CHANGELOG.md
This commit is contained in:
131
aws_auth.tf
131
aws_auth.tf
@@ -1,103 +1,140 @@
|
||||
resource "local_file" "config_map_aws_auth" {
|
||||
count = "${var.write_aws_auth_config ? 1 : 0}"
|
||||
content = "${data.template_file.config_map_aws_auth.rendered}"
|
||||
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"]
|
||||
count = var.manage_aws_auth ? 1 : 0
|
||||
depends_on = [aws_eks_cluster.this]
|
||||
|
||||
provisioner "local-exec" {
|
||||
working_dir = "${path.module}"
|
||||
working_dir = path.module
|
||||
|
||||
command = <<EOS
|
||||
for i in `seq 1 10`; do \
|
||||
echo "${null_resource.update_config_map_aws_auth.triggers.kube_config_map_rendered}" > kube_config.yaml & \
|
||||
echo "${null_resource.update_config_map_aws_auth.triggers.config_map_rendered}" > aws_auth_configmap.yaml & \
|
||||
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}"]
|
||||
|
||||
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}"
|
||||
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 "aws_caller_identity" "current" {
|
||||
}
|
||||
|
||||
data "template_file" "launch_template_mixed_worker_role_arns" {
|
||||
count = "${var.worker_group_launch_template_mixed_count}"
|
||||
template = "${file("${path.module}/templates/worker-role.tpl")}"
|
||||
count = local.worker_group_launch_template_mixed_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_mixed.*.role, data.aws_iam_instance_profile.custom_worker_group_launch_template_mixed_iam_instance_profile.*.role_name), count.index)}"
|
||||
vars = {
|
||||
worker_role_arn = "arn:aws:iam::${data.aws_caller_identity.current.account_id}:role/${element(
|
||||
coalescelist(
|
||||
aws_iam_instance_profile.workers_launch_template_mixed.*.role,
|
||||
data.aws_iam_instance_profile.custom_worker_group_launch_template_mixed_iam_instance_profile.*.role_name,
|
||||
),
|
||||
count.index,
|
||||
)}"
|
||||
}
|
||||
}
|
||||
|
||||
data "template_file" "launch_template_worker_role_arns" {
|
||||
count = "${var.worker_group_launch_template_count}"
|
||||
template = "${file("${path.module}/templates/worker-role.tpl")}"
|
||||
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)}"
|
||||
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 = "${var.worker_group_count}"
|
||||
template = "${file("${path.module}/templates/worker-role.tpl")}"
|
||||
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)}"
|
||||
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")}"
|
||||
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, data.template_file.launch_template_mixed_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)}"
|
||||
vars = {
|
||||
worker_role_arn = join(
|
||||
"",
|
||||
distinct(
|
||||
concat(
|
||||
data.template_file.launch_template_worker_role_arns.*.rendered,
|
||||
data.template_file.worker_role_arns.*.rendered,
|
||||
data.template_file.launch_template_mixed_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 = "${var.map_users_count}"
|
||||
template = "${file("${path.module}/templates/config-map-aws-auth-map_users.yaml.tpl")}"
|
||||
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")}"
|
||||
vars = {
|
||||
user_arn = var.map_users[count.index]["user_arn"]
|
||||
username = var.map_users[count.index]["username"]
|
||||
group = var.map_users[count.index]["group"]
|
||||
}
|
||||
}
|
||||
|
||||
data "template_file" "map_roles" {
|
||||
count = "${var.map_roles_count}"
|
||||
template = "${file("${path.module}/templates/config-map-aws-auth-map_roles.yaml.tpl")}"
|
||||
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")}"
|
||||
vars = {
|
||||
role_arn = var.map_roles[count.index]["role_arn"]
|
||||
username = var.map_roles[count.index]["username"]
|
||||
group = var.map_roles[count.index]["group"]
|
||||
}
|
||||
}
|
||||
|
||||
data "template_file" "map_accounts" {
|
||||
count = "${var.map_accounts_count}"
|
||||
template = "${file("${path.module}/templates/config-map-aws-auth-map_accounts.yaml.tpl")}"
|
||||
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)}"
|
||||
vars = {
|
||||
account_number = var.map_accounts[count.index]
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user