terraform - Terraform 模块内的执行顺序
问题描述
我对 terraform 脚本中模块的执行顺序有疑问。我对源代码库提出了一个问题。https://github.com/hashicorp/terraform/issues/18143
任何人都可以在这里或在 GitHub 上帮助我解决这个问题吗?
任何帮助将不胜感激。
谢谢!
解决方案
执行不等待“vpc”模块的完成,而只是等待值“module.vpc.vpc_id”的可用性。为此,执行 aws_vpc 资源就足够了。因此,您实际上并没有告诉 TerraForm 也等待 consul_keys 资源。
要解决此问题,您必须将 consul_keys 资源的依赖项添加到其他模块。这可以通过以下方式工作:
- 在其他模块(数据中心或 var.name>)中使用 consul_keys 导出的值
- 将依赖 consul_keys 的资源转储到同一个文件中。
遗憾的是,目前还没有很好的解决方案,但模块依赖关系正在研究中。
编辑: 作为将所有资源转储到同一文件中的示例:
这不起作用,因为没有模块依赖项:
module "vpc" {
...
}
module "other" {
depends_on=["module.vpc"]
}
vpc 模块文件:
resource "aws_instance" "vpc_res1" {
...
}
resource "consul_keys" "my_keys" {
...
}
其他模块文件:
resource "aws_instance" "other_res1" {
...
}
resource "aws_instance" "other_res2" {
...
}
将所有内容放在同一个文件中是可行的。您还可以将“vpc_res1”资源保存在单独的模块中:
resource "consul_keys" "my_keys" {
...
}
resource "aws_instance" "other_res1" {
depends_on = ["consul_keys.my_keys"]
}
resource "aws_instance" "other_res2" {
depends_on = ["consul_keys.my_keys"]
}
推荐阅读
- python - 用于在 unix 中自动下载 jnlp 文件的 Firefox 配置文件设置
- snowflake-cloud-data-platform - Snowflake ODBC 驱动程序支持多字节(非 ascii 字符串)?
- python - 在图中,按边名访问节点连接
- c# - System.Runtime.InteropServices.SEHException - 在 OleDb 连接中使用 C#
- scala - 使用 spark/scala 从 HDFS 目录中获取所有 csv 文件名
- python - 绘制波函数:TypeError:只有大小为 1 的数组可以转换为 Python 标量
- sql - 如何选择与固定时间范围(B)重叠的时间范围(A),其中A的开始时间或结束时间超出SQL Server中B的范围
- symfony - symfony 错误处理程序的 prod 环境中缺少供应商资产
- scala - 缺少参数类型 scala
- python - 我们可以更改 python 元组中的列表吗?