-
Notifications
You must be signed in to change notification settings - Fork 9.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Terraform Merge on Wildcard Tuple #24645
Comments
Hi! Thanks for reporting this. I think this is probably a valid issue, and I'd like to reproduce it locally. To do that, I have to be able to run this and run it on my workstation without inventing any details in order to be confident we're seeing the same behavior. As-is, I don't know what's in your Can you please restate your reproduction case such that I can copy-paste it and run it locally? Ideally, this would use the null resource provider rather than a real provider in order to minimize external dependencies. |
Hello @danieldreier ! Thanks for looking in to this. Actually, the values in Here is an example: {
"properties": {
"displayName": "require-terraTest2-tag",
"policyType": "Custom",
"mode": "Indexed",
"description": "Policy to require the 'terraTest2' tag for all resources in a scope.",
"metadata": {
"createdBy": "xxx-xxx-xxx-xxx-xxx",
"createdOn": "2020-04-03T11:26:08.7230604Z",
"updatedBy": null,
"updatedOn": null
},
"policyRule": {
"if": {
"allOf": [
{
"anyOf": [
{
"field": "tags",
"notContainsKey": "terraTest2"
},
{
"field": "tags['terraTest2']",
"notIn": "[parameters('allowedTerraTest2')]"
}
]
},
{
"field": "type",
"notIn": "[parameters('listOfResourceTypesAllowed')]"
},
{
"notIn": "[parameters('listOfAllowedResourceGroups')]",
"value": "[resourcegroup().name]"
}
]
},
"then": {
"effect": "deny"
}
},
"parameters": {
"allowedTerraTest2": {
"type": "Array",
"metadata": {
"displayName": "Allowed Terratest Values",
"description": "The list of allowed Terratest Values."
},
"allowedValues": [
"True",
"False"
]
},
"listOfAllowedResourceGroups": {
"type": "Array",
"metadata": {
"displayName": "Allowed resource groups",
"description": "The list of resource groups that can be deployed."
},
"defaultValue": [
"terraTest2-terratest2-rg"
]
},
"listOfResourceTypesAllowed": {
"type": "Array",
"metadata": {
"displayName": "Allowed resource types",
"description": "The list of resource types that can be deployed.",
"strongType": "resourceTypes"
},
"defaultValue": [
"Microsoft.Compute/virtualMachines/extensions"
]
}
},
"id": "/subscriptions/xxx-xxx-xxx-xxx-xxx/providers/Microsoft.Authorization/policyDefinitions/require-terraTest2-tag",
"type": "Microsoft.Authorization/policyDefinitions",
"name": "require-terraTest2-tag"
}
In my test I just duplicate this Policy as Then to reference the resource I use data "azurerm_policy_definition" "d_policy_definitions" {
count = 3
display_name = "require-terraTest${count.index}-tag"
} I found a workaroundIdeally the solution should be as simple as:
But I manage to find a workaround. (I do not claim this to be an optimized code) policy_parameters = [
for key,value in data.azurerm_policy_definition.d_policy_definitions:
{
parameters = jsondecode(value.parameters)
}
]
ph_parameters = local.policy_parameters[*].parameters
input_parameter = [for item in local.ph_parameters: merge(item,local.ph_parameters...)][0] Break down:
policy_parameters = [
for key,value in data.azurerm_policy_definition.d_policy_definitions:
{
parameters = jsondecode(value.parameters)
}
]
ph_parameters = local.policy_parameters[*].parameters
input_parameter = [for item in local.ph_parameters: merge(item,local.ph_parameters...)] The 3rd step gives all items in the list the same value, so we can use any index. Usage: parameters = "${jsonencode(local.input_parameter[n])}" I think this workaround is wasteful. Imagine having 200 indices with the same value. |
Thanks for explaining more. After thinking about it, and reading your explanation, this looks to me like a proposal for new functionality, rather than than a bug report. I'm going to categorize this as an enhancement request. We heavily weight community input in the form of 👍 votes, so if other people read this and would find this useful, please upvote it. |
Terraform Version
Terraform Configuration Files
Debug Output
Crash Output
Expected Behavior
test1 will have the merged parameter values
Actual Behavior
Terraform Error
Steps to Reproduce
Additional Context
Manually adding indices on merge works but Expanding a wildcard variable breaks.
References
None
The text was updated successfully, but these errors were encountered: