一个Terraform问题所想到的

有位朋友找我帮忙, 说是他的同事卡了一个问题很久。然后发了一些信息给我, 让我帮忙。

 

用到的module: https://github.com/dsieczko/vmware-on-equinix-metal

Error: Invalid function argument: Invalid value for "path" parameter: no file exists at /root/.ssh/id-rsa; this function works only with files that are distr ibuted as part of the configuration source code, so if this file will be created by a resource in this configuration you must instead obtain this result from an attribute of that resource.

还有一个

Error: Error reserving IP address block: POST https://api.equinix.com/metal/v1/projects/XXXX/ips: 502 Unexpected Content-Typ e text/html with status 502 Bad Gateway

on main.tf line 6, in resource "packet_reserved_ip_block" "esx_ip_blocks":
6: resource "packet_reserved_ip_block" "esx_ip_blocks" {

 

我可以理解,他们不太好发太多的代码给我去debug, 毕竟是不同的公司。这设计到代码的机密性问题。

 

那好吧,我们来推测一下问题吧。

先找个简单的, 502  Server 端的出错。  这种 5XX的做错, 就是说请求已经成功发给我 Server (Terraform 通过把.tf 文件跟驱动, 解释称一堆API去对应的云厂商或者本地虚拟化接口去做基础设施的搭建), 而 Server端没发处理成功。从字面上看很像是ip地址池资源不够。直接让他扩大池子。

 

第二个,这是什么鬼?只能是从错误本身去出发, 寻找里边对应的关键字。看到对应github上边有一个参数跟这个出错很接近 ssh_private_key_path, 从代码里边在找一下是怎么使用到的。找到类似这样的代码块

 

resource "null_resource" "copy_vcva_template" {
  connection {
    type        = "ssh"
    user        = "root"
    private_key = file(var.ssh_private_key_path)
    host        = packet_device.router.access_public_ipv4
  }
  provisioner "file" {
    content     = data.template_file.vcva_template.rendered
    destination = "/root/vcva_template.json"
  }
}

那好吧, 我倒要模拟一下是什么样的状况会触发这种错误。

本地模拟一下这样的文件, 对它进行修改。发现即使是格式的错误,也不会是那种错误信息。只有当文件确实是不存在的话才是一模一样的错误。然后我就看一下文件名, 是id-rsa。  对比了我本地的文件。我靠, 我本地的是id_rsa。 然后我非常大胆地推出就是因为这样的typo造成的。

 

写这个随笔主要是觉得,当我们看到一个复杂问题的时候, 最好是可以通过最直接简单的方法去重现。然后不断对这个简单切入点进行修改。证明它的可行,对应的复杂问题也就迎刃而解了。

 

posted @ 2021-12-12 00:14  DonotRegret  阅读(50)  评论(0编辑  收藏  举报