Skip to content
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

r/policy_definition: allowing the metadata field to be Computed #2939

Merged
merged 1 commit into from
Feb 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions azurerm/resource_arm_policy_definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ func resourceArmPolicyDefinition() *schema.Resource {
"metadata": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateFunc: validation.ValidateJsonString,
DiffSuppressFunc: structure.SuppressJsonDiff,
},
Expand Down
61 changes: 60 additions & 1 deletion azurerm/resource_arm_policy_definition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,30 @@ func TestAccAzureRMPolicyDefinition_requiresImport(t *testing.T) {
})
}

func TestAccAzureRMPolicyDefinition_computedMetadata(t *testing.T) {
resourceName := "azurerm_policy_definition.test"
ri := tf.AccRandTimeInt()

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMPolicyDefinitionDestroy,
Steps: []resource.TestStep{
{
Config: testAzureRMPolicyDefinition_computedMetadata(ri),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMPolicyDefinitionExists(resourceName),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccAzureRMPolicyDefinitionAtMgmtGroup_basic(t *testing.T) {
resourceName := "azurerm_policy_definition.test"
mgmtGroupName := "azurerm_management_group.test"
Expand Down Expand Up @@ -204,6 +228,7 @@ PARAMETERS
}

func testAzureRMPolicyDefinition_requiresImport(ri int) string {
template := testAzureRMPolicyDefinition_basic(ri)
return fmt.Sprintf(`
%s

Expand All @@ -215,7 +240,41 @@ resource "azurerm_policy_definition" "import" {
policy_rule = "${azurerm_policy_definition.test.policy_rule}"
parameters = "${azurerm_policy_definition.test.parameters}"
}
`, testAzureRMPolicyDefinition_basic(ri))
`, template)
}

func testAzureRMPolicyDefinition_computedMetadata(rInt int) string {
return fmt.Sprintf(`
resource "azurerm_policy_definition" "test" {
name = "acctest-%d"
policy_type = "Custom"
mode = "Indexed"
display_name = "DefaultTags"

policy_rule = <<POLICY_RULE
{
"if": {
"field": "tags",
"exists": "false"
},
"then": {
"effect": "append",
"details": [
{
"field": "tags",
"value": {
"environment": "D-137",
"owner": "Rick",
"application": "Portal",
"implementor": "Morty"
}
}
]
}
}
POLICY_RULE
}
`, rInt)
}

func testAzureRMPolicyDefinition_ManagementGroup(ri int) string {
Expand Down