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

configservice/remediation_configuration: parameters TypeSet -> TypeList #31315

Merged
merged 2 commits into from
May 11, 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
3 changes: 3 additions & 0 deletions .changelog/31315.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_config_remediation_configuration: Change `parameter` attribute to `TypeList` for better diff calculation
```
13 changes: 7 additions & 6 deletions internal/service/configservice/configservice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,13 @@ func TestAccConfigService_serial(t *testing.T) {
"TagValueScope": testAccOrganizationManagedRule_TagValueScope,
},
"RemediationConfiguration": {
"basic": testAccRemediationConfiguration_basic,
"basicBackward": testAccRemediationConfiguration_basicBackwardCompatible,
"disappears": testAccRemediationConfiguration_disappears,
"recreates": testAccRemediationConfiguration_recreates,
"updates": testAccRemediationConfiguration_updates,
"values": testAccRemediationConfiguration_values,
"basic": testAccRemediationConfiguration_basic,
"basicBackward": testAccRemediationConfiguration_basicBackwardCompatible,
"disappears": testAccRemediationConfiguration_disappears,
"migrateParameters": testAccRemediationConfiguration_migrateParameters,
"recreates": testAccRemediationConfiguration_recreates,
"updates": testAccRemediationConfiguration_updates,
"values": testAccRemediationConfiguration_values,
},
}

Expand Down
25 changes: 17 additions & 8 deletions internal/service/configservice/remediation_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/hashicorp/terraform-provider-aws/internal/flex"
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
"github.com/hashicorp/terraform-provider-aws/names"
"golang.org/x/exp/slices"
)

const (
Expand Down Expand Up @@ -87,7 +88,7 @@ func ResourceRemediationConfiguration() *schema.Resource {
ValidateFunc: validation.IntBetween(1, 25),
},
"parameter": {
Type: schema.TypeSet,
Type: schema.TypeList,
MaxItems: 25,
Optional: true,
Elem: &schema.Resource{
Expand All @@ -108,6 +109,7 @@ func ResourceRemediationConfiguration() *schema.Resource {
"static_values": {
Type: schema.TypeList,
Optional: true,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
},
Expand Down Expand Up @@ -149,8 +151,8 @@ func resourceRemediationConfigurationPut(ctx context.Context, d *schema.Resource
ConfigRuleName: aws.String(name),
}

if v, ok := d.GetOk("parameter"); ok && v.(*schema.Set).Len() > 0 {
input.Parameters = expandRemediationParameterValues(v.(*schema.Set).List())
if v, ok := d.GetOk("parameter"); ok && len(v.([]interface{})) > 0 {
input.Parameters = expandRemediationParameterValues(v.([]interface{}))
}
if v, ok := d.GetOk("resource_type"); ok {
input.ResourceType = aws.String(v.(string))
Expand Down Expand Up @@ -380,16 +382,23 @@ func flattenRemediationParameterValues(parameters map[string]*configservice.Reme
if v := value.ResourceValue; v != nil {
item["resource_value"] = aws.StringValue(v.Value)
}
if v := value.StaticValue; v != nil && len(v.Values) > 1 {
item["static_values"] = aws.StringValueSlice(v.Values)
}
if v := value.StaticValue; v != nil && len(v.Values) == 1 {
item["static_value"] = aws.StringValue(v.Values[0])
if v := value.StaticValue; v != nil {
if len(v.Values) == 1 {
item["static_value"] = aws.StringValue(v.Values[0])
} else if len(v.Values) > 1 {
item["static_values"] = aws.StringValueSlice(v.Values)
}
} else {
item["static_values"] = make([]interface{}, 0)
}

items = append(items, item)
}

slices.SortFunc(items, func(a, b interface{}) bool {
return a.(map[string]interface{})["name"].(string) < b.(map[string]interface{})["name"].(string)
})

return items
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,47 @@ func testAccRemediationConfiguration_values(t *testing.T) {
})
}

func testAccRemediationConfiguration_migrateParameters(t *testing.T) {
ctx := acctest.Context(t)
var rc configservice.RemediationConfiguration
resourceName := "aws_config_remediation_configuration.test"
rInt := sdkacctest.RandInt()
automatic := "false"
rAttempts := sdkacctest.RandIntRange(1, 25)
rSeconds := sdkacctest.RandIntRange(1, 2678000)
rExecPct := sdkacctest.RandIntRange(1, 100)
rErrorPct := sdkacctest.RandIntRange(1, 100)
prefix := "Original"
sseAlgorithm := "AES256"
expectedName := fmt.Sprintf("%s-tf-acc-test-%d", prefix, rInt)

resource.Test(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t) },
ErrorCheck: acctest.ErrorCheck(t, configservice.EndpointsID),
CheckDestroy: testAccCheckRemediationConfigurationDestroy(ctx),
Steps: []resource.TestStep{
{
ExternalProviders: map[string]resource.ExternalProvider{
"aws": {
Source: "hashicorp/aws",
VersionConstraint: "4.66.0",
},
},
Config: testAccRemediationConfigurationConfig_basic(prefix, sseAlgorithm, rInt, rAttempts, rSeconds, rExecPct, rErrorPct, automatic),
Check: resource.ComposeTestCheckFunc(
testAccCheckRemediationConfigurationExists(ctx, resourceName, &rc),
resource.TestCheckResourceAttr(resourceName, "config_rule_name", expectedName),
),
},
{
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
Config: testAccRemediationConfigurationConfig_basic(prefix, sseAlgorithm, rInt, rAttempts, rSeconds, rExecPct, rErrorPct, automatic),
PlanOnly: true,
},
},
})
}

func testAccCheckRemediationConfigurationExists(ctx context.Context, n string, obj *configservice.RemediationConfiguration) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
Expand Down