Merge pull request #14679 from ewbankkit/import-aws_kms_key_alias

provider/aws: Add ability to 'terraform import' aws_kms_alias resources
This commit is contained in:
Jake Champlin 2017-05-19 15:15:12 -04:00 committed by GitHub
commit 51620cf4fb
3 changed files with 49 additions and 0 deletions

View File

@ -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,
},
},
})
}

View File

@ -19,6 +19,10 @@ func resourceAwsKmsAlias() *schema.Resource {
Update: resourceAwsKmsAliasUpdate, Update: resourceAwsKmsAliasUpdate,
Delete: resourceAwsKmsAliasDelete, Delete: resourceAwsKmsAliasDelete,
Importer: &schema.ResourceImporter{
State: resourceAwsKmsAliasImport,
},
Schema: map[string]*schema.Schema{ Schema: map[string]*schema.Schema{
"arn": &schema.Schema{ "arn": &schema.Schema{
Type: schema.TypeString, Type: schema.TypeString,
@ -173,3 +177,8 @@ func findKmsAliasByName(conn *kms.KMS, name string, marker *string) (*kms.AliasL
return nil, nil return nil, nil
} }
func resourceAwsKmsAliasImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
d.Set("name", d.Id())
return []*schema.ResourceData{d}, nil
}

View File

@ -38,3 +38,11 @@ The name must start with the word "alias" followed by a forward slash (alias/).
The following attributes are exported: The following attributes are exported:
* `arn` - The Amazon Resource Name (ARN) of the key alias. * `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
```