Skip to content

Commit

Permalink
Merge pull request #9041 from programmer04/backup-vault-import
Browse files Browse the repository at this point in the history
Add support for terraform import to resource backup_vault
  • Loading branch information
bflad authored Jun 19, 2019
2 parents b3bd96a + 36a0645 commit 0a69682
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 18 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ website/node_modules
*~
.*.swp
.idea
.vscode
*.iml
*.test
*.iml
Expand Down
5 changes: 4 additions & 1 deletion aws/resource_aws_backup_vault.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ func resourceAwsBackupVault() *schema.Resource {
Read: resourceAwsBackupVaultRead,
Update: resourceAwsBackupVaultUpdate,
Delete: resourceAwsBackupVaultDelete,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},

Schema: map[string]*schema.Schema{
"name": {
Expand Down Expand Up @@ -91,7 +94,7 @@ func resourceAwsBackupVaultRead(d *schema.ResourceData, meta interface{}) error
if err != nil {
return fmt.Errorf("error reading Backup Vault (%s): %s", d.Id(), err)
}

d.Set("name", resp.BackupVaultName)
d.Set("kms_key_arn", resp.EncryptionKeyArn)
d.Set("arn", resp.BackupVaultArn)
d.Set("recovery_points", resp.NumberOfRecoveryPoints)
Expand Down
52 changes: 35 additions & 17 deletions aws/resource_aws_backup_vault_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ func TestAccAwsBackupVault_basic(t *testing.T) {
var vault backup.DescribeBackupVaultOutput

rInt := acctest.RandInt()
resourceName := "aws_backup_vault.test"
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSBackup(t) },
Providers: testAccProviders,
Expand All @@ -23,9 +24,14 @@ func TestAccAwsBackupVault_basic(t *testing.T) {
{
Config: testAccBackupVaultConfig(rInt),
Check: resource.ComposeTestCheckFunc(
testAccCheckAwsBackupVaultExists("aws_backup_vault.test", &vault),
testAccCheckAwsBackupVaultExists(resourceName, &vault),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}
Expand All @@ -34,6 +40,7 @@ func TestAccAwsBackupVault_withKmsKey(t *testing.T) {
var vault backup.DescribeBackupVaultOutput

rInt := acctest.RandInt()
resourceName := "aws_backup_vault.test"
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSBackup(t) },
Providers: testAccProviders,
Expand All @@ -42,10 +49,15 @@ func TestAccAwsBackupVault_withKmsKey(t *testing.T) {
{
Config: testAccBackupVaultWithKmsKey(rInt),
Check: resource.ComposeTestCheckFunc(
testAccCheckAwsBackupVaultExists("aws_backup_vault.test", &vault),
resource.TestCheckResourceAttrPair("aws_backup_vault.test", "kms_key_arn", "aws_kms_key.test", "arn"),
testAccCheckAwsBackupVaultExists(resourceName, &vault),
resource.TestCheckResourceAttrPair(resourceName, "kms_key_arn", "aws_kms_key.test", "arn"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}
Expand All @@ -54,6 +66,7 @@ func TestAccAwsBackupVault_withTags(t *testing.T) {
var vault backup.DescribeBackupVaultOutput

rInt := acctest.RandInt()
resourceName := "aws_backup_vault.test"
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSBackup(t) },
Providers: testAccProviders,
Expand All @@ -62,30 +75,35 @@ func TestAccAwsBackupVault_withTags(t *testing.T) {
{
Config: testAccBackupVaultWithTags(rInt),
Check: resource.ComposeTestCheckFunc(
testAccCheckAwsBackupVaultExists("aws_backup_vault.test", &vault),
resource.TestCheckResourceAttr("aws_backup_vault.test", "tags.%", "2"),
resource.TestCheckResourceAttr("aws_backup_vault.test", "tags.up", "down"),
resource.TestCheckResourceAttr("aws_backup_vault.test", "tags.left", "right"),
testAccCheckAwsBackupVaultExists(resourceName, &vault),
resource.TestCheckResourceAttr(resourceName, "tags.%", "2"),
resource.TestCheckResourceAttr(resourceName, "tags.up", "down"),
resource.TestCheckResourceAttr(resourceName, "tags.left", "right"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccBackupVaultWithUpdateTags(rInt),
Check: resource.ComposeTestCheckFunc(
testAccCheckAwsBackupVaultExists("aws_backup_vault.test", &vault),
resource.TestCheckResourceAttr("aws_backup_vault.test", "tags.%", "4"),
resource.TestCheckResourceAttr("aws_backup_vault.test", "tags.up", "downdown"),
resource.TestCheckResourceAttr("aws_backup_vault.test", "tags.left", "rightright"),
resource.TestCheckResourceAttr("aws_backup_vault.test", "tags.foo", "bar"),
resource.TestCheckResourceAttr("aws_backup_vault.test", "tags.fizz", "buzz"),
testAccCheckAwsBackupVaultExists(resourceName, &vault),
resource.TestCheckResourceAttr(resourceName, "tags.%", "4"),
resource.TestCheckResourceAttr(resourceName, "tags.up", "downdown"),
resource.TestCheckResourceAttr(resourceName, "tags.left", "rightright"),
resource.TestCheckResourceAttr(resourceName, "tags.foo", "bar"),
resource.TestCheckResourceAttr(resourceName, "tags.fizz", "buzz"),
),
},
{
Config: testAccBackupVaultWithRemoveTags(rInt),
Check: resource.ComposeTestCheckFunc(
testAccCheckAwsBackupVaultExists("aws_backup_vault.test", &vault),
resource.TestCheckResourceAttr("aws_backup_vault.test", "tags.%", "2"),
resource.TestCheckResourceAttr("aws_backup_vault.test", "tags.foo", "bar"),
resource.TestCheckResourceAttr("aws_backup_vault.test", "tags.fizz", "buzz"),
testAccCheckAwsBackupVaultExists(resourceName, &vault),
resource.TestCheckResourceAttr(resourceName, "tags.%", "2"),
resource.TestCheckResourceAttr(resourceName, "tags.foo", "bar"),
resource.TestCheckResourceAttr(resourceName, "tags.fizz", "buzz"),
),
},
},
Expand Down
8 changes: 8 additions & 0 deletions website/docs/r/backup_vault.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,11 @@ In addition to all arguments above, the following attributes are exported:
* `id` - The name of the vault.
* `arn` - The ARN of the vault.
* `recovery_points` - The number of recovery points that are stored in a backup vault.

## Import

Backup vault can be imported using the `name`, e.g.

```
$ terraform import aws_backup_vault.test-vault TestVault
```

0 comments on commit 0a69682

Please sign in to comment.