【发布时间】:2022-08-16 00:38:46
【问题描述】:
我正在尝试将start-stop schedule 添加到我们云存储库中的 vm 实例(这是一个 terraform/terragrunt 设置)
官方网站上的示例是这样的:
所以因为我们使用土拨鼠作为包装器,我的模块如下所示:
并作为参考我的变量块这是:
当我推送代码时,它在 CloudBuild 的第 0 步出错,并出现以下错误:
错误:在资源 \"google_compute_resource_policy\" \"hourly\" 中的 main.tf 第 116 行引用未声明的输入变量:116:time_zone = var.time_zone 尚未声明名为“time_zone”的输入变量。此变量可以用变量“time_zone”{}块声明。
我曾尝试将此变量放在块的不同位置,但我一直收到相同的错误。有没有人有任何想法?
-
因为变量
instance_schedule_policy是一个具有不同属性的对象,为了引用time_zone你需要这样做:var.instance_schedule_policy.time_zone -
我做了修改:
resource \"google_compute_resource_policy\" \"hourly\" { #description = \"Start and stop instances\" instance_schedule_policy { name = var.name region = var.region #time_zone = var.time_zone vm_start_schedule { schedule = var.vm_start_schedule } vm_stop_schedule { schedule = var.vm_stop_schedule } time_zone = var.instance_schedule_policy.time_zone } } -
on main.tf line 112, in resource \"google_compute_resource_policy\" \"hourly\": 112: schedule = var.vm_start_schedule An input variable with the name \"vm_start_schedule\" has not been declared. This variable can be declared with a variable \"vm_start_schedule\" {} block.stop_schedule 相同。如果我尝试将 schedule = var.vm_stop_schedule 重命名为 vm_stop_schedule = var.vm_stop_schedule 它错误地建议它期望schedule =
标签: google-cloud-platform terraform google-cloud-build terraform-provider-gcp terragrunt