Add ability to 'terraform import' aws_kms_alias resources.

This commit is contained in:
Kit Ewbank 2017-05-19 14:35:54 -04:00
parent 6266eef652
commit ca898d8d19
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,
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
}

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:
* `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
```