terraform - 如何将更改反向传播到父节点?
问题描述
我有一个null_resource.gateway_setup
我无法使幂等的 - 它只能运行一次。尝试多次运行它会导致错误。
因此,如果我对我的块进行更改gateway_setup
,我还想terraform apply
触发aws_instance.gateway
块刷新。
这可能吗?如果是这样,我该怎么做?
resource "aws_instance" "gateway" {
...
}
resource "null_resource" "gateway_setup" {
depends_on = [ "aws_instance.gateway" ]
...
provisioner "remote-exec" {
connection {
type = "ssh"
user = "centos"
host = "${aws_instance.gateway.public_ip}"
}
inline = [
# throw an error if gateway setup had already run on this instance
# preferrably, instead of erroring, the instance should be destroyed and recreated
"[ -f /etc/tf__null_resource__gateway_setup_complete ] && exit 1",
# make some non-idempotent changes
"./configure_gateway.sh",
# flag that this instance is dirty
"touch /etc/tf__null_resource__gateway_setup_complete",
]
}
}
如果我terraform apply
在新环境中运行,“null_resource.gateway_setup”应该可以正常运行。如果我对网关设置逻辑进行更改并terraform apply
再次运行,在运行“null_resource.gateway_setup”之前,我希望实例被销毁并重新创建。
解决方案
推荐阅读
- python - 使用交叉验证来确定机器学习算法的权重(GridSearchCv、RidgeCV、StackingClassifier)
- activemq-artemis - Artemis - 如何避免非事务会话的 TransactionRolledBackException
- html - 一旦达到指定的行数,如何使表自动开始新列
- go - Google 的 logadmin 中的条目迭代器从不返回 iterator.Done
- snowflake-cloud-data-platform - Snowflake 中的 COUNT(*) 与 COUNT(column) 性能
- jquery - jQuery自动完成 - 修改所选选项的值
- python - Python Django 表单提交按钮无法按预期工作
- r - 如果我知道 R 中的解和其他参数,如何求解交叉距离函数中的参数?
- node.js - 发布请求中的 req.body.rid 是什么意思?
- nestjs - 将 MongooseModule 添加到 AuthModule 后无法找出嵌套错误