From 244c954eac41a2c220263e474b76c163a22feda1 Mon Sep 17 00:00:00 2001 From: programmer04 Date: Tue, 18 Jun 2019 21:11:07 +0200 Subject: [PATCH 1/3] Add .vscode to .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index b4cd523496f..53849c06c32 100644 --- a/.gitignore +++ b/.gitignore @@ -20,6 +20,7 @@ website/node_modules *~ .*.swp .idea +.vscode *.iml *.test *.iml From eb827a59021595396430402c396e1f720f5ccb19 Mon Sep 17 00:00:00 2001 From: programmer04 Date: Tue, 18 Jun 2019 21:11:26 +0200 Subject: [PATCH 2/3] Add import to resource backup_vault --- aws/resource_aws_backup_vault.go | 5 ++++- website/docs/r/backup_vault.html.markdown | 8 ++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/aws/resource_aws_backup_vault.go b/aws/resource_aws_backup_vault.go index 9850f62ec5f..260222f0151 100644 --- a/aws/resource_aws_backup_vault.go +++ b/aws/resource_aws_backup_vault.go @@ -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": { @@ -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) diff --git a/website/docs/r/backup_vault.html.markdown b/website/docs/r/backup_vault.html.markdown index 8fc146ac4cd..7642a6688e1 100644 --- a/website/docs/r/backup_vault.html.markdown +++ b/website/docs/r/backup_vault.html.markdown @@ -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 +``` From 36a064527379f102be9e141483754b76d3a5faff Mon Sep 17 00:00:00 2001 From: programmer04 Date: Wed, 19 Jun 2019 09:49:32 +0200 Subject: [PATCH 3/3] Add acceptance tests for import of resource backup_vault --- aws/resource_aws_backup_vault_test.go | 52 ++++++++++++++++++--------- 1 file changed, 35 insertions(+), 17 deletions(-) diff --git a/aws/resource_aws_backup_vault_test.go b/aws/resource_aws_backup_vault_test.go index e479688e8a6..5479f3c6129 100644 --- a/aws/resource_aws_backup_vault_test.go +++ b/aws/resource_aws_backup_vault_test.go @@ -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, @@ -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, + }, }, }) } @@ -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, @@ -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, + }, }, }) } @@ -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, @@ -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"), ), }, },