From 22d695327a01111086262551479b1d62af683567 Mon Sep 17 00:00:00 2001 From: jayolmos Date: Thu, 14 May 2020 19:46:06 +0200 Subject: [PATCH 1/5] adding data_type ssm input --- aws/resource_aws_ssm_parameter.go | 9 ++++++ aws/resource_aws_ssm_parameter_test.go | 40 ++++++++++++++++++++++++++ go.mod | 2 +- go.sum | 2 ++ 4 files changed, 52 insertions(+), 1 deletion(-) diff --git a/aws/resource_aws_ssm_parameter.go b/aws/resource_aws_ssm_parameter.go index 71332e8625d..0652aed370f 100644 --- a/aws/resource_aws_ssm_parameter.go +++ b/aws/resource_aws_ssm_parameter.go @@ -67,6 +67,10 @@ func resourceAwsSsmParameter() *schema.Resource { Optional: true, Computed: true, }, + "data_type": { + Type: schema.TypeString, + Optional: true, + }, "overwrite": { Type: schema.TypeBool, Optional: true, @@ -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) + } + tags, err := keyvaluetags.SsmListTags(ssmconn, name, ssm.ResourceTypeForTaggingParameter) if err != nil { @@ -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)), } if d.HasChange("description") { diff --git a/aws/resource_aws_ssm_parameter_test.go b/aws/resource_aws_ssm_parameter_test.go index 0d099a7fffd..9620dc960ca 100644 --- a/aws/resource_aws_ssm_parameter_test.go +++ b/aws/resource_aws_ssm_parameter_test.go @@ -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"), ), }, { @@ -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, ¶m), + ), + }, + { + 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) @@ -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" { diff --git a/go.mod b/go.mod index bb57dafcf6f..8816ec46cba 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/terraform-providers/terraform-provider-aws go 1.13 require ( - github.com/aws/aws-sdk-go v1.30.21 + github.com/aws/aws-sdk-go v1.30.26 github.com/beevik/etree v1.1.0 github.com/bflad/tfproviderdocs v0.6.0 github.com/bflad/tfproviderlint v0.14.0 diff --git a/go.sum b/go.sum index ab0868d9339..a89841da949 100644 --- a/go.sum +++ b/go.sum @@ -41,6 +41,8 @@ github.com/aws/aws-sdk-go v1.15.78/go.mod h1:E3/ieXAlvM0XWO57iftYVDLLvQ824smPP3A github.com/aws/aws-sdk-go v1.25.3/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo= github.com/aws/aws-sdk-go v1.30.21 h1:19EO1Jr80+jLwJyITzH8c79C/6EwY5mMyasqDbBiCuc= github.com/aws/aws-sdk-go v1.30.21/go.mod h1:5zCpMtNQVjRREroY7sYe8lOMRSxkhG6MZveU8YkpAk0= +github.com/aws/aws-sdk-go v1.30.26 h1:wP0N6DBb/3EyHTtWNz4jzgGVi1l290zoFGfu4HFGeM0= +github.com/aws/aws-sdk-go v1.30.26/go.mod h1:5zCpMtNQVjRREroY7sYe8lOMRSxkhG6MZveU8YkpAk0= github.com/beevik/etree v1.1.0 h1:T0xke/WvNtMoCqgzPhkX2r4rjY3GDZFi+FjpRZY2Jbs= github.com/beevik/etree v1.1.0/go.mod h1:r8Aw8JqVegEf0w2fDnATrX9VpkMcyFeM0FhwO62wh+A= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= From ebb3fec28fa9d290945fe3a02c6ad332d8f08c71 Mon Sep 17 00:00:00 2001 From: jayolmos Date: Thu, 14 May 2020 19:50:33 +0200 Subject: [PATCH 2/5] doc for data_type ssm input --- website/docs/r/ssm_parameter.html.markdown | 2 ++ 1 file changed, 2 insertions(+) diff --git a/website/docs/r/ssm_parameter.html.markdown b/website/docs/r/ssm_parameter.html.markdown index 3c6861d1986..2b4560cc6c8 100644 --- a/website/docs/r/ssm_parameter.html.markdown +++ b/website/docs/r/ssm_parameter.html.markdown @@ -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 From 8e94e7b076ff64bc93575066d9c0164cd42d49f4 Mon Sep 17 00:00:00 2001 From: jayolmos Date: Fri, 15 May 2020 11:07:26 +0200 Subject: [PATCH 3/5] avoid aws-sdk-go manually updated --- go.mod | 2 +- go.sum | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 8816ec46cba..bb57dafcf6f 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/terraform-providers/terraform-provider-aws go 1.13 require ( - github.com/aws/aws-sdk-go v1.30.26 + github.com/aws/aws-sdk-go v1.30.21 github.com/beevik/etree v1.1.0 github.com/bflad/tfproviderdocs v0.6.0 github.com/bflad/tfproviderlint v0.14.0 diff --git a/go.sum b/go.sum index a89841da949..ab0868d9339 100644 --- a/go.sum +++ b/go.sum @@ -41,8 +41,6 @@ github.com/aws/aws-sdk-go v1.15.78/go.mod h1:E3/ieXAlvM0XWO57iftYVDLLvQ824smPP3A github.com/aws/aws-sdk-go v1.25.3/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo= github.com/aws/aws-sdk-go v1.30.21 h1:19EO1Jr80+jLwJyITzH8c79C/6EwY5mMyasqDbBiCuc= github.com/aws/aws-sdk-go v1.30.21/go.mod h1:5zCpMtNQVjRREroY7sYe8lOMRSxkhG6MZveU8YkpAk0= -github.com/aws/aws-sdk-go v1.30.26 h1:wP0N6DBb/3EyHTtWNz4jzgGVi1l290zoFGfu4HFGeM0= -github.com/aws/aws-sdk-go v1.30.26/go.mod h1:5zCpMtNQVjRREroY7sYe8lOMRSxkhG6MZveU8YkpAk0= github.com/beevik/etree v1.1.0 h1:T0xke/WvNtMoCqgzPhkX2r4rjY3GDZFi+FjpRZY2Jbs= github.com/beevik/etree v1.1.0/go.mod h1:r8Aw8JqVegEf0w2fDnATrX9VpkMcyFeM0FhwO62wh+A= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= From c51a9627a916cfe873237d0c7372a17b2ffba8c5 Mon Sep 17 00:00:00 2001 From: jayolmos Date: Fri, 24 Jul 2020 20:45:52 +0200 Subject: [PATCH 4/5] added @bflad suggestions --- aws/resource_aws_ssm_parameter.go | 14 +++++++++----- aws/resource_aws_ssm_parameter_test.go | 2 +- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/aws/resource_aws_ssm_parameter.go b/aws/resource_aws_ssm_parameter.go index 9e33c9f3ffd..b9ad5afd97a 100644 --- a/aws/resource_aws_ssm_parameter.go +++ b/aws/resource_aws_ssm_parameter.go @@ -70,6 +70,10 @@ func resourceAwsSsmParameter() *schema.Resource { "data_type": { Type: schema.TypeString, Optional: true, + ValidateFunc: validation.StringInSlice([]string{ + "aws:ec2:image", + "text", + }, false), }, "overwrite": { Type: schema.TypeBool, @@ -150,10 +154,7 @@ func resourceAwsSsmParameterRead(d *schema.ResourceData, meta interface{}) error d.Set("tier", detail.Tier) } d.Set("allowed_pattern", detail.AllowedPattern) - - if detail.DataType != nil { - d.Set("data_type", detail.DataType) - } + d.Set("data_type", detail.DataType) tags, err := keyvaluetags.SsmListTags(ssmconn, name, ssm.ResourceTypeForTaggingParameter) @@ -204,7 +205,10 @@ 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)), + } + + if v, ok := d.GetOk("data_type"); ok { + paramInput.DataType = aws.String(v.(string)) } if d.HasChange("description") { diff --git a/aws/resource_aws_ssm_parameter_test.go b/aws/resource_aws_ssm_parameter_test.go index 9620dc960ca..1854755a882 100644 --- a/aws/resource_aws_ssm_parameter_test.go +++ b/aws/resource_aws_ssm_parameter_test.go @@ -31,7 +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"), + resource.TestCheckResourceAttr(resourceName, "data_type", "text"), ), }, { From 9096980a434ca77df5852f0d627e391d86b6be52 Mon Sep 17 00:00:00 2001 From: jayolmos Date: Fri, 24 Jul 2020 22:20:38 +0200 Subject: [PATCH 5/5] added default: text --- aws/resource_aws_ssm_parameter.go | 1 + 1 file changed, 1 insertion(+) diff --git a/aws/resource_aws_ssm_parameter.go b/aws/resource_aws_ssm_parameter.go index b9ad5afd97a..56d4e3505d9 100644 --- a/aws/resource_aws_ssm_parameter.go +++ b/aws/resource_aws_ssm_parameter.go @@ -70,6 +70,7 @@ func resourceAwsSsmParameter() *schema.Resource { "data_type": { Type: schema.TypeString, Optional: true, + Default: "text", ValidateFunc: validation.StringInSlice([]string{ "aws:ec2:image", "text",