【发布时间】:2021-07-24 15:00:36
【问题描述】:
我有这样的 Terraform 结构: 三个模块(app、db、vpc)和两个目录(prod、stage)
├── modules
│ ├── app
│ │ ├── main.tf
│ │ ├── outputs.tf
│ │ └── variables.tf
│ ├── db
│ │ ├── main.tf
│ │ └── variables.tf
│ └── vpc
│ ├── main.tf
│ └── variables.tf
├── prod
│ ├── main.tf
│ ├── outputs.tf
│ ├── terraform.tfstate
│ └── variables.tf
├── stage
│ ├── main.tf
│ ├── outputs.tf
│ ├── terraform.tfstate
│ └── variables.tf
当我从“stage”或“prod”目录启动 Terraform 并输入变量时:
terraform/prod - (main) > terraform plan
var.cluster_name
Enter a value: prod
然后,我收到一个变量未设置的错误:
│ Error: Reference to undeclared input variable
│
│ on ../modules/app/main.tf line 47, in resource "google_compute_address" "app_ip":
│ 47: name = var.cluster_name
│ An input variable with the name "cluster_name" has not been declared. This variable can be declared with a
│ variable "cluster_name" {} block.
有人可以帮忙吗,有什么问题吗?如何正确设置变量,以便在所选项目的所有模块中看到?
【问题讨论】:
-
我假设您在 prod/main.tf 中调用 ../modules/app/main.tf 模块 - 检查您是否将变量显式传递给模块。请记住,子模块不仅会从其父模块继承变量。
标签: terraform terraform-provider-gcp