From ca898d8d1923ea2af6dbee897457ca4bd538d40e Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Fri, 19 May 2017 14:35:54 -0400 Subject: [PATCH] Add ability to 'terraform import' aws_kms_alias resources. --- .../aws/import_aws_kms_alias_test.go | 32 +++++++++++++++++++ .../providers/aws/resource_aws_kms_alias.go | 9 ++++++ .../providers/aws/r/kms_alias.html.markdown | 8 +++++ 3 files changed, 49 insertions(+) create mode 100644 builtin/providers/aws/import_aws_kms_alias_test.go diff --git a/builtin/providers/aws/import_aws_kms_alias_test.go b/builtin/providers/aws/import_aws_kms_alias_test.go new file mode 100644 index 000000000..81aa7b8e2 --- /dev/null +++ b/builtin/providers/aws/import_aws_kms_alias_test.go @@ -0,0 +1,32 @@ +package aws + +import ( + "testing" + "time" + + "github.com/hashicorp/terraform/helper/acctest" + "github.com/hashicorp/terraform/helper/resource" +) + +func TestAccAWSKmsAlias_importBasic(t *testing.T) { + resourceName := "aws_kms_alias.single" + rInt := acctest.RandInt() + kmsAliasTimestamp := time.Now().Format(time.RFC1123) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSKmsAliasDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccAWSKmsSingleAlias(rInt, kmsAliasTimestamp), + }, + + resource.TestStep{ + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} diff --git a/builtin/providers/aws/resource_aws_kms_alias.go b/builtin/providers/aws/resource_aws_kms_alias.go index b02ffefba..7e3f0f2f6 100644 --- a/builtin/providers/aws/resource_aws_kms_alias.go +++ b/builtin/providers/aws/resource_aws_kms_alias.go @@ -19,6 +19,10 @@ func resourceAwsKmsAlias() *schema.Resource { Update: resourceAwsKmsAliasUpdate, Delete: resourceAwsKmsAliasDelete, + Importer: &schema.ResourceImporter{ + State: resourceAwsKmsAliasImport, + }, + Schema: map[string]*schema.Schema{ "arn": &schema.Schema{ Type: schema.TypeString, @@ -173,3 +177,8 @@ func findKmsAliasByName(conn *kms.KMS, name string, marker *string) (*kms.AliasL return nil, nil } + +func resourceAwsKmsAliasImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { + d.Set("name", d.Id()) + return []*schema.ResourceData{d}, nil +} diff --git a/website/source/docs/providers/aws/r/kms_alias.html.markdown b/website/source/docs/providers/aws/r/kms_alias.html.markdown index b92bde5bd..8ead81e08 100644 --- a/website/source/docs/providers/aws/r/kms_alias.html.markdown +++ b/website/source/docs/providers/aws/r/kms_alias.html.markdown @@ -38,3 +38,11 @@ The name must start with the word "alias" followed by a forward slash (alias/). The following attributes are exported: * `arn` - The Amazon Resource Name (ARN) of the key alias. + +## Import + +KMS aliases can be imported using the `name`, e.g. + +``` +$ terraform import aws_kms_alias.a alias/my-key-alias +```