I have a simple Terraform config to create secret in Azure keyvault.
provider "azurerm" {
features {}
}
data "azurerm_key_vault" "SomeApp-DEV" {
name = "SomeApp-DEV"
resource_group_name = "SomeApp"
}
resource "azurerm_key_vault_secret" "test-secret" {
name = "some-key"
value = "test value"
key_vault_id = data.azurerm_key_vault.SomeApp-DEV
}
After terraform plan
I'm getting the following error:
Error: Incorrect attribute value type
on secret.tf line 13, in resource "azurerm_key_vault_secret" "test-secret":
13: key_vault_id = data.azurerm_key_vault.SomeApp-DEV
├────────────────
│ data.azurerm_key_vault.SomeApp-DEV is object with 17 attributes
Inappropriate value for attribute "key_vault_id": string required.
How to make it work? I don't know what this object with 17 attributes
message even means?
CodePudding user response:
When you access the exported attribute with the namespace data.<type>.<name>
, then you are accessing the entire Map of exported attributes from that data (this is also true of exported attributes for resources). In this situation, you only want the String for the id
, whose value is assigned to the key id
in the Map of exported attributes:
resource "azurerm_key_vault_secret" "test-secret" {
name = "some-key"
value = "test value"
key_vault_id = data.azurerm_key_vault.SomeApp-DEV.id
}
and this will fix your issue.