Skip to content

Instantly share code, notes, and snippets.

@leitu
Created October 28, 2019 00:35
Show Gist options
  • Save leitu/89c5146f8f1ae47e0fe2ddae112172d2 to your computer and use it in GitHub Desktop.
Save leitu/89c5146f8f1ae47e0fe2ddae112172d2 to your computer and use it in GitHub Desktop.
terraform v12.x count and for_each are using together
data "azurerm_client_config" "current" {}
resource "azurerm_key_vault" "keyvault" {
count = "${length(var.vaultnames)}"
name = "${var.servicename}-${var.vaultnames[count.index]}"
location = "${var.keyvault_location}"
resource_group_name = "${var.keyvault_resource_group}"
tenant_id = "${data.azurerm_client_config.current.tenant_id}"
sku_name = "standard"
dynamic "access_policy" {
for_each = var.object_user_id
content {
tenant_id = "${data.azurerm_client_config.current.tenant_id}"
object_id = access_policy.value
secret_permissions = [
"get",
"list",
]
}
}
tags = {
environment = "${var.tag_environment}"
}
}
variable "servicename" {}
variable "vaultnames" {
type=list(any)
default = ["test", "users"]
}
variable "keyvault_location" {}
variable "keyvault_resource_group" {}
variable "tag_environment" {}
variable "object_id" {
default = {
"xyz" = "3704c477-d527-4074-82c4-7f40be0435bfb"
}
}
variable "object_user_id" {
default = {
"abc" = "3704c477-d527-4074-82c4-7f40be0435bfa"
"efg" = "3704c477-d527-4074-82c4-7f40be0435bfb"
"hjk" = "3704c477-d527-4074-82c4-7f40be0435bfc"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment