I am trying to update the expiration date of all the secrets available in the Key Vault. I have written below terraform script and kind of stuck at a point.
main.tf file
data "azurerm_key_vault" "key_vault_data" {
name = var.name
resource_group_name = var.resource_group_name
}
resource "azurerm_key_vault_secret" "all_secrets" {
for_each = data.azurerm_key_vault.key_vault_data.secrets
name = each.value.name
value = each.value.value
key_vault_id = data.azurerm_key_vault.key_vault_data.id
expiration_date = timestamp() + var.days_to_expire * 24 *60 *60
}
variable.tf file
variable "name" {
default = "KV-***" # name of the key vault
}
variable "resource_group_name" {
default = "RG-***" # name of the resource group
}
variable "days_to_expire" {
type = number
default = 730
}
Below is the error I am getting when I run the terraform script
Error: Unsupported attribute on .terraform/modules/key_vault/main.tf
line 130, in resource "azurerm_key_vault_secret" "all_secrets":
130:for_each = data.azurerm_key_vault.key_vault_data.secrets this object
has no argument, nested block, or exported attribute name "secrets".