diff --git a/.changelog/32372.txt b/.changelog/32372.txt new file mode 100644 index 00000000000..2453cc73d35 --- /dev/null +++ b/.changelog/32372.txt @@ -0,0 +1,3 @@ +```release-note:bug +resource/aws_ssm_parameter: Skip Update if only `overwrite` parameter changes +``` diff --git a/internal/service/ssm/parameter.go b/internal/service/ssm/parameter.go index f764429885a..544385cfa6c 100644 --- a/internal/service/ssm/parameter.go +++ b/internal/service/ssm/parameter.go @@ -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 != "" { diff --git a/internal/service/ssm/parameter_test.go b/internal/service/ssm/parameter_test.go index 1f37c50e38d..f76fb13f00e 100644 --- a/internal/service/ssm/parameter_test.go +++ b/internal/service/ssm/parameter_test.go @@ -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, ¶m), + 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, ¶m), + 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, ¶m), + 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, ¶m), + resource.TestCheckResourceAttr(resourceName, "description", "updated description"), + resource.TestCheckResourceAttr(resourceName, "type", "String"), + resource.TestCheckResourceAttr(resourceName, "value", "test"), + resource.TestCheckNoResourceAttr(resourceName, "overwrite"), ), }, { @@ -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"), ), }, { @@ -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"), ), }, }, @@ -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, ¶m), + resource.TestCheckResourceAttr(resourceName, "overwrite", "true"), + ), + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + Config: testAccParameterConfig_overwriteRemove_Remove(rName, "String", "value1"), + Check: resource.ComposeTestCheckFunc( + testAccCheckParameterExists(ctx, resourceName, ¶m), + resource.TestCheckResourceAttr(resourceName, "overwrite", "false"), + ), + }, + }, + }) +} func TestAccSSMParameter_tags(t *testing.T) { ctx := acctest.Context(t) @@ -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" { @@ -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" {