Skip to content

Commit 0778634

Browse files
committed
Wait for revoked status during acceptance test
1 parent 012fdb7 commit 0778634

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

internal/provider/resource_tfe_hyok_configuration_test.go

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func TestAccTFEHYOKConfiguration_basic(t *testing.T) {
1818
t.Skip("Test skipped: HYOK_ORGANIZATION_NAME environment variable is not set")
1919
}
2020

21-
hyok := &tfe.HYOKConfiguration{}
21+
state := &tfe.HYOKConfiguration{}
2222

2323
// With AWS OIDC configuration
2424
resource.Test(t, resource.TestCase{
@@ -28,7 +28,7 @@ func TestAccTFEHYOKConfiguration_basic(t *testing.T) {
2828
{
2929
Config: testAccTFEAWSHYOKConfigurationConfig(orgName, "apple", "arn:aws:kms:us-east-1:123456789012:key/key1", "us-east-1"),
3030
Check: resource.ComposeAggregateTestCheckFunc(
31-
testAccCheckTFEHYOKConfigurationExists("tfe_hyok_configuration.hyok", hyok),
31+
testAccCheckTFEHYOKConfigurationExists("tfe_hyok_configuration.hyok", state),
3232
resource.TestCheckResourceAttrSet("tfe_hyok_configuration.hyok", "id"),
3333
resource.TestCheckResourceAttrSet("tfe_hyok_configuration.hyok", "aws_oidc_configuration_id"),
3434
resource.TestCheckResourceAttr("tfe_hyok_configuration.hyok", "name", "apple"),
@@ -55,7 +55,7 @@ func TestAccTFEHYOKConfiguration_basic(t *testing.T) {
5555
},
5656
// Delete - must first revoke configuration to avoid dangling resources
5757
{
58-
PreConfig: func() { revokeHYOKConfiguration(t, hyok.ID) },
58+
PreConfig: func() { revokeHYOKConfiguration(t, state.ID) },
5959
Config: testAccTFEHYOKConfigurationDestroyConfig(orgName),
6060
},
6161
},
@@ -69,7 +69,7 @@ func TestAccTFEHYOKConfiguration_basic(t *testing.T) {
6969
{
7070
Config: testAccTFEVaultHYOKConfigurationConfig(orgName, "peach", "key1"),
7171
Check: resource.ComposeAggregateTestCheckFunc(
72-
testAccCheckTFEHYOKConfigurationExists("tfe_hyok_configuration.hyok", hyok),
72+
testAccCheckTFEHYOKConfigurationExists("tfe_hyok_configuration.hyok", state),
7373
resource.TestCheckResourceAttrSet("tfe_hyok_configuration.hyok", "id"),
7474
resource.TestCheckResourceAttrSet("tfe_hyok_configuration.hyok", "vault_oidc_configuration_id"),
7575
resource.TestCheckResourceAttr("tfe_hyok_configuration.hyok", "name", "peach"),
@@ -94,7 +94,7 @@ func TestAccTFEHYOKConfiguration_basic(t *testing.T) {
9494
},
9595
// Delete - must first revoke configuration to avoid dangling resources
9696
{
97-
PreConfig: func() { revokeHYOKConfiguration(t, hyok.ID) },
97+
PreConfig: func() { revokeHYOKConfiguration(t, state.ID) },
9898
Config: testAccTFEHYOKConfigurationDestroyConfig(orgName),
9999
},
100100
},
@@ -108,7 +108,7 @@ func TestAccTFEHYOKConfiguration_basic(t *testing.T) {
108108
{
109109
Config: testAccTFEGCPHYOKConfigurationConfig(orgName, "cucumber", "key1", "global", "key-ring-1"),
110110
Check: resource.ComposeAggregateTestCheckFunc(
111-
testAccCheckTFEHYOKConfigurationExists("tfe_hyok_configuration.hyok", hyok),
111+
testAccCheckTFEHYOKConfigurationExists("tfe_hyok_configuration.hyok", state),
112112
resource.TestCheckResourceAttrSet("tfe_hyok_configuration.hyok", "id"),
113113
resource.TestCheckResourceAttrSet("tfe_hyok_configuration.hyok", "gcp_oidc_configuration_id"),
114114
resource.TestCheckResourceAttr("tfe_hyok_configuration.hyok", "name", "cucumber"),
@@ -127,7 +127,7 @@ func TestAccTFEHYOKConfiguration_basic(t *testing.T) {
127127
{
128128
Config: testAccTFEGCPHYOKConfigurationConfig(orgName, "tomato", "key2", "global", "key-ring-2"),
129129
Check: resource.ComposeAggregateTestCheckFunc(
130-
testAccCheckTFEHYOKConfigurationExists("tfe_hyok_configuration.hyok", hyok),
130+
testAccCheckTFEHYOKConfigurationExists("tfe_hyok_configuration.hyok", state),
131131
resource.TestCheckResourceAttrSet("tfe_hyok_configuration.hyok", "id"),
132132
resource.TestCheckResourceAttrSet("tfe_hyok_configuration.hyok", "gcp_oidc_configuration_id"),
133133
resource.TestCheckResourceAttr("tfe_hyok_configuration.hyok", "name", "tomato"),
@@ -138,7 +138,7 @@ func TestAccTFEHYOKConfiguration_basic(t *testing.T) {
138138
},
139139
// Delete - must first revoke configuration to avoid dangling resources
140140
{
141-
PreConfig: func() { revokeHYOKConfiguration(t, hyok.ID) },
141+
PreConfig: func() { revokeHYOKConfiguration(t, state.ID) },
142142
Config: testAccTFEHYOKConfigurationDestroyConfig(orgName),
143143
},
144144
},
@@ -152,7 +152,7 @@ func TestAccTFEHYOKConfiguration_basic(t *testing.T) {
152152
{
153153
Config: testAccTFEAzureHYOKConfigurationConfig(orgName, "banana", "https://random.vault.azure.net/keys/key1"),
154154
Check: resource.ComposeAggregateTestCheckFunc(
155-
testAccCheckTFEHYOKConfigurationExists("tfe_hyok_configuration.hyok", hyok),
155+
testAccCheckTFEHYOKConfigurationExists("tfe_hyok_configuration.hyok", state),
156156
resource.TestCheckResourceAttrSet("tfe_hyok_configuration.hyok", "id"),
157157
resource.TestCheckResourceAttrSet("tfe_hyok_configuration.hyok", "azure_oidc_configuration_id"),
158158
resource.TestCheckResourceAttr("tfe_hyok_configuration.hyok", "name", "banana"),
@@ -177,7 +177,7 @@ func TestAccTFEHYOKConfiguration_basic(t *testing.T) {
177177
},
178178
// Delete - must first revoke configuration to avoid dangling resources
179179
{
180-
PreConfig: func() { revokeHYOKConfiguration(t, hyok.ID) },
180+
PreConfig: func() { revokeHYOKConfiguration(t, state.ID) },
181181
Config: testAccTFEHYOKConfigurationDestroyConfig(orgName),
182182
},
183183
},
@@ -189,6 +189,19 @@ func revokeHYOKConfiguration(t *testing.T, id string) {
189189
if err != nil {
190190
t.Fatalf("failed to revoke HYOK configuration: %v", err)
191191
}
192+
193+
// Wait for configuration to be in the revoked status
194+
_, err = retryFn(10, 1, func() (any, error) {
195+
hyok, err := testAccConfiguredClient.Client.HYOKConfigurations.Read(ctx, id, nil)
196+
if err != nil {
197+
t.Fatalf("failed to read HYOK configuration: %v", err)
198+
}
199+
200+
if hyok.Status != tfe.HYOKConfigurationRevoked {
201+
return nil, fmt.Errorf("expected HYOK configuration to be revoked, got %s", hyok.Status)
202+
}
203+
return nil, nil
204+
})
192205
}
193206

194207
func testAccCheckTFEHYOKConfigurationExists(n string, hyokConfig *tfe.HYOKConfiguration) resource.TestCheckFunc {

0 commit comments

Comments
 (0)