The below is the custom variable that will use for specific AWS resource creation
INPUT Variable:
VAR = {
"commonPolicy" = [
"DenyRootUser",
"denyIamAccessKeyCreation"
]
"extraPolicy" = [
"denyGlobalService",
"denyBillingModify"
]
}
The interpolation/modification method i am using below to modify the value using Terraform console.
Method:
> { for i,j in var.VAR : "${i}" => [ for k in j : "file('policies/${k}.json')}" ] }
Through this method i am able to get this value when i parse value from specific key:
Like this:
> { for i,j in var.VAR : "${i}" => [ for k in j : "file('policies/${k}.json')}" ] }["commonPolicy"]
OUTPUT:
[
"file('policies/DenyRootUser.json')}",
"file('policies/denyIamAccessKeyCreation.json')}",
]
But the following value i want from interpolation method
Expected Output:
[
file("policies/DenyRootUser.json")},
file("policies/denyIamAccessKeyCreation.json")},
]
NOTE:
- The difference between output & expected output is that i want list of values without doube quotes.
- under file function, the location/path should be under double quotes.
2
Answers
[SOLVED] I resolved this issue by using below method.
Directory Structure:
Method:
main.tf
The above
local_policy_list
variable collect file input and created a list under specific map variable.Terraform console:
As i am getting the expected output but the resultant is similar to the
aws_iam_policy_document
data variablesource_policy_documents
requirement.Example:
You can use it as below which will yield the result as follows:
Is this the expected output?