Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DOS-958] Replace built-in functions list and map with first-class syntax #7

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions examples/create_false/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ data "aws_eks_cluster_auth" "cluster" {
}

provider "kubernetes" {
host = element(concat(data.aws_eks_cluster.cluster[*].endpoint, list("")), 0)
cluster_ca_certificate = base64decode(element(concat(data.aws_eks_cluster.cluster[*].certificate_authority.0.data, list("")), 0))
token = element(concat(data.aws_eks_cluster_auth.cluster[*].token, list("")), 0)
host = element(concat(data.aws_eks_cluster.cluster[*].endpoint, [""]), 0)
cluster_ca_certificate = base64decode(element(concat(data.aws_eks_cluster.cluster[*].certificate_authority.0.data, [""]), 0))
token = element(concat(data.aws_eks_cluster_auth.cluster[*].token, [""]), 0)
load_config_file = false
version = "~> 1.11"
}
Expand Down
2 changes: 1 addition & 1 deletion local.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
locals {

cluster_security_group_id = var.cluster_create_security_group ? join("", aws_security_group.cluster.*.id) : var.cluster_security_group_id
cluster_primary_security_group_id = var.cluster_version >= 1.14 ? element(concat(aws_eks_cluster.this[*].vpc_config[0].cluster_security_group_id, list("")), 0) : null
cluster_primary_security_group_id = var.cluster_version >= 1.14 ? element(concat(aws_eks_cluster.this[*].vpc_config[0].cluster_security_group_id, [""]), 0) : null
cluster_iam_role_name = var.manage_cluster_iam_resources ? join("", aws_iam_role.cluster.*.name) : var.cluster_iam_role_name
cluster_iam_role_arn = var.manage_cluster_iam_resources ? join("", aws_iam_role.cluster.*.arn) : join("", data.aws_iam_role.custom_cluster_iam_role.*.arn)
worker_security_group_id = var.worker_create_security_group ? join("", aws_security_group.workers.*.id) : var.worker_security_group_id
Expand Down
4 changes: 2 additions & 2 deletions modules/fargate/locals.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
locals {
create_eks = var.create_eks && length(var.fargate_profiles) > 0
pod_execution_role_arn = var.create_fargate_pod_execution_role ? element(concat(aws_iam_role.eks_fargate_pod.*.arn, list("")), 0) : element(concat(data.aws_iam_role.custom_fargate_iam_role.*.arn, list("")), 0)
pod_execution_role_name = var.create_fargate_pod_execution_role ? element(concat(aws_iam_role.eks_fargate_pod.*.name, list("")), 0) : element(concat(data.aws_iam_role.custom_fargate_iam_role.*.name, list("")), 0)
pod_execution_role_arn = var.create_fargate_pod_execution_role ? element(concat(aws_iam_role.eks_fargate_pod.*.arn, [""]), 0) : element(concat(data.aws_iam_role.custom_fargate_iam_role.*.arn, [""]), 0)
pod_execution_role_name = var.create_fargate_pod_execution_role ? element(concat(aws_iam_role.eks_fargate_pod.*.name, [""]), 0) : element(concat(data.aws_iam_role.custom_fargate_iam_role.*.name, [""]), 0)

fargate_profiles_expanded = { for k, v in var.fargate_profiles : k => merge(
v,
Expand Down
14 changes: 7 additions & 7 deletions outputs.tf
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
output "cluster_id" {
description = "The name/id of the EKS cluster. Will block on cluster creation until the cluster is really ready"
value = element(concat(aws_eks_cluster.this.*.id, list("")), 0)
value = element(concat(aws_eks_cluster.this.*.id, [""]), 0)
# So that calling plans wait for the cluster to be available before attempting
# to use it. They will not need to duplicate this null_resource
depends_on = [null_resource.wait_for_cluster]
}

output "cluster_arn" {
description = "The Amazon Resource Name (ARN) of the cluster."
value = element(concat(aws_eks_cluster.this.*.arn, list("")), 0)
value = element(concat(aws_eks_cluster.this.*.arn, [""]), 0)
}

output "cluster_certificate_authority_data" {
description = "Nested attribute containing certificate-authority-data for your cluster. This is the base64 encoded certificate data required to communicate with your cluster."
value = element(concat(aws_eks_cluster.this[*].certificate_authority[0].data, list("")), 0)
value = element(concat(aws_eks_cluster.this[*].certificate_authority[0].data, [""]), 0)
}

output "cluster_endpoint" {
description = "The endpoint for your EKS Kubernetes API."
value = element(concat(aws_eks_cluster.this.*.endpoint, list("")), 0)
value = element(concat(aws_eks_cluster.this.*.endpoint, [""]), 0)
}

output "cluster_version" {
description = "The Kubernetes server version for the EKS cluster."
value = element(concat(aws_eks_cluster.this[*].version, list("")), 0)
value = element(concat(aws_eks_cluster.this[*].version, [""]), 0)
}

output "cluster_security_group_id" {
Expand Down Expand Up @@ -58,12 +58,12 @@ output "cluster_primary_security_group_id" {

output "cloudwatch_log_group_name" {
description = "Name of cloudwatch log group created"
value = element(concat(aws_cloudwatch_log_group.this[*].name, list("")), 0)
value = element(concat(aws_cloudwatch_log_group.this[*].name, [""]), 0)
}

output "cloudwatch_log_group_arn" {
description = "Arn of cloudwatch log group created"
value = element(concat(aws_cloudwatch_log_group.this[*].arn, list("")), 0)
value = element(concat(aws_cloudwatch_log_group.this[*].arn, [""]), 0)
}

output "kubeconfig" {
Expand Down
10 changes: 5 additions & 5 deletions workers.tf
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,11 @@ resource "aws_autoscaling_group" "workers" {
],
[
for tag_key, tag_value in var.tags :
map(
"key", tag_key,
"value", tag_value,
"propagate_at_launch", "true"
)
{
"key" : tag_key,
"value" : tag_value,
"propagate_at_launch" : "true"
}
if tag_key != "Name" && !contains([for tag in lookup(var.worker_groups[count.index], "tags", local.workers_group_defaults["tags"]) : tag["key"]], tag_key)
],
lookup(
Expand Down
16 changes: 8 additions & 8 deletions workers_launch_template.tf
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ resource "aws_autoscaling_group" "workers_launch_template" {

dynamic "mixed_instances_policy" {
iterator = item
for_each = (lookup(var.worker_groups_launch_template[count.index], "override_instance_types", null) != null) || (lookup(var.worker_groups_launch_template[count.index], "on_demand_allocation_strategy", local.workers_group_defaults["on_demand_allocation_strategy"]) != null) ? list(var.worker_groups_launch_template[count.index]) : []
for_each = (lookup(var.worker_groups_launch_template[count.index], "override_instance_types", null) != null) || (lookup(var.worker_groups_launch_template[count.index], "on_demand_allocation_strategy", local.workers_group_defaults["on_demand_allocation_strategy"]) != null) ? [var.worker_groups_launch_template[count.index]] : []

content {
instances_distribution {
Expand Down Expand Up @@ -164,7 +164,7 @@ resource "aws_autoscaling_group" "workers_launch_template" {

dynamic "launch_template" {
iterator = item
for_each = (lookup(var.worker_groups_launch_template[count.index], "override_instance_types", null) != null) || (lookup(var.worker_groups_launch_template[count.index], "on_demand_allocation_strategy", local.workers_group_defaults["on_demand_allocation_strategy"]) != null) ? [] : list(var.worker_groups_launch_template[count.index])
for_each = (lookup(var.worker_groups_launch_template[count.index], "override_instance_types", null) != null) || (lookup(var.worker_groups_launch_template[count.index], "on_demand_allocation_strategy", local.workers_group_defaults["on_demand_allocation_strategy"]) != null) ? [] : [var.worker_groups_launch_template[count.index]]

content {
id = aws_launch_template.workers_launch_template.*.id[count.index]
Expand Down Expand Up @@ -209,11 +209,11 @@ resource "aws_autoscaling_group" "workers_launch_template" {
],
[
for tag_key, tag_value in var.tags :
map(
"key", tag_key,
"value", tag_value,
"propagate_at_launch", "true"
)
{
"key" : tag_key,
"value" : tag_value,
"propagate_at_launch" : "true"
}
if tag_key != "Name" && !contains([for tag in lookup(var.worker_groups_launch_template[count.index], "tags", local.workers_group_defaults["tags"]) : tag["key"]], tag_key)
],
lookup(
Expand Down Expand Up @@ -363,7 +363,7 @@ resource "aws_launch_template" "workers_launch_template" {
}

dynamic "instance_market_options" {
for_each = lookup(var.worker_groups_launch_template[count.index], "market_type", null) == null ? [] : list(lookup(var.worker_groups_launch_template[count.index], "market_type", null))
for_each = lookup(var.worker_groups_launch_template[count.index], "market_type", null) == null ? [] : [lookup(var.worker_groups_launch_template[count.index], "market_type", null)]
content {
market_type = instance_market_options.value
}
Expand Down
Loading