0

我有一个代码

resource "oci_core_security_list" "db_security_list" {
  count          = var.deploy_database ? 1 : 0
  compartment_id = var.network_compartment_id
  vcn_id         = var.vcn_id
  freeform_tags  = { "Component" = "Database" }
  display_name   = "test-db-sl"
  ingress_security_rules {
    protocol = "6" # TCP
    source   = var.compute_subnet_cidr
    tcp_options {
      max = "1522"
      min = "1522"
    }
  }
}

目前compute_subnet_cidr有一个子网 cidr 块

如果 compute_subnet_cidr 是一个列表,我该如何迭代。

compute_subnet_cidr  = ["10.10.10.0/24", "10.10.10.1/24", "10.10.10.2/24"]

如何更改上述代码?

4

1 回答 1

1

是的,您可以使用动态块

resource "oci_core_security_list" "db_security_list" {
  count          = var.deploy_database ? 1 : 0
  compartment_id = var.network_compartment_id
  vcn_id         = var.vcn_id
  freeform_tags  = { "Component" = "Database" }
  display_name   = "test-db-sl"

  dynamic "ingress_security_rules" {    
      for_each   = var.compute_subnet_cidr
      content {
        protocol = "6" # TCP
        source   = ingress_security_rules.value
        tcp_options {
          max = "1522"
          min = "1522"
        }
     }
   }  

}
于 2021-11-23T09:59:45.053 回答