How to update a value for a given key in a list of objects?

Dear Team,
I am trying to create custom effect for an azure policy set definition so that each of the policy can have its own effect. To do this, i have to change the below set of json.

“parameters”: {
“effectA”: {
“type”: “String”,
“metadata”: {
“displayName”: “Effect”,
“description”: “Enable or disable the execution of the policy”
},
“allowedValues”: [
“Audit”,
“Deny”,
“Disabled”
],
“defaultValue”: “Audit”
},
“effectB”: {
“type”: “String”,
“metadata”: {
“displayName”: “Effect”,
“description”: “Enable or disable the execution of the policy”
},
“allowedValues”: [
“Audit”,
“Deny”,
“Disabled”
],
“defaultValue”: “Audit”
}
}

Generally It should be something like below

“parameters”: {
“effectA”: {
“type”: “String”,
“metadata”: {
“displayName”: “EffectA_some_custom_id”,
“description”: “Enable or disable the execution of the policy”
},
“allowedValues”: [
“Audit”,
“Deny”,
“Disabled”
],
“defaultValue”: “Audit”
},
“effectB”: {
“type”: “String”,
“metadata”: {
“displayName”: “EffectB_some_custom_id”,
“description”: “Enable or disable the execution of the policy”
},
“allowedValues”: [
“Audit”,
“Deny”,
“Disabled”
],
“defaultValue”: “Audit”
}
}

so that the value for “displayName”: “EffectA” gets changed to “displayName”:“EffectA_policyName” , with the rest of json stay intact.
Can someone help me in achieving this please ?

Terraform is not a language suited to performing complex transformations on arbitrary JSON structures. I think you would do best to do this in some other programming language.

@maxb Thanks for the quick reply. I thought it is possible to acheive this using terraform.
Do you suggest a better way to do this.

At the moment you have just presented a pure JSON data structure and described (a little) how you want to change it.

You haven’t said where it is coming from, where the extra data you want to substitute in is coming from, or what Terraform code you want to use the result with.

Not knowing these things, all I can suggest is “any general purpose programming language that your area familiar with”.

@maxb I am working to create a azure policy set definition using a group of built-in policies from Azure.
This scenario is that each policy have same parameter keys named effect, but hold different values like Audit, Deny,Disabled based on the policy.
So, in order to create this policy set definition , we need to assign different keys for the parameters. The JSON i shared in this topic contains the parameters that should get updated to keyName_something so that we can assign values individually.

I am stuck with this json updation part and was looking for help in resolving it using terraform :grinning: Please let me know if more information is needed.

I feel I should warn you I have no Azure experience at all, so to me it’s just an arbitrary JSON format.

You didn’t say anything about these things again:

or at least, not in a way I was able to understand without any Azure experience - so my thinking here remains unchanged:

With what I know so far, I think you’d be better off using something other than Terraform to do this.