-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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
Updating the value of an azurerm_key_vault_secret does not update its ID when used as a dependency #13337
Comments
Hello @kensykora , It's hard to say that it is a Terraform or AzureRM Provider's bug. This behavior is by design and I think it's very hard for HashiCorp to change that. Terraform workflow have two different stages: Plan and Apply. If you change data "azurerm_client_config" "current" {}
resource "azurerm_resource_group" "example" {
name = "example"
location = "East Asia"
}
resource "azurerm_key_vault" "example" {
name = "example"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
tenant_id = data.azurerm_client_config.current.tenant_id
sku_name = "standard"
soft_delete_retention_days = 7
access_policy {
tenant_id = data.azurerm_client_config.current.tenant_id
object_id = data.azurerm_client_config.current.client_id
key_permissions = [
"create",
"get",
]
secret_permissions = [
"set",
"get",
"delete",
"purge",
"recover"
]
}
}
resource "azurerm_key_vault_secret" "example" {
name = "secret-sauce"
value = "szechuan"
key_vault_id = azurerm_key_vault.example.id
}
resource "local_file" "output" {
filename = "${path.module}/output.txt"
content = azurerm_key_vault_secret.example.id
} In this case, if you change But, there's a walkaround: data "azurerm_client_config" "current" {}
resource "azurerm_resource_group" "example" {
name = "example"
location = "East Asia"
}
resource "azurerm_key_vault" "example" {
name = "example"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
tenant_id = data.azurerm_client_config.current.tenant_id
sku_name = "standard"
soft_delete_retention_days = 7
access_policy {
tenant_id = data.azurerm_client_config.current.tenant_id
object_id = data.azurerm_client_config.current.client_id
key_permissions = [
"create",
"get",
]
secret_permissions = [
"set",
"get",
"delete",
"purge",
"recover"
]
}
}
resource "azurerm_key_vault_secret" "example" {
name = "secret-sauce"
value = "szechuan"
key_vault_id = azurerm_key_vault.example.id
}
resource "null_resource" "example" {
triggers = {
trigger = azurerm_key_vault_secret.example.value
}
}
resource "local_file" "output" {
filename = "${path.module}/output.txt"
content = null_resource.example.id != "" ? azurerm_key_vault_secret.example.id : ""
} We can leverage |
@lonegunmanb Thanks for the reply -- I'm confused, why can't the |
Hi @kensykora , I think that could be related to how Terraform calculate plan that involved a force new resource's attribute. For now we can use this workaround trick, but we can check if there's issue on Terraform core project. Actually, we can use |
Hey @lonegunmanb -- I've seen other resources behave differently when they know their upstream dependencies are going to change. For example you see Are you saying it's not possible at all for the plugin to mark the |
Hi @kensykora , I think the problem we are facing here is, when you change |
Hi @lonegunmanb. I also faced this issue, and in my case it also causes inconsistent plan issue, when importing a key and changing its value in a single apply. Is there an issue to track on terraform core? |
Reported hashicorp/terraform-plugin-sdk#1267 |
@orgads The issue was closed and it seems to be possible. Can this be fixed in the provider? I also noticed that adding a new secret version isn't detected. |
Community Note
Terraform (and AzureRM Provider) Version
Terraform Configuration Files
Description / Feedback
When the underlying value for an
azurerm_key_vault_secret
changes, the ID for the secret is generated. In the above code sample, the first timeterraform apply
is run, the app_setting is seeded properly with the resulting ID from the key vault operation with the version of the secret created. Theapp_settings
config value will look something like:@Microsoft.KeyVault(SecretUri=https://hmykv.vault.azure.net/secrets/service-bus-connection-string/809284ceae23484589eb0fa1a6c6e147)
Again, on the initial first apply, this works as expected.
After changing the value (in our use case, rotating the primary access key of the access policy for the service bus account) however, the ID does not change on the 2nd apply. On the 2nd
terraform apply
, the value of the secret will be updated, but theazurerm_key_vault_secret.service_bus_connection_string.id
reference will remain at the old value.On a 3rd
terraform apply
, the secret version value in the attribute output reference will be properly updated.Steps to Reproduce:
terraform apply
- Observe that the use of theid
attribute inazurerm_key_vault_secret
is used correctlyazurerm_key_vault_secret
terraform apply
Expected: The dependency on the
azurerm_key_vault_secret
updates the usage of the.id
property such that dependencies on the secret in terraform are propagated and updated in their usagesActual: The value is updated in terraform, but the dependencies on the
.id
value of theazurerm_key_vault_secret
do not reflect the new ID created in Azure.Workaround: Run
terraform apply
a third time, and the ID will get updated.The text was updated successfully, but these errors were encountered: