【问题标题】:Cannot taint null_resource不能污染 null_resource
【发布时间】:2020-07-28 18:07:07
【问题描述】:

我得到了 terraform 0.11.11。 图中显示说话的资源在根模块中

$ terraform graph
digraph {
        compound = "true"
        newrank = "true"
        subgraph "root" {
                "[root] data.template_file.default" [label = "data.template_file.default", shape = "box"]
                "[root] data.template_file.etcd" [label = 
...
                "[root] null_resource.service_resolv_conf" [label = "null_resource.service_resolv_conf", shape = "box"]
...

但试图玷污它说它不是:

$ terraform taint null_resource.service_resolv_conf
The resource null_resource.service_resolv_conf couldn't be found in the module root.

更新

$ terraform state list|grep resolv_conf 
null_resource.service_resolv_conf[0] 
null_resource.service_resolv_conf[1] 

然后我尝试了:

$ terraform taint null_resource.service_resolv_conf[0] 

The resource null_resource.service_resolv_conf[0] couldn't be found in the module root. 

$ terraform taint null_resource.service_resolv_conf 
The resource null_resource.service_resolv_conf couldn't be found in the module root.

【问题讨论】:

  • 如果代码在模块中,请尝试' terraform taint -module=name null_resource.name
  • @victorm 这个 ^ 是正确的答案。非常感谢!

标签: terraform


【解决方案1】:

terraform graph 让您全面了解资源及其关系。

但这不是一个很好的故障排除命令和了解资源在 terraform *.tfstate 文件中的命名方式。

我建议使用terraform state list 运行,然后您可以轻松知道如何污染列表中的资源之一。

terraform state list
terraform taint <copy resource directly from above list>

【讨论】:

  • 好的,我试过了,但它仍然说它不在根模块中,尽管它是... $ terraform state list|grep resolv_conf null_resource.service_resolv_conf[0] null_resource.service_resolv_conf[1] 然后我尝试:$ terraform taint null_resource.service_resolv_conf[0] The resource null_resource.service_resolv_conf[0] couldn't be found in the module root.$ terraform taint null_resource.service_resolv_conf The resource null_resource.service_resolv_conf couldn't be found in the module root. 两种情况都相同;
  • 我注意到,如果我在资源中没有“计数”,那么它可以工作。
【解决方案2】:

对于进入此线程寻找 terraform taint/untaint null_resource 的任何人,其中 terraform 出现 The resource […] couldn't be found in the module root 错误,这是@victor-m 在Cannot taint null_resource 发布的正确且有效的答案

terraform taint -module=name null_resource.name

untaint 命令也一样。

【讨论】:

    【解决方案3】:

    毕竟我找到了解决办法

    出现了,那么当有更多主机基于列表连接时(使用'count')

    resource "null_resource" "provision_docker_registry" {
      count      = "${length(local.service_vms_names)}"
      depends_on = ["null_resource.service_resolv_conf"]
    
      connection {
        user        = "cloud-user"
        private_key = "${file("${path.module}/../ssh/${var.os_keypair}.pem")}"
        host        = "${element(local.service_fip, count.index)}"
      }
    

    您通过在点后指定索引来污染资源,即

    $ terraform taint null_resource.provision_docker_registry.0
    The resource null_resource.provision_docker_registry.0 in the module root has been marked as tainted!
    

    瞧!

    我无法在文档中找到它。希望这对某人有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-08
      • 2019-12-22
      • 1970-01-01
      • 1970-01-01
      • 2016-02-10
      • 1970-01-01
      相关资源
      最近更新 更多