@@ -11,9 +11,6 @@ import (
1111)
1212
1313func init () {
14- if ! terraformBetaEnabled {
15- return
16- }
1714 resource .AddTestSweepers ("scaleway_iam_api_key" , & resource.Sweeper {
1815 Name : "scaleway_iam_api_key" ,
1916 F : testSweepIamAPIKey ,
@@ -26,13 +23,16 @@ func testSweepIamAPIKey(_ string) error {
2623
2724 l .Debugf ("sweeper: destroying the api keys" )
2825
29- listAPIKeys , err := api .ListAPIKeys (& iam.ListAPIKeysRequest {})
26+ listAPIKeys , err := api .ListAPIKeys (& iam.ListAPIKeysRequest {}, scw . WithAllPages () )
3027 if err != nil {
3128 return fmt .Errorf ("failed to list api keys: %w" , err )
3229 }
33- for _ , app := range listAPIKeys .APIKeys {
30+ for _ , key := range listAPIKeys .APIKeys {
31+ if ! isTestResource (key .Description ) {
32+ continue
33+ }
3434 err = api .DeleteAPIKey (& iam.DeleteAPIKeyRequest {
35- AccessKey : app .AccessKey ,
35+ AccessKey : key .AccessKey ,
3636 })
3737 if err != nil {
3838 return fmt .Errorf ("failed to delete api key: %w" , err )
@@ -60,13 +60,13 @@ func TestAccScalewayIamApiKey_WithApplication(t *testing.T) {
6060
6161 resource "scaleway_iam_api_key" "main" {
6262 application_id = scaleway_iam_application.main.id
63- description = "a description "
63+ description = "tf_tests_with_application "
6464 }
6565 ` ,
6666 Check : resource .ComposeTestCheckFunc (
6767 testAccCheckScalewayIamAPIKeyExists (tt , "scaleway_iam_api_key.main" ),
6868 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 " ),
7070 resource .TestCheckResourceAttrSet ("scaleway_iam_api_key.main" , "secret_key" ),
7171 ),
7272 },
@@ -78,13 +78,13 @@ func TestAccScalewayIamApiKey_WithApplication(t *testing.T) {
7878
7979 resource "scaleway_iam_api_key" "main" {
8080 application_id = scaleway_iam_application.main.id
81- description = "another description "
81+ description = "tf_tests_with_application_changed "
8282 }
8383 ` ,
8484 Check : resource .ComposeTestCheckFunc (
8585 testAccCheckScalewayIamAPIKeyExists (tt , "scaleway_iam_api_key.main" ),
8686 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 " ),
8888 resource .TestCheckResourceAttrSet ("scaleway_iam_api_key.main" , "secret_key" ),
8989 ),
9090 },
@@ -116,14 +116,14 @@ func TestAccScalewayIamApiKey_Expires(t *testing.T) {
116116
117117 resource "scaleway_iam_api_key" "main" {
118118 application_id = scaleway_iam_application.main.id
119- description = "an api key with an expiration date "
119+ description = "tf_tests_expires "
120120 expires_at = "2025-07-06T09:00:00Z"
121121 }
122122 ` ,
123123 Check : resource .ComposeTestCheckFunc (
124124 testAccCheckScalewayIamAPIKeyExists (tt , "scaleway_iam_api_key.main" ),
125125 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 " ),
127127 resource .TestCheckResourceAttr ("scaleway_iam_api_key.main" , "expires_at" , "2025-07-06T09:00:00Z" ),
128128 ),
129129 },
@@ -147,13 +147,13 @@ func TestAccScalewayIamApiKey_NoUpdate(t *testing.T) {
147147
148148 resource "scaleway_iam_api_key" "main" {
149149 application_id = scaleway_iam_application.main.id
150- description = "no update "
150+ description = "tf_tests_no_update "
151151 }
152152 ` ,
153153 Check : resource .ComposeTestCheckFunc (
154154 testAccCheckScalewayIamAPIKeyExists (tt , "scaleway_iam_api_key.main" ),
155155 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 " ),
157157 ),
158158 },
159159 {
@@ -164,13 +164,13 @@ func TestAccScalewayIamApiKey_NoUpdate(t *testing.T) {
164164
165165 resource "scaleway_iam_api_key" "main" {
166166 application_id = scaleway_iam_application.main.id
167- description = "no update "
167+ description = "tf_tests_no_update "
168168 }
169169 ` ,
170170 Check : resource .ComposeTestCheckFunc (
171171 testAccCheckScalewayIamAPIKeyExists (tt , "scaleway_iam_api_key.main" ),
172172 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 " ),
174174 ),
175175 },
176176 },
0 commit comments