Skip to content

Commit

Permalink
Fix errors from usage of coalesce (terraform-aws-modules#402) (terraf…
Browse files Browse the repository at this point in the history
…orm-aws-modules#459)

* Replace coalesce() usage for locals with ternary operator. Fixes terraform errors during destroy when only empty strings were passed to coalesce().

* Update changelog.

* Fix formatting.
  • Loading branch information
petrikero authored and max-rocket-internet committed Aug 6, 2019
1 parent ebac6c9 commit c9986f5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 21 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ project adheres to [Semantic Versioning](http://semver.org/).

### Changed

- Fixed errors sometimes happening during destroy due to usage of coalesce() in local.tf (by @petrikero)
- Write your awesome change here (by @you)

# History
Expand Down
25 changes: 4 additions & 21 deletions local.tf
Original file line number Diff line number Diff line change
@@ -1,28 +1,11 @@
locals {
asg_tags = null_resource.tags_as_list_of_maps.*.triggers

# Followed recommendation http://67bricks.com/blog/?p=85
# to workaround terraform not supporting short circut evaluation
cluster_security_group_id = coalesce(
join("", aws_security_group.cluster.*.id),
var.cluster_security_group_id,
)
cluster_security_group_id = var.cluster_create_security_group ? aws_security_group.cluster[0].id : var.cluster_security_group_id
cluster_iam_role_name = var.manage_cluster_iam_resources ? aws_iam_role.cluster[0].name : var.cluster_iam_role_name
cluster_iam_role_arn = var.manage_cluster_iam_resources ? aws_iam_role.cluster[0].arn : data.aws_iam_role.custom_cluster_iam_role[0].arn
worker_security_group_id = var.worker_create_security_group ? aws_security_group.workers[0].id : var.worker_security_group_id

cluster_iam_role_name = coalesce(
join("", aws_iam_role.cluster.*.name),
var.cluster_iam_role_name,
"aws-eks"
)
cluster_iam_role_arn = coalesce(
join("", aws_iam_role.cluster.*.arn),
join("", data.aws_iam_role.custom_cluster_iam_role.*.arn),
"aws-eks"
)

worker_security_group_id = coalesce(
join("", aws_security_group.workers.*.id),
var.worker_security_group_id,
)
default_iam_role_id = concat(aws_iam_role.workers.*.id, [""])[0]
kubeconfig_name = var.kubeconfig_name == "" ? "eks_${var.cluster_name}" : var.kubeconfig_name

Expand Down

0 comments on commit c9986f5

Please sign in to comment.