Terraform:引用了未知模块

Terraform: unknown module referenced

希望大家周末愉快。

对于在我的 GCP 项目中实现 nat 网关的最佳方式,我感到有些困惑。

我只是想简单地实现这个:https://github.com/GoogleCloudPlatform/terraform-google-nat-gateway

我把这个扔进了我的 main.tf:

module "nat" {
  source     = "GoogleCloudPlatform/nat-gateway/google"
  region     = "us-central1"
  network    = "default"
  subnetwork = "default"
}

并且我已将此标记(根据自述文件)添加到我的计算实例中: ${module.nat.routing_tag_regional}

但是,我看到了以下内容(我想这有点道理):

Error: resource 'google_compute_instance.ds3-build' config: reference to undefined module "nat"

因为我的 root/main.tf 中有模块,并且实例是通过另一个自定义编写的模块构建的。我是否需要从 root/main.tf 输出值才能在另一个模块中使用?

root/
├── app1-deploy/
│   ├── main.tf
│   ├── outputs.tf
│   └── variables.tf
├── app2-deploy
│   ├── main.tf
│   ├── outputs.tf
│   └── variables.tf
├── app3-deploy
│   ├── main.tf
│   ├── outputs.tf
│   └── variables.tf
├── creds
│   └── account.json
├── scripts
│   └── startup.sh
├── main.tf
├── outputs.tf
├── variables.tf
└── terraform.tfvars

机器在 app1-deploy/main.tf app2-deploy/main.tf 等中提供...并且 module "nat"root/main.tf

1) 计算资源是单独的 Terraform 项目吗?如果是这样,他们将看不到 module.nat,因为您的 root 项目是一个具有自己状态的不同项目。

2) 如果您的 nat 模块是在 root 项目中创建的,我会在您的计算模块上使用变量传递 ${module.nat.routing_tag_regional}