Skip to content

Commit 2243263

Browse files
authored
fix(iam_api_key): set application_id to force_new (#2023)
1 parent f2e0f1d commit 2243263

3 files changed

+959
-0
lines changed

scaleway/resource_iam_api_key.go

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ func resourceScalewayIamAPIKey() *schema.Resource {
5656
"application_id": {
5757
Type: schema.TypeString,
5858
Optional: true,
59+
ForceNew: true,
5960
Description: "ID of the application attached to the api key",
6061
ConflictsWith: []string{"user_id"},
6162
ValidateFunc: validationUUID(),

scaleway/resource_iam_api_key_test.go

+64
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,70 @@ func TestAccScalewayIamApiKey_WithApplication(t *testing.T) {
105105
})
106106
}
107107

108+
func TestAccScalewayIamApiKey_WithApplicationChange(t *testing.T) {
109+
tt := NewTestTools(t)
110+
defer tt.Cleanup()
111+
resource.ParallelTest(t, resource.TestCase{
112+
ProviderFactories: tt.ProviderFactories,
113+
CheckDestroy: resource.ComposeTestCheckFunc(
114+
testAccCheckScalewayIamAPIKeyDestroy(tt),
115+
testAccCheckScalewayIamApplicationDestroy(tt),
116+
),
117+
Steps: []resource.TestStep{
118+
{
119+
Config: `
120+
resource "scaleway_iam_application" "main" {
121+
name = "tf_tests_api_key_app_change"
122+
}
123+
124+
resource "scaleway_iam_application" "main2" {
125+
name = "tf_tests_api_key_app_change2"
126+
}
127+
128+
resource "scaleway_iam_api_key" "main" {
129+
application_id = scaleway_iam_application.main.id
130+
description = "tf_tests_with_application_change"
131+
}
132+
`,
133+
Check: resource.ComposeTestCheckFunc(
134+
testAccCheckScalewayIamAPIKeyExists(tt, "scaleway_iam_api_key.main"),
135+
resource.TestCheckResourceAttrPair("scaleway_iam_api_key.main", "application_id", "scaleway_iam_application.main", "id"),
136+
resource.TestCheckResourceAttr("scaleway_iam_api_key.main", "description", "tf_tests_with_application_change"),
137+
resource.TestCheckResourceAttrSet("scaleway_iam_api_key.main", "secret_key"),
138+
),
139+
},
140+
{
141+
Config: `
142+
resource "scaleway_iam_application" "main" {
143+
name = "tf_tests_api_key_app_change"
144+
}
145+
146+
resource "scaleway_iam_application" "main2" {
147+
name = "tf_tests_api_key_app_change2"
148+
}
149+
150+
resource "scaleway_iam_api_key" "main" {
151+
application_id = scaleway_iam_application.main2.id
152+
description = "tf_tests_with_application_change"
153+
}
154+
`,
155+
Check: resource.ComposeTestCheckFunc(
156+
testAccCheckScalewayIamAPIKeyExists(tt, "scaleway_iam_api_key.main"),
157+
resource.TestCheckResourceAttrPair("scaleway_iam_api_key.main", "application_id", "scaleway_iam_application.main2", "id"),
158+
resource.TestCheckResourceAttr("scaleway_iam_api_key.main", "description", "tf_tests_with_application_change"),
159+
resource.TestCheckResourceAttrSet("scaleway_iam_api_key.main", "secret_key"),
160+
),
161+
},
162+
{
163+
ResourceName: "scaleway_iam_api_key.main",
164+
ImportState: true,
165+
ImportStateVerify: true,
166+
ImportStateVerifyIgnore: []string{"secret_key"},
167+
},
168+
},
169+
})
170+
}
171+
108172
func TestAccScalewayIamApiKey_Expires(t *testing.T) {
109173
tt := NewTestTools(t)
110174
defer tt.Cleanup()

0 commit comments

Comments
 (0)