为什么Terraform要再次创建自定义属性?

为什么Terraform要再次创建自定义属性?,terraform,vmware,vsphere,Terraform,Vmware,Vsphere,我正在尝试使用Vsphere_自定义_属性资源。在VSphere上第一次运行时,它运行良好,但在第二次运行时,我得到以下错误 你有什么办法解决这个问题吗? 还是我用错了 我使用这个版本的Terraform和Vsphere provider 地形v0.12.12 provider.template v2.1.2 provider.vsphere v1.13.0 这些是我创建自定义属性和使用自定义属性的代码部分 resource "vsphere_custom_attribute" "hostn

我正在尝试使用Vsphere_自定义_属性资源。在VSphere上第一次运行时,它运行良好,但在第二次运行时,我得到以下错误

你有什么办法解决这个问题吗? 还是我用错了

我使用这个版本的Terraform和Vsphere provider

地形v0.12.12

  • provider.template v2.1.2
  • provider.vsphere v1.13.0
这些是我创建自定义属性和使用自定义属性的代码部分

resource "vsphere_custom_attribute" "hostname" {
  name                = "hypervisor.hostname"
  managed_object_type = "VirtualMachine"
}

resource "vsphere_virtual_machine" "vm" {
  ...
  custom_attributes = "${map(vsphere_custom_attribute.hostname.id, "${var.vsphere_name}${var.vsphere_dom}" )}"
  ...
}
错误:

Error: could not create custom attribute: ServerFaultCode: The name 'hypervisor.hostname' already exists.

  on main.tf line 32, in resource "vsphere_custom_attribute" "hostname":
  32: resource "vsphere_custom_attribute" "hostname" {
地形平面图:

我不明白Terraform为什么要创建自定义属性,因为它已经存在

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # vsphere_custom_attribute.hostname will be created
  + resource "vsphere_custom_attribute" "hostname" {
      + id                  = (known after apply)
      + managed_object_type = "VirtualMachine"
      + name                = "hypervisor.hostname"
    }

这是因为您说的是创建“资源”,而不是从vsphere中提取“数据”。在理解所需的“vsphere_数据存储”输入之前,我也有这种困惑

尝试类似的方法(im使用octopus deploy进行变量替换,所以忽略im使用的无效#{,应该是${或0.12.x的直字符串)

...
data "vsphere_custom_attribute" "consul_backend_path" {
  name = "consul.backend.path"
}
...
resource "vsphere_virtual_machine" "windows_virtual_machine" {
...
custom_attributes = map(data.vsphere_custom_attribute.consul_backend_path.id, "custom_attribute_value")
...
}

请记住,这要求在创建此虚拟机资源之前,自定义属性的资源必须在vcenter中。否则,您将需要执行逻辑测试以验证是否需要标记。

在运行之间状态文件是否发生任何变化?可能,请将
aws
的资源与
terraform的资源取消匹配。tfstate