Hi folks,
I’m using terraform with Vault KV v2 to manage secrets. When I try to update a secret for the first time, I get the following error:
vault_kv_secret_v2.user: Modifying… [id=xxxx/data/]
╷
│ Error: error writing custom metadata to xxxx/metadata/xxxx, err=Error making API request.
│
│ URL: PUT v1/xxxx/metadata/xxxx
│ Code: 403. Errors:
│
│ * 1 error occurred:
│ * permission denied
│
│
│ with vault_kv_secret_v2.user,
│ on main.tf line 49, in resource “vault_kv_secret_v2” “user”:
│ 49: resource “vault_kv_secret_v2” “user” {
Interestingly, if I try the same operation a second time, it succeeds.Why does vault_kv_secret_v2 require access to the metadata/… path even if I’m only updating a secret under data/…?
Based on the source code implementing this resource type in the hashicorp/vault provider, it seems like this request is handling the value of the custom_metadata argument in vault_kv_secret_v2:
I notice that you already found this because you linked to it from a different issue, but just to make this link visible to anyone who finds this forum post there seems to be a bug where the provider calls this endpoint even when custom_metadata is unset: