@@ -11,9 +11,6 @@ import (
11
11
)
12
12
13
13
func init () {
14
- if ! terraformBetaEnabled {
15
- return
16
- }
17
14
resource .AddTestSweepers ("scaleway_iam_api_key" , & resource.Sweeper {
18
15
Name : "scaleway_iam_api_key" ,
19
16
F : testSweepIamAPIKey ,
@@ -26,13 +23,16 @@ func testSweepIamAPIKey(_ string) error {
26
23
27
24
l .Debugf ("sweeper: destroying the api keys" )
28
25
29
- listAPIKeys , err := api .ListAPIKeys (& iam.ListAPIKeysRequest {})
26
+ listAPIKeys , err := api .ListAPIKeys (& iam.ListAPIKeysRequest {}, scw . WithAllPages () )
30
27
if err != nil {
31
28
return fmt .Errorf ("failed to list api keys: %w" , err )
32
29
}
33
- for _ , app := range listAPIKeys .APIKeys {
30
+ for _ , key := range listAPIKeys .APIKeys {
31
+ if ! isTestResource (key .Description ) {
32
+ continue
33
+ }
34
34
err = api .DeleteAPIKey (& iam.DeleteAPIKeyRequest {
35
- AccessKey : app .AccessKey ,
35
+ AccessKey : key .AccessKey ,
36
36
})
37
37
if err != nil {
38
38
return fmt .Errorf ("failed to delete api key: %w" , err )
@@ -60,13 +60,13 @@ func TestAccScalewayIamApiKey_WithApplication(t *testing.T) {
60
60
61
61
resource "scaleway_iam_api_key" "main" {
62
62
application_id = scaleway_iam_application.main.id
63
- description = "a description "
63
+ description = "tf_tests_with_application "
64
64
}
65
65
` ,
66
66
Check : resource .ComposeTestCheckFunc (
67
67
testAccCheckScalewayIamAPIKeyExists (tt , "scaleway_iam_api_key.main" ),
68
68
resource .TestCheckResourceAttrPair ("scaleway_iam_api_key.main" , "application_id" , "scaleway_iam_application.main" , "id" ),
69
- resource .TestCheckResourceAttr ("scaleway_iam_api_key.main" , "description" , "a description " ),
69
+ resource .TestCheckResourceAttr ("scaleway_iam_api_key.main" , "description" , "tf_tests_with_application " ),
70
70
resource .TestCheckResourceAttrSet ("scaleway_iam_api_key.main" , "secret_key" ),
71
71
),
72
72
},
@@ -78,13 +78,13 @@ func TestAccScalewayIamApiKey_WithApplication(t *testing.T) {
78
78
79
79
resource "scaleway_iam_api_key" "main" {
80
80
application_id = scaleway_iam_application.main.id
81
- description = "another description "
81
+ description = "tf_tests_with_application_changed "
82
82
}
83
83
` ,
84
84
Check : resource .ComposeTestCheckFunc (
85
85
testAccCheckScalewayIamAPIKeyExists (tt , "scaleway_iam_api_key.main" ),
86
86
resource .TestCheckResourceAttrPair ("scaleway_iam_api_key.main" , "application_id" , "scaleway_iam_application.main" , "id" ),
87
- resource .TestCheckResourceAttr ("scaleway_iam_api_key.main" , "description" , "another description " ),
87
+ resource .TestCheckResourceAttr ("scaleway_iam_api_key.main" , "description" , "tf_tests_with_application_changed " ),
88
88
resource .TestCheckResourceAttrSet ("scaleway_iam_api_key.main" , "secret_key" ),
89
89
),
90
90
},
@@ -116,14 +116,14 @@ func TestAccScalewayIamApiKey_Expires(t *testing.T) {
116
116
117
117
resource "scaleway_iam_api_key" "main" {
118
118
application_id = scaleway_iam_application.main.id
119
- description = "an api key with an expiration date "
119
+ description = "tf_tests_expires "
120
120
expires_at = "2025-07-06T09:00:00Z"
121
121
}
122
122
` ,
123
123
Check : resource .ComposeTestCheckFunc (
124
124
testAccCheckScalewayIamAPIKeyExists (tt , "scaleway_iam_api_key.main" ),
125
125
resource .TestCheckResourceAttrPair ("scaleway_iam_api_key.main" , "application_id" , "scaleway_iam_application.main" , "id" ),
126
- resource .TestCheckResourceAttr ("scaleway_iam_api_key.main" , "description" , "an api key with an expiration date " ),
126
+ resource .TestCheckResourceAttr ("scaleway_iam_api_key.main" , "description" , "tf_tests_expires " ),
127
127
resource .TestCheckResourceAttr ("scaleway_iam_api_key.main" , "expires_at" , "2025-07-06T09:00:00Z" ),
128
128
),
129
129
},
@@ -147,13 +147,13 @@ func TestAccScalewayIamApiKey_NoUpdate(t *testing.T) {
147
147
148
148
resource "scaleway_iam_api_key" "main" {
149
149
application_id = scaleway_iam_application.main.id
150
- description = "no update "
150
+ description = "tf_tests_no_update "
151
151
}
152
152
` ,
153
153
Check : resource .ComposeTestCheckFunc (
154
154
testAccCheckScalewayIamAPIKeyExists (tt , "scaleway_iam_api_key.main" ),
155
155
resource .TestCheckResourceAttrPair ("scaleway_iam_api_key.main" , "application_id" , "scaleway_iam_application.main" , "id" ),
156
- resource .TestCheckResourceAttr ("scaleway_iam_api_key.main" , "description" , "no update " ),
156
+ resource .TestCheckResourceAttr ("scaleway_iam_api_key.main" , "description" , "tf_tests_no_update " ),
157
157
),
158
158
},
159
159
{
@@ -164,13 +164,13 @@ func TestAccScalewayIamApiKey_NoUpdate(t *testing.T) {
164
164
165
165
resource "scaleway_iam_api_key" "main" {
166
166
application_id = scaleway_iam_application.main.id
167
- description = "no update "
167
+ description = "tf_tests_no_update "
168
168
}
169
169
` ,
170
170
Check : resource .ComposeTestCheckFunc (
171
171
testAccCheckScalewayIamAPIKeyExists (tt , "scaleway_iam_api_key.main" ),
172
172
resource .TestCheckResourceAttrPair ("scaleway_iam_api_key.main" , "application_id" , "scaleway_iam_application.main" , "id" ),
173
- resource .TestCheckResourceAttr ("scaleway_iam_api_key.main" , "description" , "no update " ),
173
+ resource .TestCheckResourceAttr ("scaleway_iam_api_key.main" , "description" , "tf_tests_no_update " ),
174
174
),
175
175
},
176
176
},
0 commit comments