diff --git a/builtin/providers/aws/import_aws_glacier_vault_test.go b/builtin/providers/aws/import_aws_glacier_vault_test.go new file mode 100644 index 0000000000..e5fd5aa5ba --- /dev/null +++ b/builtin/providers/aws/import_aws_glacier_vault_test.go @@ -0,0 +1,28 @@ +package aws + +import ( + "testing" + + "github.com/hashicorp/terraform/helper/resource" +) + +func TestAccAWSGlacierVault_importBasic(t *testing.T) { + resourceName := "aws_glacier_vault.full" + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckGlacierVaultDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccGlacierVault_full, + }, + + resource.TestStep{ + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} diff --git a/builtin/providers/aws/resource_aws_glacier_vault.go b/builtin/providers/aws/resource_aws_glacier_vault.go index 21ac4d7cc1..99332f6e00 100644 --- a/builtin/providers/aws/resource_aws_glacier_vault.go +++ b/builtin/providers/aws/resource_aws_glacier_vault.go @@ -1,6 +1,7 @@ package aws import ( + "errors" "fmt" "log" "regexp" @@ -19,6 +20,10 @@ func resourceAwsGlacierVault() *schema.Resource { Update: resourceAwsGlacierVaultUpdate, Delete: resourceAwsGlacierVaultDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + Schema: map[string]*schema.Schema{ "name": &schema.Schema{ Type: schema.TypeString, @@ -130,7 +135,15 @@ func resourceAwsGlacierVaultRead(d *schema.ResourceData, meta interface{}) error return fmt.Errorf("Error reading Glacier Vault: %s", err.Error()) } - d.Set("arn", *out.VaultARN) + awsClient := meta.(*AWSClient) + d.Set("name", out.VaultName) + d.Set("arn", out.VaultARN) + + location, err := buildGlacierVaultLocation(awsClient.accountid, d.Id()) + if err != nil { + return err + } + d.Set("location", location) tags, err := getGlacierVaultTags(glacierconn, d.Id()) if err != nil { @@ -366,6 +379,13 @@ func glacierPointersToStringList(pointers []*string) []interface{} { return list } +func buildGlacierVaultLocation(accountId, vaultName string) (string, error) { + if accountId == "" { + return "", errors.New("AWS account ID unavailable - failed to construct Vault location") + } + return fmt.Sprintf("/" + accountId + "/vaults/" + vaultName), nil +} + func getGlacierVaultNotification(glacierconn *glacier.Glacier, vaultName string) ([]map[string]interface{}, error) { request := &glacier.GetVaultNotificationsInput{ VaultName: aws.String(vaultName),