Created
October 14, 2020 05:36
-
-
Save jesseloudon/73f7c6069945084b75ca02f93cf178bc to your computer and use it in GitHub Desktop.
Example of passing multiple array parameters to an AzureRM policyset resource with multiple policies
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", | |
"Allowed virtual machine size SKUs" | |
] | |
} | |
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" | |
] | |
}, | |
"listOfAllowedSKUs": { | |
"type": "Array", | |
"metadata": { | |
"description": "The list of size SKUs that can be specified for virtual machines.", | |
"displayName": "Allowed Size SKUs", | |
"strongType": "VMSKUs" | |
}, | |
"defaultValue": [ | |
"standard_b2s", | |
"standard_d2", | |
"standard_d2_v2" | |
] | |
} | |
} | |
PARAMETERS | |
policy_definition_reference { | |
policy_definition_id = data.azurerm_policy_definition.policyset_definitions.*.id[0] | |
parameter_values = <<VALUE | |
{ | |
"listOfAllowedLocations": {"value": "[parameters('allowedLocations')]"} | |
} | |
VALUE | |
} | |
policy_definition_reference { | |
policy_definition_id = data.azurerm_policy_definition.policyset_definitions.*.id[1] | |
parameter_values = <<VALUE | |
{ | |
"listOfAllowedSKUs": {"value": "[parameters('listOfAllowedSKUs')]"} | |
} | |
VALUE | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment