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:
commit
51620cf4fb
|
@ -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,
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
```
|
||||
|
|
Loading…
Reference in New Issue