I am rendering a .json
document containing a policy:
data "template_file" "my_role_policy" {
template = file("iam_role_policy_template.json")
vars = {
ACCESS_TO_SM = false
FOO = bar
}
}
Within the iam_role_policy_template.json
, I have the following snippet
%{ if try(ACCESS_TO_SM, false) }
{
"Effect": "Allow",
"Action": [
"s3:PutObject",
"s3:GetObject",
],
"Resource": "s3://my-bucket/my-path"
}
%{ endif }
This is because there are other .tf
files using the same template that (for some reason) may not pass this variable.
The plan fails with the error
Error: failed to render : <template_file>:20,15-18: Call to unknown function; There is no function named “try”.
I thought it was possible to use it in a template.