Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Error after upgrade provider: Error: id "85" does not match expected format. Should be in the format: stackSlug:serviceAccountID #1425

Closed
jkroepke opened this issue Mar 18, 2024 · 5 comments · Fixed by #1424 or #1426

Comments

@jkroepke
Copy link

Terraform Version

1.7.5

Terraform Grafana Provider Version

2.14.0

Grafana Version

Cloud

Affected Resource(s)

  • grafana_cloud_stack_service_account

Terraform Configuration Files

# Creating a grafana cloud stack service account
resource "grafana_cloud_stack_service_account" "terraform" {
  provider   = grafana.cloud
  stack_slug = grafana_cloud_stack.opsstack.slug

  name = "terraform"
  role = "Admin"
}

Expected Behavior

No error

Actual Behavior

Error: id "85" does not match expected format. Should be in the format: stackSlug:serviceAccountID

Steps to Reproduce

  1. Apply the terraform using 2.13.0
  2. Update to 2.14.0

Important Factoids

No response

References

No response

@julienduchesne
Copy link
Member

julienduchesne commented Mar 18, 2024

Sorry about that. PR and patch release incoming: #1424

@julienduchesne julienduchesne linked a pull request Mar 18, 2024 that will close this issue
@jkroepke
Copy link
Author

Hi @julienduchesne

I have the same issue with grafana_cloud_stack_service_account_token.

grafana_cloud_stack_service_account_token.terraform: Refreshing state... [id=82]

Planning failed. Terraform encountered an error while generating this plan.

╷
│ Error: id "85" does not match expected format. Should be in the format: stackSlug:serviceAccountID
│ 
│   with grafana_cloud_stack_service_account_token.terraform,
│   on main.tf line 19, in resource "grafana_cloud_stack_service_account_token" "terraform":
│   19: resource "grafana_cloud_stack_service_account_token" "terraform" {
│

julienduchesne added a commit that referenced this issue Mar 18, 2024
Closes #1425

I didn't fix all of it in #1424, unfortunately. Now, I have a test though!
@julienduchesne
Copy link
Member

This is embarrassing... Fix is here: #1426

As a workaround, you can do a targeted apply on the stack_service_account resource and then planning the token resource will work

julienduchesne added a commit that referenced this issue Mar 19, 2024
* One more fix for `grafana_cloud_stack_service_account`
Closes #1425

I didn't fix all of it in #1424, unfortunately. Now, I have a test though!

* Remove trailing whiteline
@jkroepke
Copy link
Author

Hi @julienduchesne

plan works in theory, but I now terraform wants to recreate the SA. Is this expected?


Note: Objects have changed outside of Terraform

Terraform detected the following changes made outside of Terraform since the
last "terraform apply" which may have affected this plan:

  # grafana_cloud_stack_service_account.terraform has changed
  ~ resource "grafana_cloud_stack_service_account" "terraform" {
      ~ id          = "85" -> "opsstack:85"
        name        = "terraform"
        # (3 unchanged attributes hidden)
    }


Unless you have made equivalent changes to your configuration, or ignored the
relevant attributes using ignore_changes, the following plan may include
actions to undo or respond to these changes.

─────────────────────────────────────────────────────────────────────────────

Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
-/+ destroy and then create replacement

Terraform planned the following actions, but then encountered a problem:

  # grafana_cloud_stack_service_account_token.terraform must be replaced
-/+ resource "grafana_cloud_stack_service_account_token" "terraform" {
      + expiration         = (known after apply)
      ~ has_expired        = false -> (known after apply)
      ~ id                 = "82" -> (known after apply)
      ~ key                = (sensitive value)
        name               = "terraform"
      ~ service_account_id = "85" -> "opsstack:85" # forces replacement
        # (1 unchanged attribute hidden)
    }

Plan: 1 to add, 0 to change, 1 to destroy.
Releasing state lock. This may take a few moments...
╷
│ Error: the Grafana client is required for this resource. Set the auth and url provider attributes
│ 
│   with grafana_dashboard.this["dashboards/Ops.Stack Overview.json"],
│   on dashboards.tf line 2, in resource "grafana_dashboard" "this":
│    2: resource "grafana_dashboard" "this" {
│ 
╵
Error: Terraform exited with code 1.
Error: Process completed with exit code 1.

@julienduchesne
Copy link
Member

Not expected but will fix. Terraform resource IDs are a minefield, can't wait to move away from the old SDK. For now, you can do a targeted apply on the service account token

julienduchesne added a commit that referenced this issue Mar 20, 2024
…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
julienduchesne added a commit that referenced this issue Mar 20, 2024
…esource (#1431)

* Fix `service_account_id` reference in `stack_service_account_token` resource
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

* Add validation for update and delete too. These can make tests panic

* Fix test so it doesn't fail randomly
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants