我有一组变量terraform.tfvars:
resource_groups = {
cow = {
name = "Cow"
location = "eastus"
},
horse = {
name = "Horse"
location = "eastus"
},
chicken = {
name = "Chicken"
location = "westus2"
},
}
Run Code Online (Sandbox Code Playgroud)
我的main.tf样子是这样的:
...
module "myapp" {
source = "./modules/myapp"
resource_groups = var.resource_groups
}
variable "resource_groups" {}
...
Run Code Online (Sandbox Code Playgroud)
./modules/myapp.main.tf看起来像这样:
module "resource_group" {
source = "../myapp.resource_group"
resource_groups = var.resource_groups
for_each = {
for key, value in try(var.resource_groups, {}) : key => value
if …Run Code Online (Sandbox Code Playgroud)