Terraform 0.12-网络模块

时间:2019-08-08 21:53:19

标签: google-cloud-platform terraform terraform-provider-gcp

我正在使用以下网络模块来构建VPC:https://github.com/terraform-google-modules/terraform-google-network

在main.tf中,我创建了三个子网:

:

该模块的功能之一是创建一系列子网。该模块包含一个输出:

locals {
  subnet_01 = "subnet-01"
  subnet_02 = "subnet-02"
  subnet_03 = "subnet-03"
}

module "test-vpc" {
  source       = "./modules/network/"
  project_id   = "${var.project}"
  network_name = "custom"

  subnets = [
    {
      subnet_name   = "${local.subnet_01}"
      subnet_ip     = "10.10.10.0/24"
      subnet_region = "us-east1"
    },
    {
      subnet_name           = "${local.subnet_02}"
      subnet_ip             = "10.10.20.0/24"
      subnet_region         = "us-west1"
      subnet_private_access = "false"
      subnet_flow_logs      = "false"
    },
    {
      subnet_name           = "${local.subnet_03}"
      subnet_ip             = "10.10.30.0/24"
      subnet_region         = "us-central1"
      subnet_private_access = "false"
      subnet_flow_logs      = "false"
    },
  ]

使用0.12的新功能,最好是外推这些值之一,让我们说“ subnet-01”,然后再将其传递到我的计算模块中?

例如:

output "subnets_names" {
  value       = google_compute_subnetwork.subnetwork.*.name
  description = "The names of the subnets being created"

output "subnets_self_links" {   
  value       = google_compute_subnetwork.subnetwork.*.self_link   
  description = "The self-links of subnets being created"

我当前正在传递local.subnet_03,但是我遇到了一个问题,即在VM(特别是创建保留的内部IP地址)之前未创建子网。由于网络和计算是不同的模块,因此我不能使用depends_on,因此我认为传递输出将对此有所帮助。

0 个答案:

没有答案