【问题标题】:Pass terraform output from one file to another将 terraform 输出从一个文件传递到另一个文件
【发布时间】:2020-11-30 06:44:45
【问题描述】:

我有以下结构:

modules
 |_ test1
 |    |_vpc.tf
 |_test2
      |_subnet.tf

我在 test1/vpc.tf 中创建了一个 vpc

resource "aws_vpc" "main" {
  cidr_block = "10.0.0.0/16"
}

我在输出中得到 vpc id,例如:

output "vpc_id" {
  value = aws_vpc.main.id
}

如何将此 id 传递给 test2/subnet.tf 文件?我正在网上搜索,似乎无法找到答案。

【问题讨论】:

    标签: terraform terraform0.12+


    【解决方案1】:

    在subnet.tf中创建一个变量:

    variable "vpc_id" {
      type = string
    }
    

    然后在您使用这两个模块的主 terraform 文件中,您将从 vpc 模块获取输出并将其传递给子网模块的输入:

    module "vpc" {
      source = "modules/test1"
    }
    
    module "subnet" {
      source = "modules/test2"
      vpc_id = module.vpc.vpc_id
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-27
      • 1970-01-01
      • 2016-10-30
      相关资源
      最近更新 更多