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

resource/aws_ssm_parameter: Ignore Update if only overwrite parameter changes #32372

Merged
merged 2 commits into from
Jul 5, 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/32372.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_ssm_parameter: Skip Update if only `overwrite` parameter changes
```
2 changes: 1 addition & 1 deletion internal/service/ssm/parameter.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ func resourceParameterUpdate(ctx context.Context, d *schema.ResourceData, meta i
var diags diag.Diagnostics
conn := meta.(*conns.AWSClient).SSMConn(ctx)

if d.HasChangesExcept("tags", "tags_all") {
if d.HasChangesExcept("overwrite", "tags", "tags_all") {
value := d.Get("value").(string)

if v, ok := d.Get("insecure_value").(string); ok && v != "" {
Expand Down
167 changes: 167 additions & 0 deletions internal/service/ssm/parameter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,101 @@ func TestAccSSMParameter_basic(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "tags.%", "0"),
resource.TestCheckResourceAttrSet(resourceName, "version"),
resource.TestCheckResourceAttr(resourceName, "data_type", "text"),
resource.TestCheckNoResourceAttr(resourceName, "overwrite"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"overwrite"},
},
},
})
}

func TestAccSSMParameter_updateValue(t *testing.T) {
ctx := acctest.Context(t)
var param ssm.Parameter
name := fmt.Sprintf("%s_%s", t.Name(), sdkacctest.RandString(10))
resourceName := "aws_ssm_parameter.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t) },
ErrorCheck: acctest.ErrorCheck(t, ssm.EndpointsID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckParameterDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccParameterConfig_basic(name, "String", "test"),
Check: resource.ComposeTestCheckFunc(
testAccCheckParameterExists(ctx, resourceName, &param),
resource.TestCheckResourceAttr(resourceName, "type", "String"),
resource.TestCheckResourceAttr(resourceName, "value", "test"),
resource.TestCheckNoResourceAttr(resourceName, "overwrite"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"overwrite"},
},
{
Config: testAccParameterConfig_basic(name, "String", "test2"),
Check: resource.ComposeTestCheckFunc(
testAccCheckParameterExists(ctx, resourceName, &param),
resource.TestCheckResourceAttr(resourceName, "type", "String"),
resource.TestCheckResourceAttr(resourceName, "value", "test2"),
resource.TestCheckNoResourceAttr(resourceName, "overwrite"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"overwrite"},
},
},
})
}

func TestAccSSMParameter_updateDescription(t *testing.T) {
ctx := acctest.Context(t)
var param ssm.Parameter
name := fmt.Sprintf("%s_%s", t.Name(), sdkacctest.RandString(10))
resourceName := "aws_ssm_parameter.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t) },
ErrorCheck: acctest.ErrorCheck(t, ssm.EndpointsID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckParameterDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccParameterConfig_description(name, "description", "String", "test"),
Check: resource.ComposeTestCheckFunc(
testAccCheckParameterExists(ctx, resourceName, &param),
resource.TestCheckResourceAttr(resourceName, "description", "description"),
resource.TestCheckResourceAttr(resourceName, "type", "String"),
resource.TestCheckResourceAttr(resourceName, "value", "test"),
resource.TestCheckNoResourceAttr(resourceName, "overwrite"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"overwrite"},
},
{
Config: testAccParameterConfig_description(name, "updated description", "String", "test"),
Check: resource.ComposeTestCheckFunc(
testAccCheckParameterExists(ctx, resourceName, &param),
resource.TestCheckResourceAttr(resourceName, "description", "updated description"),
resource.TestCheckResourceAttr(resourceName, "type", "String"),
resource.TestCheckResourceAttr(resourceName, "value", "test"),
resource.TestCheckNoResourceAttr(resourceName, "overwrite"),
),
},
{
Expand Down Expand Up @@ -316,12 +411,14 @@ func TestAccSSMParameter_Overwrite_basic(t *testing.T) {
Config: testAccParameterConfig_basicOverwrite(name, "String", "This value is set using Terraform"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "version", "2"),
resource.TestCheckResourceAttr(resourceName, "overwrite", "true"),
),
},
{
Config: testAccParameterConfig_basicOverwrite(name, "String", "test2"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "version", "3"),
resource.TestCheckResourceAttr(resourceName, "overwrite", "true"),
),
},
{
Expand All @@ -337,6 +434,7 @@ func TestAccSSMParameter_Overwrite_basic(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "value", "test3"),
resource.TestCheckResourceAttr(resourceName, "type", "String"),
resource.TestCheckResourceAttr(resourceName, "version", "4"),
resource.TestCheckResourceAttr(resourceName, "overwrite", "true"),
),
},
},
Expand Down Expand Up @@ -468,6 +566,41 @@ func TestAccSSMParameter_Overwrite_updateToTags(t *testing.T) {
},
})
}
func TestAccSSMParameter_Overwrite_removeAttribute(t *testing.T) {
ctx := acctest.Context(t)
var param ssm.Parameter
rName := fmt.Sprintf("%s_%s", t.Name(), sdkacctest.RandString(10))
resourceName := "aws_ssm_parameter.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t) },
ErrorCheck: acctest.ErrorCheck(t, ssm.EndpointsID),
CheckDestroy: testAccCheckParameterDestroy(ctx),
Steps: []resource.TestStep{
{
ExternalProviders: map[string]resource.ExternalProvider{
"aws": {
Source: "hashicorp/aws",
VersionConstraint: "4.67.0",
},
},
Config: testAccParameterConfig_overwriteRemove_Setup(rName, "String", "value1"),
Check: resource.ComposeTestCheckFunc(
testAccCheckParameterExists(ctx, resourceName, &param),
resource.TestCheckResourceAttr(resourceName, "overwrite", "true"),
),
},
{
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
Config: testAccParameterConfig_overwriteRemove_Remove(rName, "String", "value1"),
Check: resource.ComposeTestCheckFunc(
testAccCheckParameterExists(ctx, resourceName, &param),
resource.TestCheckResourceAttr(resourceName, "overwrite", "false"),
),
},
},
})
}

func TestAccSSMParameter_tags(t *testing.T) {
ctx := acctest.Context(t)
Expand Down Expand Up @@ -983,6 +1116,17 @@ resource "aws_ssm_parameter" "test" {
`, rName, pType, value)
}

func testAccParameterConfig_description(rName, description, pType, value string) string {
return fmt.Sprintf(`
resource "aws_ssm_parameter" "test" {
name = %[1]q
description = %[2]q
type = %[3]q
value = %[4]q
}
`, rName, description, pType, value)
}

func testAccParameterConfig_insecure(rName, pType, value string) string {
return fmt.Sprintf(`
resource "aws_ssm_parameter" "test" {
Expand Down Expand Up @@ -1124,6 +1268,29 @@ resource "aws_ssm_parameter" "test_downstream" {
`, rName, value)
}

func testAccParameterConfig_overwriteRemove_Setup(rName, pType, value string) string {
return fmt.Sprintf(`
resource "aws_ssm_parameter" "test" {
name = "test_parameter-%[1]s"
description = "description for parameter %[1]s"
type = "%[2]s"
value = "%[3]s"
overwrite = true
}
`, rName, pType, value)
}

func testAccParameterConfig_overwriteRemove_Remove(rName, pType, value string) string {
return fmt.Sprintf(`
resource "aws_ssm_parameter" "test" {
name = "test_parameter-%[1]s"
description = "description for parameter %[1]s"
type = "%[2]s"
value = "%[3]s"
}
`, rName, pType, value)
}

func testAccParameterConfig_secure(rName string, value string) string {
return fmt.Sprintf(`
resource "aws_ssm_parameter" "test" {
Expand Down