Skip to content

Commit ca898d8

Browse files
committed
Add ability to 'terraform import' aws_kms_alias resources.
1 parent 6266eef commit ca898d8

3 files changed

Lines changed: 49 additions & 0 deletions

File tree

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package aws
2+
3+
import (
4+
"testing"
5+
"time"
6+
7+
"github.com/hashicorp/terraform/helper/acctest"
8+
"github.com/hashicorp/terraform/helper/resource"
9+
)
10+
11+
func TestAccAWSKmsAlias_importBasic(t *testing.T) {
12+
resourceName := "aws_kms_alias.single"
13+
rInt := acctest.RandInt()
14+
kmsAliasTimestamp := time.Now().Format(time.RFC1123)
15+
16+
resource.Test(t, resource.TestCase{
17+
PreCheck: func() { testAccPreCheck(t) },
18+
Providers: testAccProviders,
19+
CheckDestroy: testAccCheckAWSKmsAliasDestroy,
20+
Steps: []resource.TestStep{
21+
resource.TestStep{
22+
Config: testAccAWSKmsSingleAlias(rInt, kmsAliasTimestamp),
23+
},
24+
25+
resource.TestStep{
26+
ResourceName: resourceName,
27+
ImportState: true,
28+
ImportStateVerify: true,
29+
},
30+
},
31+
})
32+
}

‎builtin/providers/aws/resource_aws_kms_alias.go‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ func resourceAwsKmsAlias() *schema.Resource {
1919
Update: resourceAwsKmsAliasUpdate,
2020
Delete: resourceAwsKmsAliasDelete,
2121

22+
Importer: &schema.ResourceImporter{
23+
State: resourceAwsKmsAliasImport,
24+
},
25+
2226
Schema: map[string]*schema.Schema{
2327
"arn": &schema.Schema{
2428
Type: schema.TypeString,
@@ -173,3 +177,8 @@ func findKmsAliasByName(conn *kms.KMS, name string, marker *string) (*kms.AliasL
173177

174178
return nil, nil
175179
}
180+
181+
func resourceAwsKmsAliasImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
182+
d.Set("name", d.Id())
183+
return []*schema.ResourceData{d}, nil
184+
}

‎website/source/docs/providers/aws/r/kms_alias.html.markdown‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,11 @@ The name must start with the word "alias" followed by a forward slash (alias/).
3838
The following attributes are exported:
3939

4040
* `arn` - The Amazon Resource Name (ARN) of the key alias.
41+
42+
## Import
43+
44+
KMS aliases can be imported using the `name`, e.g.
45+
46+
```
47+
$ terraform import aws_kms_alias.a alias/my-key-alias
48+
```

0 commit comments

Comments
 (0)