【问题标题】:Asked to enter values for variables set in terraform module using terragrunt要求使用 terragrunt 为 terraform 模块中设置的变量输入值
【发布时间】:2018-09-29 21:04:55
【问题描述】:

我有一个 terragrunt 项目,其结构如下:

|---terraform.tfvars
|---account
|   |---us-east-1
|       |---nonprod
|           |---s3
|               |---terraform.tfvars
|---modules
|   |---s3
|       |---main.tf
|---source
    |---s3
        |---main.tf
        |---provider.tf
        |---vars.tf

/account/us-east-1/nonprod/s3/terraform.tvars

terragrunt = {
  terraform {
    source = "../../../../modules/s3"
  }

  include {
    path = "${find_in_parent_folders()}"
  }
}

/modules/s3/main.tf

module "s3" {
    source = "../../source/s3"

    app-name = "example-app"
    aws-region = "us-east-1"
    bucket-name = "example-app-bucket"
}

/source/s3/main.tf

resource "aws_s3_bucket" "s3" {
  region        = "${var.aws-region}"
  bucket        = "${var.bucket-name}"
  acl           = "private"
  force_destroy = "true"

  tags {
    Name        = "${var.app-name}"
  }
}

当我从account 目录运行 terragrunt 时:

$ terragrunt plan-all --terragrunt-source ../../../../source

我被要求输入我在 /modules/s3/main.tf 中设置的变量的值

var.app-name
  Enter a value:

但是,当我从 modules/s3 目录运行 terraform plan 时,它似乎可以工作。

使用 terragrunt 时此设置有什么问题?

【问题讨论】:

    标签: terraform terragrunt


    【解决方案1】:

    我认为导致问题的混淆在于事物的命名。即source/s3 是真正的TF 模块,而modules/s3调用(使用) 模块的TF 代码。

    terragrunt 期望在配置中找到模块源,而不是调用模块的 TF 代码。

    terraform.tfvars试试这个:

    terragrunt = {
      terraform {
        source = "../../../../source/s3"
      }
    
      # ... other code & configs ...
    
    }
    

    HTH!

    【讨论】:

      猜你喜欢
      • 2020-12-08
      • 2021-01-11
      • 2021-05-16
      • 2022-01-27
      • 2022-06-22
      • 2019-10-06
      • 2021-06-01
      • 1970-01-01
      • 2017-05-26
      相关资源
      最近更新 更多