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

Update azurerm_policy_set_definition - Fix #8663 #8668

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -444,8 +444,8 @@ func expandAzureRMPolicySetDefinitionPolicyDefinitions(input []interface{}) (*[]
v := item.(map[string]interface{})

parameters := make(map[string]*policy.ParameterValuesValue)
if p, ok := v["parameter_values"]; ok {
if err := json.Unmarshal([]byte(p.(string)), &parameters); err != nil {
if p, ok := v["parameter_values"].(string); ok && p != "" {
if err := json.Unmarshal([]byte(p), &parameters); err != nil {
return nil, fmt.Errorf("unmarshalling `parameter_values`: %+v", err)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,24 @@ func TestAccAzureRMPolicySetDefinition_custom(t *testing.T) {
})
}

func TestAccAzureRMPolicySetDefinition_customNoParameter(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_policy_set_definition", "test")
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.PreCheck(t) },
Providers: acceptance.SupportedProviders,
CheckDestroy: testCheckAzureRMPolicySetDefinitionDestroy,
Steps: []resource.TestStep{
{
Config: testAzureRMPolicySetDefinition_customNoParameter(data),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMPolicySetDefinitionExists(data.ResourceName),
),
},
data.ImportStep(),
},
})
}

func TestAccAzureRMPolicySetDefinition_customWithPolicyReferenceID(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_policy_set_definition", "test")

Expand Down Expand Up @@ -367,6 +385,23 @@ VALUES
`, template, data.RandomInteger, data.RandomInteger)
}

func testAzureRMPolicySetDefinition_customNoParameter(data acceptance.TestData) string {
template := testAzureRMPolicySetDefinition_templateNoParameter(data)
return fmt.Sprintf(`
%s

resource "azurerm_policy_set_definition" "test" {
name = "acctestPolSet-%d"
policy_type = "Custom"
display_name = "acctestPolSet-display-%d"

policy_definition_reference {
policy_definition_id = azurerm_policy_definition.test.id
}
}
`, template, data.RandomInteger, data.RandomInteger)
}

func testAzureRMPolicySetDefinition_managementGroupDeprecated(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
Expand Down Expand Up @@ -619,6 +654,35 @@ PARAMETERS
`, data.RandomInteger, data.RandomInteger)
}

func testAzureRMPolicySetDefinition_templateNoParameter(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}

resource "azurerm_policy_definition" "test" {
name = "acctestpol-%d"
policy_type = "Custom"
mode = "All"
display_name = "acctestpol-%d"

policy_rule = <<POLICY_RULE
{
"if": {
"not": {
"field": "location",
"equals": "%s"
}
},
"then": {
"effect": "deny"
}
}
POLICY_RULE
}
`, data.RandomInteger, data.RandomInteger, data.Locations.Primary)
}

func testCheckAzureRMPolicySetDefinitionExists(resourceName string) resource.TestCheckFunc {
return func(s *terraform.State) error {
client := acceptance.AzureProvider.Meta().(*clients.Client).Policy.SetDefinitionsClient
Expand Down