[英]Multiple subnets in same VNet with Terrafrom
我對 terraform 完全陌生,我正在嘗試學習和編寫 TF 代碼來自動化 Azure VM 部署。 我試圖將每個部分作為模塊(rg 除外)覆蓋,而不是將其保存在單個 main.tf 文件中。 我的意圖是創建 1 個 vnet (TESTVNET) 並在同一個 Vnet 中創建多個子網,我可以在我的 tfvars 文件中定義子網名稱和地址。
我能夠到達直到在 VNet 上創建,但無法遍歷定義的子網
請通過我的代碼。 文件
Main.tf<\/code>
resource "azurerm_resource_group" "resource_group" {
name = var.RGname
location = var.RGlocation
}
module "VNET" {
source = "./Modules/NetworkConfig"
name = var.VNETname
address_space = var.address_space
location = var.RGlocation
resource_group_name = azurerm_resource_group.resource_group.name
}
module "SUBNETS" {
source = "./Modules/SubnetConfig"
Subnetlist = var.Subnetlist
virtual_network_name = module.VNET.vnet_name
resource_group_name = azurerm_resource_group.resource_group.name
depends_on = [azurerm_resource_group.resource_group, module.VNET.vnet]
}
Variables.tf (of main)
variable "RGlocation" {
}
variable "RGname" {
}
variable "VNETname" {
}
variable "address_space" {
}
variable "Subnetlist" {
type = map(object({
name = list(string)
address = list(string)
}))
}
迭代
Subnetlist<\/code>的方式是不正確的 - 您只能獲得“list”鍵的值,最終得到的是一組子網而不是單個項目。
將其改為單個子網對象的映射:
variable "Subnetlist" {
type = map(object({
name = string
address = string
}))
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.