Skip to content
Merged
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
24 changes: 18 additions & 6 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ locals {
auth_service_enabled = local.enabled && var.auth_service_config.enabled
urlrewrite_service_enabled = local.enabled && var.urlrewrite_service_config.enabled

aws_account_id = try(coalesce(var.aws_account_id, data.aws_caller_identity.current[0].account_id), "") # tflint-ignore: terraform_unused_declarations
aws_region_name = try(coalesce(var.aws_region_name, data.aws_region.current[0].name), "")
aws_account_id = one(data.aws_caller_identity.current.*.account_id)
aws_region_name = one(data.aws_region.current.*.region)
aws_partition = one(data.aws_partition.current.*.partition)

service_config = {
rewrite_url = {
Expand Down Expand Up @@ -74,6 +75,10 @@ locals {
result := []
EOF
)

iam_role_attachments = toset(module.this.enabled ? [
"arn:${local.aws_partition}:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
] : [])
}

data "aws_caller_identity" "current" {
Expand All @@ -84,6 +89,10 @@ data "aws_region" "current" {
count = module.this.enabled && var.aws_region_name == "" ? 1 : 0
}

data "aws_partition" "current" {
count = module.this.enabled ? 1 : 0
}

# ====================================================== middleware-services ===

module "mw_service_label" {
Expand Down Expand Up @@ -134,17 +143,20 @@ resource "aws_iam_role" "this" {
}]
})

managed_policy_arns = [
"arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
]

tags = module.mw_service_label.tags

lifecycle {
create_before_destroy = true
}
}

resource "aws_iam_role_policy_attachment" "this" {
for_each = local.iam_role_attachments

role = aws_iam_role.this[0].name
policy_arn = each.key
}

# ============================================================ auth-services ===

module "mw_auth_service_label" {
Expand Down