Skip to content

Commit

Permalink
separate import test for external_id case
Browse files Browse the repository at this point in the history
  • Loading branch information
helenfufu committed Nov 20, 2024
1 parent 2c48a30 commit 670162b
Showing 1 changed file with 27 additions and 10 deletions.
37 changes: 27 additions & 10 deletions vault/resource_aws_auth_backend_sts_role_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,35 @@ func TestAccAWSAuthBackendSTSRole_import(t *testing.T) {
backend := acctest.RandomWithPrefix("aws")
accountID := strconv.Itoa(acctest.RandInt())
arn := acctest.RandomWithPrefix("arn:aws:iam::" + accountID + ":role/test-role")
externalID := "external-id"

importStateVerifyIgnore := make([]string, 0)
// Ignore external_id if Vault version is < 1.17.0.
if !provider.IsAPISupported(testProvider.Meta(), provider.VaultVersion117) {
importStateVerifyIgnore = append(importStateVerifyIgnore, consts.FieldExternalID)
}
resource.Test(t, resource.TestCase{
PreCheck: func() { testutil.TestAccPreCheck(t) },
ProviderFactories: providerFactories,
CheckDestroy: testAccCheckAWSAuthBackendSTSRoleDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSAuthBackendSTSRoleConfig_basic(backend, accountID, arn, ""),
Check: testAccAWSAuthBackendSTSRoleCheck_attrs(backend, accountID, arn),
},
{
ResourceName: "vault_aws_auth_backend_sts_role.role",
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccAWSAuthBackendSTSRole_importWithExternalID(t *testing.T) {
backend := acctest.RandomWithPrefix("aws")
accountID := strconv.Itoa(acctest.RandInt())
arn := acctest.RandomWithPrefix("arn:aws:iam::" + accountID + ":role/test-role")
externalID := "external-id"

resource.Test(t, resource.TestCase{
PreCheck: func() {
testutil.TestAccPreCheck(t)
SkipIfAPIVersionLT(t, testProvider.Meta(), provider.VaultVersion117)
},
ProviderFactories: providerFactories,
CheckDestroy: testAccCheckAWSAuthBackendSTSRoleDestroy,
Expand All @@ -42,10 +60,9 @@ func TestAccAWSAuthBackendSTSRole_import(t *testing.T) {
Check: testAccAWSAuthBackendSTSRoleCheck_attrs(backend, accountID, arn),
},
{
ResourceName: "vault_aws_auth_backend_sts_role.role",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: importStateVerifyIgnore,
ResourceName: "vault_aws_auth_backend_sts_role.role",
ImportState: true,
ImportStateVerify: true,
},
},
})
Expand Down

0 comments on commit 670162b

Please sign in to comment.