From 4d39166eb2c6297e704cd8ae127ba62208887fbd Mon Sep 17 00:00:00 2001 From: stack72 Date: Fri, 30 Jun 2017 16:02:44 +0300 Subject: [PATCH] resource/aws_ssm_parameter: ForceNew on ssm_parameter rename Fixes: #1008 There doesn't seem to be a way to change the name of an AWS SSM Parameter. Therefore, it should be marked as ForceNew. ``` % make testacc TEST=./aws TESTARGS='-run=TestAccAWSSSMParameter_' ==> Checking that code complies with gofmt requirements... TF_ACC=1 go test ./aws -v -run=TestAccAWSSSMParameter_ -timeout 120m === RUN TestAccAWSSSMParameter_basic --- PASS: TestAccAWSSSMParameter_basic (25.06s) === RUN TestAccAWSSSMParameter_update --- PASS: TestAccAWSSSMParameter_update (43.21s) === RUN TestAccAWSSSMParameter_changeNameForcesNew --- PASS: TestAccAWSSSMParameter_changeNameForcesNew (40.84s) === RUN TestAccAWSSSMParameter_secure --- PASS: TestAccAWSSSMParameter_secure (37.90s) === RUN TestAccAWSSSMParameter_secure_with_key --- PASS: TestAccAWSSSMParameter_secure_with_key (73.26s) PASS ok github.com/terraform-providers/terraform-provider-aws/aws 220.297s ``` --- aws/resource_aws_ssm_parameter.go | 1 + aws/resource_aws_ssm_parameter_test.go | 44 ++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/aws/resource_aws_ssm_parameter.go b/aws/resource_aws_ssm_parameter.go index fb65f1d08fd..72669bfc72c 100644 --- a/aws/resource_aws_ssm_parameter.go +++ b/aws/resource_aws_ssm_parameter.go @@ -21,6 +21,7 @@ func resourceAwsSsmParameter() *schema.Resource { "name": { Type: schema.TypeString, Required: true, + ForceNew: true, }, "type": { Type: schema.TypeString, diff --git a/aws/resource_aws_ssm_parameter_test.go b/aws/resource_aws_ssm_parameter_test.go index 4dcbe6eee49..7ed5d223738 100644 --- a/aws/resource_aws_ssm_parameter_test.go +++ b/aws/resource_aws_ssm_parameter_test.go @@ -50,6 +50,27 @@ func TestAccAWSSSMParameter_update(t *testing.T) { }) } +func TestAccAWSSSMParameter_changeNameForcesNew(t *testing.T) { + before := acctest.RandString(10) + after := acctest.RandString(10) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSSSMParameterDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSSSMParameterBasicConfig(before, "bar"), + }, + { + Config: testAccAWSSSMParameterBasicConfig(after, "bar"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSSSMParameterDestroyed(before), + ), + }, + }, + }) +} + func TestAccAWSSSMParameter_secure(t *testing.T) { name := acctest.RandString(10) resource.Test(t, resource.TestCase{ @@ -147,6 +168,29 @@ func testAccCheckAWSSSMParameterType(n string, v string) resource.TestCheckFunc } } +func testAccCheckAWSSSMParameterDestroyed(name string) resource.TestCheckFunc { + return func(s *terraform.State) error { + conn := testAccProvider.Meta().(*AWSClient).ssmconn + + paramInput := &ssm.GetParametersInput{ + Names: []*string{ + aws.String(name), + }, + } + + resp, err := conn.GetParameters(paramInput) + if err != nil { + return err + } + + if len(resp.Parameters) > 0 { + return fmt.Errorf("Expected AWS SSM Parameter to be gone, but was still found") + } + + return nil + } +} + func testAccCheckAWSSSMParameterDestroy(s *terraform.State) error { conn := testAccProvider.Meta().(*AWSClient).ssmconn