Skip to content

Commit

Permalink
fix: depends_on and random_id to sns publish policy
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian-Soares committed Jul 17, 2024
1 parent 8f4a42e commit a365fa7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
17 changes: 17 additions & 0 deletions infrastructure/ebs-checker/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 11 additions & 3 deletions infrastructure/modules/complete/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@ module "lambda_function" {
security_group_ids = var.lambda_vpc_config.security_group_ids
} : null
env = var.lambda_function_env
custom_policy_arns = try(concat(var.lambda_function_custom_policy_arns, ["arn:aws:iam::${data.aws_caller_identity.current.account_id}:policy/sns-publish-policy"]), ["arn:aws:iam::${data.aws_caller_identity.current.account_id}:policy/sns-publish-policy"])
custom_policy_arns = try(concat(var.lambda_function_custom_policy_arns, ["arn:aws:iam::${data.aws_caller_identity.current.account_id}:policy/sns-publish-policy-${random_id.id.hex}"]), ["arn:aws:iam::${data.aws_caller_identity.current.account_id}:policy/sns-publish-policy-${random_id.id.hex}"])
tags = merge(var.lambda_function_tags, var.default_tags)

depends_on = [
aws_iam_policy.sns_publish
]
}

module "sns_topic" {
Expand All @@ -31,7 +35,7 @@ module "sns_topic" {
}

resource "aws_iam_policy" "sns_publish" {
name = "sns-publish-policy"
name = "sns-publish-policy-${random_id.id.hex}"
description = "IAM policy for publishing to the SNS topic"

policy = jsonencode({
Expand All @@ -40,8 +44,12 @@ resource "aws_iam_policy" "sns_publish" {
{
Effect = "Allow"
Action = "sns:Publish"
Resource = module.sns_topic.arn
Resource = module.sns_topic.topic_arn
},
]
})
}

resource "random_id" "id" {
byte_length = 8
}

0 comments on commit a365fa7

Please sign in to comment.