Skip to content

Commit

Permalink
Fix service_account_id reference in stack_service_account_token r…
Browse files Browse the repository at this point in the history
…esource

As mentioned here: #1425 (comment), the plan looks good but the apply of the stack SA causes a recreation of the token

Added a `DiffSuppressFunc` and expanded the test to include a full use case
  • Loading branch information
julienduchesne committed Mar 20, 2024
1 parent f567d37 commit 513d516
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func TestAccGrafanaServiceAccountFromCloud_MigrateFrom213(t *testing.T) {
testAccGrafanaAuthCheckServiceAccounts(&stack, []string{"management-sa"}),
resource.TestCheckResourceAttr("grafana_cloud_stack_service_account.management", "name", "management-sa"),
resource.TestCheckResourceAttr("grafana_cloud_stack_service_account.management", "role", "Admin"),
resource.TestCheckResourceAttr("grafana_cloud_stack_service_account.management", "is_disabled", "true"),
resource.TestCheckResourceAttr("grafana_cloud_stack_service_account.management", "is_disabled", "false"),
resource.TestCheckResourceAttr("grafana_cloud_stack_service_account_token.management_token", "name", "management-sa-token"),
resource.TestCheckNoResourceAttr("grafana_cloud_stack_service_account_token.management_token", "expiration"),
resource.TestCheckResourceAttrSet("grafana_cloud_stack_service_account_token.management_token", "key"),
Expand All @@ -88,7 +88,7 @@ func TestAccGrafanaServiceAccountFromCloud_MigrateFrom213(t *testing.T) {
Steps: []resource.TestStep{
// Apply with 2.13.0 provider
{
Config: testAccGrafanaServiceAccountFromCloud(slug, slug, true),
Config: testAccGrafanaServiceAccountFromCloud(slug, slug, false),
ExternalProviders: map[string]resource.ExternalProvider{
"grafana": {
VersionConstraint: "=2.13.0",
Expand All @@ -99,7 +99,7 @@ func TestAccGrafanaServiceAccountFromCloud_MigrateFrom213(t *testing.T) {
},
// Apply with latest provider
{
Config: testAccGrafanaServiceAccountFromCloud(slug, slug, true),
Config: testAccGrafanaServiceAccountFromCloud(slug, slug, false),
Check: check,
ProtoV5ProviderFactories: testutils.ProtoV5ProviderFactories,
},
Expand All @@ -121,6 +121,17 @@ func testAccGrafanaServiceAccountFromCloud(name, slug string, disabled bool) str
service_account_id = grafana_cloud_stack_service_account.management.id
name = "management-sa-token"
}
provider "grafana" {
alias = "stack"
auth = grafana_cloud_stack_service_account_token.management_token.key
url = grafana_cloud_stack.test.url
}
resource "grafana_folder" "test" {
provider = grafana.stack
title = "test"
}
`, disabled)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ Required access policy scopes:
Type: schema.TypeString,
Required: true,
ForceNew: true,
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
// The service account ID is now possibly a composite ID that includes the stack slug
oldID, _ := getStackServiceAccountID(old)
newID, _ := getStackServiceAccountID(new)
return oldID == newID && oldID != 0 && newID != 0
},
},
"seconds_to_live": {
Type: schema.TypeInt,
Expand Down

0 comments on commit 513d516

Please sign in to comment.