Skip to content

fix: Correct logic for local needs_infrastructure_iam_role check #224

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

Merged
merged 5 commits into from
Sep 3, 2024
Merged
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
1 change: 0 additions & 1 deletion examples/ec2-autoscaling/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ module "ecs_service" {
}
}

create_infrastructure_iam_role = true
volume_configuration = {
ebs-volume = {
managed_ebs_volume = {
Expand Down
2 changes: 1 addition & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ module "service" {
iam_role_statements = lookup(each.value, "iam_role_statements", {})

# ECS infrastructure IAM role
create_infrastructure_iam_role = try(each.value.create_infrastructure_iam_role, false)
create_infrastructure_iam_role = try(each.value.create_infrastructure_iam_role, true)
infrastructure_iam_role_arn = try(each.value.infrastructure_iam_role_arn, null)
infrastructure_iam_role_name = try(each.value.infrastructure_iam_role_name, null)
infrastructure_iam_role_use_name_prefix = try(each.value.infrastructure_iam_role_use_name_prefix, true)
Expand Down
8 changes: 5 additions & 3 deletions modules/service/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ resource "aws_ecs_service" "this" {
for_each = try([volume_configuration.value.managed_ebs_volume], [])

content {
role_arn = try(aws_iam_role.infrastructure_iam_role[0].arn, var.infrastructure_iam_role_arn)
role_arn = local.infrastructure_iam_role_arn
encrypted = try(managed_ebs_volume.value.encrypted, null)
file_system_type = try(managed_ebs_volume.value.file_system_type, null)
iops = try(managed_ebs_volume.value.iops, null)
Expand Down Expand Up @@ -254,7 +254,8 @@ resource "aws_ecs_service" "this" {

depends_on = [
aws_iam_role_policy_attachment.service,
aws_iam_role_policy_attachment.infrastructure_iam_role_ebs_policy
aws_iam_role_policy_attachment.infrastructure_iam_role_ebs_policy,
aws_iam_role.infrastructure_iam_role,
]

lifecycle {
Expand Down Expand Up @@ -1505,8 +1506,9 @@ resource "aws_security_group_rule" "this" {
############################################################################################

locals {
needs_infrastructure_iam_role = var.volume_configuration != null
needs_infrastructure_iam_role = length(var.volume_configuration) > 0
create_infrastructure_iam_role = var.create && var.create_infrastructure_iam_role && local.needs_infrastructure_iam_role
infrastructure_iam_role_arn = local.needs_infrastructure_iam_role ? try(aws_iam_role.infrastructure_iam_role[0].arn, var.infrastructure_iam_role_arn) : null
infrastructure_iam_role_name = try(coalesce(var.infrastructure_iam_role_name, var.name), "")
}

Expand Down