terraform - 将 terraform 输出从一个文件传递到另一个文件
问题描述
我有以下结构:
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 文件?我正在网上搜索,似乎无法找到答案。
解决方案
在 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
}
推荐阅读
- javascript - 在 Tampermonkey 中使用 JS 或 jQuery 设置 Body 标签的 ID
- c - 为什么我的 printf 函数没有在以下 C 代码中返回正确的扫描值?
- node.js - 从数据库获取响应时遇到问题,我随机输入了数据库名称作为测试。使用 mongodbAtlas 作为 url
- python - 使用 upnp 发布网页
- node.js - 如何从 shell 命令导入模拟数据
- azure - 为什么我的 Azure 应用服务会阻止来自 Kentico 调度程序的请求?
- oracle - 这个 UNION 语句有什么问题
- javascript - “body”溢出隐藏或通过onclick功能滚动
- excel - VBA 用户表单,文本框命名为 Reg.1 的日期,但是当我发送到数据表时,它不是日期值。如果按 F2 更改日期值
- laravel - 存储文件夹未提交到 laravel 项目中的 github