Skip to content

Commit

Permalink
Merge pull request #8664 from terraform-providers/b-aws_ssm_parameter…
Browse files Browse the repository at this point in the history
…-tier-validationexception

resource/aws_ssm_parameter: Remove Tier from PutParameter if unsupported, fix testing for GovCloud
  • Loading branch information
bflad authored May 17, 2019
2 parents 40c41dc + 07fb37e commit b203096
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
14 changes: 12 additions & 2 deletions aws/resource_aws_ssm_parameter.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,10 @@ func resourceAwsSsmParameterRead(d *schema.ResourceData, meta interface{}) error
detail := describeResp.Parameters[0]
d.Set("key_id", detail.KeyId)
d.Set("description", detail.Description)
d.Set("tier", detail.Tier)
d.Set("tier", ssm.ParameterTierStandard)
if detail.Tier != nil {
d.Set("tier", detail.Tier)
}
d.Set("allowed_pattern", detail.AllowedPattern)

if tagList, err := ssmconn.ListTagsForResource(&ssm.ListTagsForResourceInput{
Expand Down Expand Up @@ -209,7 +212,14 @@ func resourceAwsSsmParameterPut(d *schema.ResourceData, meta interface{}) error
}

log.Printf("[DEBUG] Waiting for SSM Parameter %v to be updated", d.Get("name"))
if _, err := ssmconn.PutParameter(paramInput); err != nil {
_, err := ssmconn.PutParameter(paramInput)

if isAWSErr(err, "ValidationException", "Tier is not supported") {
paramInput.Tier = nil
_, err = ssmconn.PutParameter(paramInput)
}

if err != nil {
return fmt.Errorf("error creating SSM parameter: %s", err)
}

Expand Down
7 changes: 2 additions & 5 deletions aws/resource_aws_ssm_parameter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package aws

import (
"fmt"
"regexp"
"testing"

"github.com/aws/aws-sdk-go/aws"
Expand Down Expand Up @@ -49,8 +48,7 @@ func TestAccAWSSSMParameter_basic(t *testing.T) {
Config: testAccAWSSSMParameterBasicConfig(name, "String", "bar"),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSSSMParameterExists("aws_ssm_parameter.foo", &param),
resource.TestMatchResourceAttr("aws_ssm_parameter.foo", "arn",
regexp.MustCompile(fmt.Sprintf("^arn:aws:ssm:[a-z0-9-]+:[0-9]{12}:parameter/%s$", name))),
testAccCheckResourceAttrRegionalARN("aws_ssm_parameter.foo", "arn", "ssm", fmt.Sprintf("parameter/%s", name)),
resource.TestCheckResourceAttr("aws_ssm_parameter.foo", "value", "bar"),
resource.TestCheckResourceAttr("aws_ssm_parameter.foo", "type", "String"),
resource.TestCheckResourceAttr("aws_ssm_parameter.foo", "tier", "Standard"),
Expand Down Expand Up @@ -230,8 +228,7 @@ func TestAccAWSSSMParameter_fullPath(t *testing.T) {
Config: testAccAWSSSMParameterBasicConfig(name, "String", "bar"),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSSSMParameterExists("aws_ssm_parameter.foo", &param),
resource.TestMatchResourceAttr("aws_ssm_parameter.foo", "arn",
regexp.MustCompile(fmt.Sprintf("^arn:aws:ssm:[a-z0-9-]+:[0-9]{12}:parameter%s$", name))),
testAccCheckResourceAttrRegionalARN("aws_ssm_parameter.foo", "arn", "ssm", fmt.Sprintf("parameter%s", name)),
resource.TestCheckResourceAttr("aws_ssm_parameter.foo", "value", "bar"),
resource.TestCheckResourceAttr("aws_ssm_parameter.foo", "type", "String"),
),
Expand Down

0 comments on commit b203096

Please sign in to comment.