Skip to content

Conversation

@tobio
Copy link
Member

@tobio tobio commented Aug 21, 2025

Fixes #693

I started off creating an independent resource for cross cluster keys, but there's a lot of duplication and it's not clear what benefit there is in splitting them apart.

@tobio tobio requested review from dimuon and nick-benoit August 21, 2025 11:03
@tobio tobio self-assigned this Aug 21, 2025
@nick-benoit
Copy link
Contributor

nick-benoit commented Sep 2, 2025

@tobio It seems that updating the key access:

  # elasticstack_elasticsearch_security_api_key.cross_cluster_key will be updated in-place
  ~ resource "elasticstack_elasticsearch_security_api_key" "cross_cluster_key" {
      ~ access               = {
          ~ replication = [
              ~ {
                  ~ names = [
                      ~ "archive-*" -> "archive-test-*",
                    ]
                },
            ]
        }
        id                   = "SgYidikGTeuWQ-qWz5pU_w/z2PdC5kBKm2x_cQXbsR7"
        name                 = "My Cross-Cluster API Key"
        # (8 unchanged attributes hidden)
    }

The role descriptions are also updated which results in this error:

elasticstack_elasticsearch_security_api_key.cross_cluster_key: Modifying... [id=SgYidikGTeuWQ-qWz5pU_w/z2PdC5kBKm2x_cQXbsR7]
╷
│ Error: Provider produced inconsistent result after apply
│ 
│ When applying changes to elasticstack_elasticsearch_security_api_key.cross_cluster_key, provider "provider[\"registry.terraform.io/elastic/elasticstack\"]" produced an unexpected
│ new value: .role_descriptors: was
│ cty.StringVal("{\"cross_cluster\":{\"cluster\":[\"cross_cluster_replication\"],\"indices\":[{\"names\":[\"archive-*\"],\"privileges\":[\"cross_cluster_replication\",\"cross_cluster_replication_internal\"],\"allow_restricted_indices\":false}]}}"),
│ but now
│ cty.StringVal("{\"cross_cluster\":{\"cluster\":[\"cross_cluster_replication\"],\"indices\":[{\"names\":[\"archive-test-*\"],\"privileges\":[\"cross_cluster_replication\",\"cross_cluster_replication_internal\"],\"allow_restricted_indices\":false}]}}").
│ 
│ This is a bug in the provider, which should be reported in the provider's own issue tracker.

I wonder if we should get rid of UseStateForUnknown for the role_descriptors field? It seems like this field is not updatable in the cross cluster api (docs). Perhaps this is a good argument for a different resource like you mentioned in the PR description?

IMPORTANT: If you don't specify role_descriptors in the request, a call to this API might still change the API key's access scope. This change can occur if the owner user's permissions have changed since the API key was created or last modified.

link

It looks like this field is a bit sticky for non-cross cluster api key updates as well.

name = "%s"
type = "cross_cluster"
access = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense to have this acceptance test update something in access to get some IT style acceptance test coverage of SetUnknownIfAccessHasChanges?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, it does exactly that.

@tobio tobio merged commit 61a23dc into main Sep 5, 2025
70 of 71 checks passed
@tobio tobio deleted the api-key-with-cross-cluster branch September 5, 2025 03:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Add Cross Cluster API keys management

3 participants