下面的代码有效,但我无法在 vcn 名称的末尾添加 -vcn,而且我无法确保 vcn 位于它打算放置的隔间中。
我的 variables.tf 看起来像 -
#Compartment
variable "pv_compartment" {
type = map(string)
description = "Compartment Details"
}
variable "pv_enable_delete" {
description = "enable duplicate check on compartment names and delete on destroy"
}
variable "pv_subtenancy_ocid" {
description = "sub-tenancy ocid"
}
# VCN
variable "pv_vcn" {
type = map(string)
description = "VCN Details"
}
我的 main.tf 看起来像 -
resource "oci_identity_compartment" "tf_compartment" {
for_each = var.pv_compartment
compartment_id = var.pv_subtenancy_ocid
description = each.value
name = each.key
enable_delete = var.pv_enable_delete
}
resource "oci_core_vcn" "tf_vcn" {
count = length(var.pv_vcn)
cidr_block = values(var.pv_vcn)[count.index]
compartment_id = element([for x in oci_identity_compartment.tf_compartment: x.id], count.index)
display_name = keys(var.pv_vcn)[count.index]
}
我的 terraform.tfvars 看起来像 -
pv_subtenancy_ocid = "ocid1.tenancy.oc1..aaaaaaaa"
pv_compartment = {
mngmt-compartment = "Management Services Compartment"
app-compartment = "Application Compartment"
dmz-compartment = "DMZ Compartment"
db-compartment = "DB Compartment"
}
pv_enable_delete = "true"
#VCN Details
pv_vcn = {
mngmt = "10.234.0.0/23"
app = "10.234.10.0/23"
dmz = "10.234.2.0/23"
db = "10.234.16.0/23"
}