Tomas Gryzbon
Tomas Gryzbon

Reputation: 97

Terraform utilize a value passed into a Data Source

How can I use a value passed into a Data Source? It seems like there is no issue in snowflake_user.userSVC_db as it properly states that I would like to check whether or not a Secret within Azure Key Vault with name INGEROIS_ABB_PBI_SVC exists

resource "snowflake_user" "userSVC_db" {
  for_each             = var.user_collection
  name                 = each.key
  ...
  password             =  ( each.value.password_overwrite == false ? random_password.password[ index(keys(var.user_collection), each.key) ].result : (                                                           
                            each.value.password_overwrite == true  ? random_password.password-overwrite.result : (
                            each.value.password_overwrite == null ? data.azurerm_key_vault_secret.secret_check["PM-${replace(each.value.name, "_", "-")}"].value : null
  )
 )
)
}

The problem is that I do not know how I am suppose to express that a passed value should be assigned to property name instead of looping through whole collection:

data "azurerm_key_vault_secret" "secret_check" {
  for_each     = var.user_collection
  name         = "PM-${replace(each.value.name, "_", "-")}"
  key_vault_id = module.variables.keyVault-id
}

Upvotes: 0

Views: 44

Answers (1)

SoySolisCarlos
SoySolisCarlos

Reputation: 853

You can reference a key vault secret ID with the following syntax:

azurerm_key_vault_secret.secret_checkSecrets["KEY-VALUE-FROM-user_collection"].id

The value "KEY-VALUE-FROM-user_collection" is from your loop var.user_collection

Upvotes: 1

Related Questions