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

Add support for advanced SSM parameters #8525

Merged
merged 3 commits into from
May 9, 2019
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
11 changes: 11 additions & 0 deletions aws/resource_aws_ssm_parameter.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ func resourceAwsSsmParameter() *schema.Resource {
Type: schema.TypeString,
Optional: true,
},
"tier": {
Type: schema.TypeString,
Optional: true,
Default: ssm.ParameterTierStandard,
ValidateFunc: validation.StringInSlice([]string{
ssm.ParameterTierStandard,
ssm.ParameterTierAdvanced,
}, false),
},
"type": {
Type: schema.TypeString,
Required: true,
Expand Down Expand Up @@ -127,6 +136,7 @@ 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("allowed_pattern", detail.AllowedPattern)

if tagList, err := ssmconn.ListTagsForResource(&ssm.ListTagsForResourceInput{
Expand Down Expand Up @@ -173,6 +183,7 @@ func resourceAwsSsmParameterPut(d *schema.ResourceData, meta interface{}) error
paramInput := &ssm.PutParameterInput{
Name: aws.String(d.Get("name").(string)),
Type: aws.String(d.Get("type").(string)),
Tier: aws.String(d.Get("tier").(string)),
Value: aws.String(d.Get("value").(string)),
Overwrite: aws.Bool(shouldUpdateSsmParameter(d)),
AllowedPattern: aws.String(d.Get("allowed_pattern").(string)),
Expand Down
41 changes: 41 additions & 0 deletions aws/resource_aws_ssm_parameter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,33 @@ func TestAccAWSSSMParameter_basic(t *testing.T) {
regexp.MustCompile(fmt.Sprintf("^arn:aws:ssm:[a-z0-9-]+:[0-9]{12}: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"),
resource.TestCheckResourceAttr("aws_ssm_parameter.foo", "tags.%", "1"),
resource.TestCheckResourceAttr("aws_ssm_parameter.foo", "tags.Name", "My Parameter"),
),
},
},
})
}

func TestAccAWSSSMParameter_Tier(t *testing.T) {
var param ssm.Parameter
name := fmt.Sprintf("%s_%s", t.Name(), acctest.RandString(10))

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSSSMParameterDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSSSMAdvancedParameterConfig(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))),
resource.TestCheckResourceAttr("aws_ssm_parameter.foo", "value", "bar"),
resource.TestCheckResourceAttr("aws_ssm_parameter.foo", "type", "String"),
resource.TestCheckResourceAttr("aws_ssm_parameter.foo", "tier", "Advanced"),
resource.TestCheckResourceAttr("aws_ssm_parameter.foo", "tags.%", "1"),
resource.TestCheckResourceAttr("aws_ssm_parameter.foo", "tags.Name", "My Parameter"),
),
Expand Down Expand Up @@ -379,6 +406,20 @@ resource "aws_ssm_parameter" "foo" {
`, rName, pType, value)
}

func testAccAWSSSMAdvancedParameterConfig(rName, pType, value string) string {
return fmt.Sprintf(`
resource "aws_ssm_parameter" "foo" {
name = "%s"
type = "%s"
value = "%s"
tier = "Advanced"
tags = {
Name = "My Parameter"
}
}
`, rName, pType, value)
}

func testAccAWSSSMParameterBasicConfigTagsUpdated(rName, pType, value string) string {
return fmt.Sprintf(`
resource "aws_ssm_parameter" "foo" {
Expand Down
1 change: 1 addition & 0 deletions website/docs/r/ssm_parameter.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ The following arguments are supported:
* `type` - (Required) The type of the parameter. Valid types are `String`, `StringList` and `SecureString`.
* `value` - (Required) The value of the parameter.
* `description` - (Optional) The description of the parameter.
* `tier` - (Optional) The tier of the parameter. If not specified, will default to `Standard`. Valid tiers are `Standard` and `Advanced`. For more information on parameter tiers, see the [AWS SSM Parameter tier comparison and guide](https://docs.aws.amazon.com/systems-manager/latest/userguide/parameter-store-advanced-parameters.html).
* `key_id` - (Optional) The KMS key id or arn for encrypting a SecureString.
* `overwrite` - (Optional) Overwrite an existing parameter. If not specified, will default to `false` if the resource has not been created by terraform to avoid overwrite of existing resource and will default to `true` otherwise (terraform lifecycle rules should then be used to manage the update behavior).
* `allowed_pattern` - (Optional) A regular expression used to validate the parameter value.
Expand Down