Skip to content

Commit

Permalink
resource/aws_ssm_parameter: ForceNew on ssm_parameter rename (#1022)
Browse files Browse the repository at this point in the history
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
```
  • Loading branch information
stack72 authored Jul 6, 2017
1 parent 48193e7 commit 0e47e25
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
1 change: 1 addition & 0 deletions aws/resource_aws_ssm_parameter.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func resourceAwsSsmParameter() *schema.Resource {
"name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"type": {
Type: schema.TypeString,
Expand Down
44 changes: 44 additions & 0 deletions aws/resource_aws_ssm_parameter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 0e47e25

Please sign in to comment.