0

我正在尝试使用模块在 Azure 中创建多个元素。

目录结构看起来像

.
├── azure-provider.tf
├── backend.tf
├── rg
│   ├── azure-provider.tf
│   ├── backend.tf
│   ├── main.tf
│   ├── outputs.tf
│   ├── terragrunt-debug.tfvars.json
│   └── terragrunt.hcl
├── tags.tf
├── terragrunt.hcl
├── vnet
│   ├── main.tf
│   └── terragrunt.hcl
└── vwan
    ├── azure-provider.tf
    ├── backend.tf
    ├── main.tf
    ├── terragrunt-debug.tfvars.json
    └── terragrunt.hcl

3 directories, 17 files

我运行的第一个计划是创建一个资源组,基本上每个后续计划都需要它的位置。

modules/rg/outputs.tf 包含:

output "rg_name" {
  value = azurerm_resource_group.rg.name
}

output "rg_id" {
  value = azurerm_resource_group.rg.id
}

output "rg_location" {
  value = azurerm_resource_group.rg.location
}

stage/rg/outputs.tf 包含:

output "rg_location" {
  value = module.rg.rg_location
}

output "rg_name" {
  value = module.rg.rg_name
}

rg 中的计划运行良好,并输出

Apply complete! Resources: 0 added, 0 changed, 0 destroyed.
Releasing state lock. This may take a few moments...

Outputs:

rg_location = eastus
rg_name = vce-lab-stage

接下来我去构建 vwan,它的 main.tf 看起来像

  source = "../../modules/vwan"

  # these two are explicit
  vwan_name = "lab-vwan"
  vhub_name = "lab-vhub"

  # the other ones from rg state live in the terragrunt.hcl file as "inputs"
}

查找 rg 变量失败

terragrunt apply --auto-approve --terragrunt-debug                                                                                                    ✔ │ 12:13:12 PM
[terragrunt] [/Users/craigb/Projects/velocloud-virtual/azure-vwan/stage/vwan] 2020/09/21 12:13:17 Running command: terraform --version
[terragrunt] 2020/09/21 12:13:17 Terraform version: 0.13.3
[terragrunt] 2020/09/21 12:13:17 Reading Terragrunt config file at /Users/craigb/Projects/velocloud-virtual/azure-vwan/stage/vwan/terragrunt.hcl
[terragrunt] [/Users/craigb/Projects/velocloud-virtual/azure-vwan/stage/rg] 2020/09/21 12:13:17 Generated file /Users/craigb/Projects/velocloud-virtual/azure-vwan/stage/rg/.terragrunt-cache/387388653/backend.tf.
[terragrunt] [/Users/craigb/Projects/velocloud-virtual/azure-vwan/stage/rg] 2020/09/21 12:13:17 Running command: terraform init -get=false -get-plugins=false
[terragrunt] [/Users/craigb/Projects/velocloud-virtual/azure-vwan/stage/rg] 2020/09/21 12:13:28 Running command: terraform output -json
[terragrunt] 2020/09/21 12:13:30 The file path /Users/craigb/Projects/velocloud-virtual/azure-vwan/stage/vwan/azure-provider.tf already exists, but was a previously generated file by terragrunt. Since if_exists for code generation is set to "overwrite_terragrunt", regenerating file.
[terragrunt] 2020/09/21 12:13:30 Generated file /Users/craigb/Projects/velocloud-virtual/azure-vwan/stage/vwan/azure-provider.tf.
[terragrunt] 2020/09/21 12:13:30 The file path /Users/craigb/Projects/velocloud-virtual/azure-vwan/stage/vwan/backend.tf already exists, but was a previously generated file by terragrunt. Since if_exists for code generation is set to "overwrite_terragrunt", regenerating file.
[terragrunt] 2020/09/21 12:13:30 Generated file /Users/craigb/Projects/velocloud-virtual/azure-vwan/stage/vwan/backend.tf.
[terragrunt] 2020/09/21 12:13:30 Debug mode requested: generating debug file terragrunt-debug.tfvars.json in working dir /Users/craigb/Projects/velocloud-virtual/azure-vwan/stage/vwan
[terragrunt] 2020/09/21 12:13:30 Variables passed to terraform are located in "/Users/craigb/Projects/velocloud-virtual/azure-vwan/stage/vwan/terragrunt-debug.tfvars.json"
[terragrunt] 2020/09/21 12:13:30 Run this command to replicate how terraform was invoked:
[terragrunt] 2020/09/21 12:13:30    terraform apply --auto-approve -var-file="/Users/craigb/Projects/velocloud-virtual/azure-vwan/stage/vwan/terragrunt-debug.tfvars.json" "/Users/craigb/Projects/velocloud-virtual/azure-vwan/stage/vwan"
[terragrunt] 2020/09/21 12:13:30 Running command: terraform apply --auto-approve
Releasing state lock. This may take a few moments...

Error: Missing required argument

  on main.tf line 1, in module "vwan":
   1: module "vwan" {

The argument "rg_name" is required, but no definition was found.


Error: Missing required argument

  on main.tf line 1, in module "vwan":
   1: module "vwan" {

The argument "rg_location" is required, but no definition was found.

[terragrunt] 2020/09/21 12:13:48 Hit multiple errors:
exit status 1

stage/vwan/terragrunt-debug.tfvars.json,它只包含 {}

所以,我试图确定为什么 rg 的输出没有作为其他计划的输入。有任何想法吗?

Terraform v0.13.3 terragrunt 版本 v0.25.1

4

1 回答 1

0

“rg_name”和“rg_location”是第二个模块的依赖项,您是否在模块“vwan”中定义了它们?

于 2020-11-02T13:56:08.803 回答