【问题标题】:terragrunt not accepting vars filesterragrunt 不接受 vars 文件
【发布时间】:2020-02-04 01:21:25
【问题描述】:

我正在尝试使用 2-repo IaC,所谓的后端采用 terragrunt 模块的形式,前端(或 live)具有正在填充的此类模块的实例化在变量中。

下图描述了这 2 个 repos 的结构(terragrunt 是后端,terraform-live 顾名思义是实时的)。

在我的terragrunt/aws-vpc/variables.tf,有如下声明:

variable "remote_state_bucket" {
  description = "The bucket containing the terraform remote state"
}

但是,当尝试在 live 目录中执行 terragrunt apply 时,我得到以下信息:

var.remote_state_bucket
  The bucket containing the terraform remote state

  Enter a value:

这是我的terraform-live/environments/staging/terragrunt.hcl

  remote_state {
    backend = "s3"
    config = {
      bucket  = "my-bucket-staging"
      key  = "terraform/state/var.env_name/${path_relative_to_include()}"
      region = "eu-west-1"
    }
  }
  # Configure root level variables that all resources can inherit
  terraform {
    extra_arguments "extra_args" {
      commands = "${get_terraform_commands_that_need_vars()}"
      optional_var_files = [
          "${get_terragrunt_dir()}/${find_in_parent_folders("config.tfvars", "ignore")}",
          "${get_terragrunt_dir()}/${find_in_parent_folders("secrets.auto.tfvars", "ignore")}",
      ]
    }
  }

更重要的是,该变量似乎是在terragrunt被指示从以下文件中读取变量的文件之一中声明的:

➢  cat terraform-live/environments/staging/config.tfvars
remote_state_bucket = "pkaramol-staging"

为什么terragrunt(或terraform?)无法读取特定变量?

➢  terragrunt --version
terragrunt version v0.19.29

➢  terraform --version
Terraform v0.12.4

【问题讨论】:

    标签: terraform infrastructure-as-code terragrunt


    【解决方案1】:

    因为config.tfvars 不在父文件夹中:)

    find_in_parent_folders 在父文件夹中查找,但不在当前文件夹中。而且您的config.tfvars 与您的terragrunt.hcl 在同一个文件夹中。

    尝试使用类似的东西:

    optional_var_files = [
        "${get_terragrunt_dir()}/config.tfvars",
        "${get_terragrunt_dir()}/secrets.auto.tfvars",
    ]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-03-09
      • 1970-01-01
      • 2014-09-10
      • 2011-03-21
      • 2014-10-17
      • 2021-05-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多