如何将更改反向传播到父节点?

时间:2019-05-03 11:40:08

标签: 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”之前,我希望实例被销毁并重新创建。

0 个答案:

没有答案