diff --git a/aws/import_aws_ssm_parameter_test.go b/aws/import_aws_ssm_parameter_test.go new file mode 100644 index 00000000000..fc1a2c79f7a --- /dev/null +++ b/aws/import_aws_ssm_parameter_test.go @@ -0,0 +1,32 @@ +package aws + +import ( + "testing" + + "github.com/hashicorp/terraform/helper/acctest" + "github.com/hashicorp/terraform/helper/resource" +) + +func TestAccAWSSSMParameter_importBasic(t *testing.T) { + resourceName := "aws_ssm_parameter.foo" + randName := acctest.RandString(5) + randValue := acctest.RandString(5) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSSSMParameterDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSSSMParameterBasicConfig(randName, randValue), + }, + + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"overwrite"}, + }, + }, + }) +} diff --git a/aws/resource_aws_ssm_parameter.go b/aws/resource_aws_ssm_parameter.go index 9348df48a0d..8ecf82b3e6c 100644 --- a/aws/resource_aws_ssm_parameter.go +++ b/aws/resource_aws_ssm_parameter.go @@ -17,6 +17,9 @@ func resourceAwsSsmParameter() *schema.Resource { Update: resourceAwsSsmParameterPut, Delete: resourceAwsSsmParameterDelete, Exists: resourceAwsSmmParameterExists, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, Schema: map[string]*schema.Schema{ "name": { @@ -61,7 +64,7 @@ func resourceAwsSmmParameterExists(d *schema.ResourceData, meta interface{}) (bo conn := meta.(*AWSClient).ssmconn resp, err := conn.GetParameters(&ssm.GetParametersInput{ - Names: []*string{aws.String(d.Get("name").(string))}, + Names: []*string{aws.String(d.Id())}, WithDecryption: aws.Bool(true), }) @@ -72,14 +75,19 @@ func resourceAwsSmmParameterExists(d *schema.ResourceData, meta interface{}) (bo } func resourceAwsSsmParameterRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*AWSClient).ssmconn + ssmconn := meta.(*AWSClient).ssmconn log.Printf("[DEBUG] Reading SSM Parameter: %s", d.Id()) - resp, err := conn.GetParameters(&ssm.GetParametersInput{ - Names: []*string{aws.String(d.Get("name").(string))}, + paramInput := &ssm.GetParametersInput{ + Names: []*string{ + aws.String(d.Id()), + }, WithDecryption: aws.Bool(true), - }) + } + + resp, err := ssmconn.GetParameters(paramInput) + if err != nil { return errwrap.Wrapf("[ERROR] Error getting SSM parameter: {{err}}", err) } @@ -89,11 +97,11 @@ func resourceAwsSsmParameterRead(d *schema.ResourceData, meta interface{}) error d.Set("type", param.Type) d.Set("value", param.Value) - respDetailed, err := conn.DescribeParameters(&ssm.DescribeParametersInput{ + respDetailed, err := ssmconn.DescribeParameters(&ssm.DescribeParametersInput{ Filters: []*ssm.ParametersFilter{ &ssm.ParametersFilter{ Key: aws.String("Name"), - Values: []*string{aws.String(d.Get("name").(string))}, + Values: []*string{aws.String(d.Id())}, }, }, }) @@ -116,8 +124,8 @@ func resourceAwsSsmParameterRead(d *schema.ResourceData, meta interface{}) error d.Set("description", detail.Description) d.Set("allowed_pattern", detail.AllowedPattern) - if tagList, err := conn.ListTagsForResource(&ssm.ListTagsForResourceInput{ - ResourceId: aws.String(d.Get("name").(string)), + if tagList, err := ssmconn.ListTagsForResource(&ssm.ListTagsForResourceInput{ + ResourceId: aws.String(d.Id()), ResourceType: aws.String("Parameter"), }); err != nil { return fmt.Errorf("Failed to get SSM parameter tags for %s: %s", d.Get("name"), err)