provider/aws: Allow import of glacier_vault (#7596)

This commit is contained in:
Radek Simko 2016-07-12 08:49:26 +01:00 committed by Paul Stack
parent fc4d548761
commit 40e05ecc33
2 changed files with 49 additions and 1 deletions

View File

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

View File

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