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

resource/aws_ssm_parameter added data_type as option for possible validation #13326

Merged
merged 8 commits into from
Jul 31, 2020
Merged
Show file tree
Hide file tree
Changes from 5 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
9 changes: 9 additions & 0 deletions aws/resource_aws_ssm_parameter.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ func resourceAwsSsmParameter() *schema.Resource {
Optional: true,
Computed: true,
},
"data_type": {
jayolmos marked this conversation as resolved.
Show resolved Hide resolved
Type: schema.TypeString,
Optional: true,
},
"overwrite": {
Type: schema.TypeBool,
Optional: true,
Expand Down Expand Up @@ -147,6 +151,10 @@ func resourceAwsSsmParameterRead(d *schema.ResourceData, meta interface{}) error
}
d.Set("allowed_pattern", detail.AllowedPattern)

if detail.DataType != nil {
d.Set("data_type", detail.DataType)
}
jayolmos marked this conversation as resolved.
Show resolved Hide resolved

tags, err := keyvaluetags.SsmListTags(ssmconn, name, ssm.ResourceTypeForTaggingParameter)

if err != nil {
Expand Down Expand Up @@ -196,6 +204,7 @@ func resourceAwsSsmParameterPut(d *schema.ResourceData, meta interface{}) error
Value: aws.String(d.Get("value").(string)),
Overwrite: aws.Bool(shouldUpdateSsmParameter(d)),
AllowedPattern: aws.String(d.Get("allowed_pattern").(string)),
DataType: aws.String(d.Get("data_type").(string)),
jayolmos marked this conversation as resolved.
Show resolved Hide resolved
}

if d.HasChange("description") {
Expand Down
40 changes: 40 additions & 0 deletions aws/resource_aws_ssm_parameter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func TestAccAWSSSMParameter_basic(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "tier", "Standard"),
resource.TestCheckResourceAttr(resourceName, "tags.%", "0"),
resource.TestCheckResourceAttrSet(resourceName, "version"),
resource.TestCheckResourceAttr(resourceName, "data_type", "string"),
jayolmos marked this conversation as resolved.
Show resolved Hide resolved
),
},
{
Expand Down Expand Up @@ -334,6 +335,34 @@ func TestAccAWSSSMParameter_secure(t *testing.T) {
})
}

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

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSSSMParameterDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSSSMParameterConfigDataType(name, "text", "teststring"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "value", "teststring"),
resource.TestCheckResourceAttr(resourceName, "data_type", "text"),
testAccCheckAWSSSMParameterExists(resourceName, &param),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"overwrite"},
},
},
})
}

func TestAccAWSSSMParameter_secure_with_key(t *testing.T) {
var param ssm.Parameter
randString := acctest.RandString(10)
Expand Down Expand Up @@ -509,6 +538,17 @@ resource "aws_ssm_parameter" "test" {
`, rName, tier)
}

func testAccAWSSSMParameterConfigDataType(rName, data_type, value string) string {
return fmt.Sprintf(`
resource "aws_ssm_parameter" "test" {
name = %[1]q
data_type = %[2]q
type = "String"
value = %[3]q
}
`, rName, data_type, value)
}

func testAccAWSSSMParameterBasicConfigTags1(rName, tagKey1, tagValue1 string) string {
return fmt.Sprintf(`
resource "aws_ssm_parameter" "test" {
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/ssm_parameter.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ The following arguments are supported:
* `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.
* `data_type` - (Optional) The data_type of the parameter. Valid values: text and aws:ec2:image for AMI format, see the [Native parameter support for Amazon Machine Image IDs
](https://docs.aws.amazon.com/systems-manager/latest/userguide/parameter-store-ec2-aliases.html)
* `tags` - (Optional) A map of tags to assign to the object.

## Attributes Reference
Expand Down