Created
October 14, 2020 05:09
-
-
Save jesseloudon/887157ba06d74179a698c608dae2ff54 to your computer and use it in GitHub Desktop.
Example of passing array parameter to AzureRM policyset resource
This file contains 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
terraform { | |
required_version = "~> 0.13.0" | |
required_providers { | |
azurerm = { | |
source = "hashicorp/azurerm" | |
version = "~> 2.29.0" | |
} | |
} | |
} | |
provider "azurerm" { | |
features {} | |
} | |
variable "policyset_definitions" { | |
type = list | |
description = "array of built-in policy definitions" | |
default = [ | |
"Allowed locations for resource groups" | |
] | |
} | |
data "azurerm_policy_definition" "policyset_definitions" { | |
count = length(var.policyset_definitions) | |
display_name = var.policyset_definitions[count.index] | |
} | |
resource "azurerm_policy_set_definition" "custompolicyset" { | |
name = "CustomPolicySet" | |
policy_type = "Custom" | |
display_name = "CustomPolicySet" | |
parameters = <<PARAMETERS | |
{ | |
"allowedLocations": { | |
"type": "Array", | |
"metadata": { | |
"description": "The list of locations that resource groups can be created in.", | |
"displayName": "Allowed locations", | |
"strongType": "location" | |
}, | |
"defaultValue": [ | |
"australiaeast", | |
"australiasoutheast" | |
] | |
} | |
} | |
PARAMETERS | |
policy_definition_reference { | |
policy_definition_id = data.azurerm_policy_definition.policyset_definitions.*.id[0] | |
parameter_values = <<VALUE | |
{ | |
"listOfAllowedLocations": {"value": "[parameters('allowedLocations')]"} | |
} | |
VALUE | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment