Created
February 18, 2022 20:33
-
-
Save sairamkrish/aefd45d88564514de978d7aef9fe5181 to your computer and use it in GitHub Desktop.
terraform demo benefit of jsonencode
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Not good | |
resource "aws_iam_policy" "secrets_policy" { | |
name = "some_name" | |
policy = <<EOF | |
{ | |
"Version": "2012-10-17", | |
"Statement": [ | |
{ | |
"Action": "secretsmanager:GetSecretValue", | |
"Effect": "Allow". # syntax error - dot instead of comma | |
"Resource": [ | |
"${aws_secretsmanager_secret.my_secrets.arn}" | |
] | |
} | |
] | |
} | |
EOF | |
} | |
# Better option - using jsonencode | |
resource "aws_iam_policy" "secrets_policy" { | |
name = "some_name" | |
policy = jsonencode({ | |
"Version": "2012-10-17", | |
"Statement": [ | |
{ | |
"Action": "secretsmanager:GetSecretValue", | |
"Effect": "Allow". # syntax error - dot instead of comma | |
"Resource": [ | |
"${aws_secretsmanager_secret.my_secrets.arn}" | |
] | |
} | |
] | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment