-
-
Notifications
You must be signed in to change notification settings - Fork 37
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
Enable 1 Pod Execution Role Per Cluster #33
Conversation
/terratest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, a few nitpicks
main.tf
Outdated
fargate_profile_iam_role_name = local.fargate_pod_execution_role_name != null ? local.fargate_pod_execution_role_name : ( | ||
var.fargate_profile_enabled ? "${module.role_label.id}${var.iam_role_kubernetes_namespace_delimiter}${var.kubernetes_namespace}" : | ||
module.role_label.id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this would be less painful like this
fargate_profile_iam_role_name = local.fargate_pod_execution_role_name != null ? local.fargate_pod_execution_role_name : ( | |
var.fargate_profile_enabled ? "${module.role_label.id}${var.iam_role_kubernetes_namespace_delimiter}${var.kubernetes_namespace}" : | |
module.role_label.id) | |
fargate_profile_concatenated = "${module.role_label.id}${var.iam_role_kubernetes_namespace_delimiter}${var.kubernetes_namespace}" | |
default_fargate_profile_role_name = var.fargate_profile_enabled ? local.fargate_profile_concatenated : module.role_label.id | |
fargate_profile_iam_role_name = coalesce(local.fargate_pod_execution_role_name, local.default_fargate_profile_role_name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Problem is:
fargate_profile_concatenated = "${module.role_label.id}${var.iam_role_kubernetes_namespace_delimiter}${var.kubernetes_namespace}"
fails with Error if var.kubernetes_namespace
is null, which it could be if user is only provisioning the Pod Execution Role.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay, I wouldn't see why that couldn't be coalesced as well.
So:
fargate_profile_concatenated = "${module.role_label.id}${var.iam_role_kubernetes_namespace_delimiter}${coalesce(var.kubernetes_namespace,"")}"
or if any number of the elements could be null, then use:
fargate_profile_concatenated = join("", compact([module.role_label.id,var.iam_role_kubernetes_namespace_delimiter,var.kubernetes_namespace]))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be clear, I'm just offering options to avoid a nested conditional.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
coalesce
fails when all the arguments are empty. The advantage of the ternary operator in Terraform is that the unused expressions are not evaluated and need not be valid.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is functionally fine, but added some readability and comprehension remarks
/terratest |
/terratest |
what
why