Skip to content

Commit e639869

Browse files
FIx cloud instance service account update (#1355)
Closes #1354 Seems like the update doesn't work here. However, changing it to `ForceNew` fixes the issue
1 parent 8366ba1 commit e639869

File tree

2 files changed

+20
-17
lines changed

2 files changed

+20
-17
lines changed

internal/resources/cloud/resource_cloud_stack_service_account.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ This can be used to bootstrap a management service account for a new stack
5858
Type: schema.TypeBool,
5959
Optional: true,
6060
Default: false,
61+
ForceNew: true,
6162
Description: "The disabled status for the service account.",
6263
},
6364
},
@@ -136,17 +137,12 @@ func updateStackServiceAccount(ctx context.Context, d *schema.ResourceData, meta
136137
}
137138

138139
updateRequest := service_accounts.NewUpdateServiceAccountParams().
139-
WithBody(&models.UpdateServiceAccountForm{}).
140+
WithBody(&models.UpdateServiceAccountForm{
141+
Name: d.Get("name").(string),
142+
Role: d.Get("role").(string),
143+
IsDisabled: d.Get("is_disabled").(bool),
144+
}).
140145
WithServiceAccountID(id)
141-
if d.HasChange("name") {
142-
updateRequest.Body.Name = d.Get("name").(string)
143-
}
144-
if d.HasChange("role") {
145-
updateRequest.Body.Role = d.Get("role").(string)
146-
}
147-
if d.HasChange("is_disabled") {
148-
updateRequest.Body.IsDisabled = d.Get("is_disabled").(bool)
149-
}
150146

151147
if _, err := client.ServiceAccounts.UpdateServiceAccount(updateRequest); err != nil {
152148
return diag.FromErr(err)

internal/resources/cloud/resource_cloud_stack_service_account_test.go

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,24 @@ func TestAccGrafanaServiceAccountFromCloud(t *testing.T) {
3030
CheckDestroy: testAccStackCheckDestroy(&stack),
3131
Steps: []resource.TestStep{
3232
{
33-
Config: testAccGrafanaServiceAccountFromCloud(slug, slug),
33+
Config: testAccGrafanaServiceAccountFromCloud(slug, slug, true),
3434
Check: resource.ComposeTestCheckFunc(
3535
testAccStackCheckExists("grafana_cloud_stack.test", &stack),
3636
testAccGrafanaAuthCheckServiceAccounts(&stack, []string{"management-sa"}),
3737
resource.TestCheckResourceAttr("grafana_cloud_stack_service_account.management", "name", "management-sa"),
3838
resource.TestCheckResourceAttr("grafana_cloud_stack_service_account.management", "role", "Admin"),
39-
resource.TestCheckResourceAttr("grafana_cloud_stack_service_account.management", "is_disabled", "false"),
39+
resource.TestCheckResourceAttr("grafana_cloud_stack_service_account.management", "is_disabled", "true"),
4040
resource.TestCheckResourceAttr("grafana_cloud_stack_service_account_token.management_token", "name", "management-sa-token"),
4141
resource.TestCheckNoResourceAttr("grafana_cloud_stack_service_account_token.management_token", "expiration"),
4242
resource.TestCheckResourceAttrSet("grafana_cloud_stack_service_account_token.management_token", "key"),
4343
),
4444
},
45+
{
46+
Config: testAccGrafanaServiceAccountFromCloud(slug, slug, false),
47+
Check: resource.ComposeTestCheckFunc(
48+
resource.TestCheckResourceAttr("grafana_cloud_stack_service_account.management", "is_disabled", "false"),
49+
),
50+
},
4551
{
4652
Config: testAccStackConfigBasic(slug, slug, "description"),
4753
Check: testAccGrafanaAuthCheckServiceAccounts(&stack, []string{}),
@@ -50,20 +56,21 @@ func TestAccGrafanaServiceAccountFromCloud(t *testing.T) {
5056
})
5157
}
5258

53-
func testAccGrafanaServiceAccountFromCloud(name, slug string) string {
54-
return testAccStackConfigBasic(name, slug, "description") + `
59+
func testAccGrafanaServiceAccountFromCloud(name, slug string, disabled bool) string {
60+
return testAccStackConfigBasic(name, slug, "description") + fmt.Sprintf(`
5561
resource "grafana_cloud_stack_service_account" "management" {
5662
stack_slug = grafana_cloud_stack.test.slug
57-
name = "management-sa"
58-
role = "Admin"
63+
name = "management-sa"
64+
role = "Admin"
65+
is_disabled = %t
5966
}
6067
6168
resource "grafana_cloud_stack_service_account_token" "management_token" {
6269
stack_slug = grafana_cloud_stack.test.slug
6370
service_account_id = grafana_cloud_stack_service_account.management.id
6471
name = "management-sa-token"
6572
}
66-
`
73+
`, disabled)
6774
}
6875

6976
func testAccGrafanaAuthCheckServiceAccounts(stack *gcom.FormattedApiInstance, expectedSAs []string) resource.TestCheckFunc {

0 commit comments

Comments
 (0)