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

azurerm_policy_set_definition: fix acceptance test policy set with no parameter #23155

Merged
merged 1 commit into from
Sep 4, 2023
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 @@ -587,8 +587,9 @@ func expandAzureRMPolicySetDefinitionPolicyDefinitions(input []interface{}) (*[]
for _, item := range input {
v := item.(map[string]interface{})

parameters := make(map[string]*policy.ParameterValuesValue)
var parameters map[string]*policy.ParameterValuesValue
if p, ok := v["parameter_values"].(string); ok && p != "" {
parameters = make(map[string]*policy.ParameterValuesValue)
if err := json.Unmarshal([]byte(p), &parameters); err != nil {
return nil, fmt.Errorf("unmarshalling `parameter_values`: %+v", err)
}
Expand All @@ -597,6 +598,7 @@ func expandAzureRMPolicySetDefinitionPolicyDefinitions(input []interface{}) (*[]
if len(parameters) > 0 && len(p) > 0 {
return nil, fmt.Errorf("cannot set both `parameters` and `parameter_values`")
}
parameters = make(map[string]*policy.ParameterValuesValue)
for k, value := range p {
parameters[k] = &policy.ParameterValuesValue{
Value: value,
Expand Down
25 changes: 25 additions & 0 deletions internal/services/policy/policy_set_definition_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ func TestAccAzureRMPolicySetDefinition_customNoParameter(t *testing.T) {
),
},
data.ImportStep(),
{
Config: r.customNoParameterUpdate(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
})
}

Expand Down Expand Up @@ -482,6 +489,24 @@ resource "azurerm_policy_set_definition" "test" {
`, template, data.RandomInteger, data.RandomInteger)
}

func (r PolicySetDefinitionResource) customNoParameterUpdate(data acceptance.TestData) string {
template := r.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
parameter_values = "{}"
}
}
`, template, data.RandomInteger, data.RandomInteger)
}

func (r PolicySetDefinitionResource) managementGroup(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
Expand Down