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] 0.11.10 forces api key replacement due to whitespaces #873

Closed
Davasny opened this issue Oct 24, 2024 · 2 comments · Fixed by #875
Closed

[Bug] 0.11.10 forces api key replacement due to whitespaces #873

Davasny opened this issue Oct 24, 2024 · 2 comments · Fixed by #875
Labels
bug Something isn't working

Comments

@Davasny
Copy link

Davasny commented Oct 24, 2024

Describe the bug
After upgrading provider from 0.11.8 to 0.11.10 it want to replace api key due to whitespace changes. Api key role_descriptors are not changed

To Reproduce

  1. Create api key with 0.11.8
  2. Upgrade provider to 0.11.10
  3. Run plan
  # elasticstack_elasticsearch_security_api_key.telegraf must be replaced
-/+ resource "elasticstack_elasticsearch_security_api_key" "telegraf" {
      ~ api_key              = (sensitive value)
      ~ encoded              = (sensitive value)
      ~ expiration_timestamp = 0 -> (known after apply)
      ~ id                   = "25opFie5T1qs3JS9dz9YFA/daCobZIBlhlmOGXYaM3k" -> (known after apply)
      ~ key_id               = "daCobZIBlhlmOGXYaM3k" -> (known after apply)
      ~ metadata             = jsonencode({}) -> (known after apply)
        name                 = "telegraf"
      ~ role_descriptors     = jsonencode( # whitespace changes
            {
                telegraf = {
                    cluster = [
                        "monitor",
                        "cluster:admin/snapshot/status",
                        "cluster:admin/repository/get",
                        "manage_slm",
                    ]
                    indices = [
                        {
                            allow_restricted_indices = true
                            names                    = [
                                "*",
                            ]
                            privileges               = [
                                "monitor",
                                "view_index_metadata",
                            ]
                        },
                    ]
                }
            }
        )
        # (1 unchanged attribute hidden)
    }

Plan: 1 to add, 0 to change, 1 to destroy.

Expected behavior
Whitespaces shouldn't force api key replacement

Debug output
N/A

Screenshots
N/A

Versions (please complete the following information):

  • OS: macos 15
  • terraform 1.8.0
  • provider registry.terraform.io/elastic/elasticstack v0.11.10
  • elasticsearch 8.14.3 on elastic.co

Additional context
N/A

@Davasny Davasny added the bug Something isn't working label Oct 24, 2024
@flaper87
Copy link

Hi folks! FWIW, we just had multiple production incidents due to this. All tokens were rotated. which caused several services to fail.

There's a lot to say about what we can do internally to prevent this from happening in the future but figured I'd share that this has a wide spread impact and may be worth communicating.

I'd probably avoid a rollback of whatever caused this but definitely make the provider resilient to whitespace changes. We will now make 0.11.10 the minimum required version for us.

@tobio
Copy link
Member

tobio commented Oct 24, 2024

Ah, this bug sucks. Sorry folks.

For clarity, changes to role_descriptors aren't causing resource replacement here. This resource was migrated from the old Terraform SDK to the newer Plugin Framework in 0.11.10. The SDK stored unset attributes as in state as their default values, specifically expiration:"". The Plugin Framework correctly models this as expiration:null, however this was causing TF to force replacement of the API Key resource, since "" != null

#875 fixes this behaviour, only requiring replacement if the expiration values actually change (e.g 1d -> 1h).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
3 participants