terraform自定义提供程序差异不适用于SetType

时间:2018-06-21 07:14:49

标签: terraform

我正在为terraform开发自定义提供程序,并且遇到类型schema.TypeSet的资源配置参数时遇到了麻烦。当我仅更改集合terraform plan中的参数时,现在与已部署版本的差异。当我添加另一个设置条目时,还会显示现有设置条目中的更改。

我的架构定义如下:

"variable": &schema.Schema{
  Type:     schema.TypeSet,
  Required: true,
  Elem: &schema.Resource{
    Schema: map[string]*schema.Schema{
      "type": {
        Type: schema.TypeString,
      },
      "name": {
        Type: schema.TypeString,
      },
      ...
    },
  },
  Set: func(v interface{}) int {
    m := v.(map[string]interface{})
    return hashcode.String(m["name"].(string))
  },
}

我的读取功能(据我所知,该功能将已部署的配置作为diff的输入返回)执行以下操作:

func resourceAspectTypeRead(d *schema.ResourceData, 
                            meta interface{}) error {
  ...
  result := restcall()

  var variablesData []map[string]interface{}
  for _, variable := range result.Payload.Variables {
    variableData := map[string]interface{}{
        "type":         *variable.Type,
        "name":         *variable.Name,
        ...
    }
    variablesData = append(variablesData, variableData)
  }
  d.Set("variable", &variablesData)

  return nil
}

我的main.tf大致具有以下内容:

resource "platform_type" "my-type" {
  ...
  variable {
    name ="temperature"
    # Changed from "STRING" to "DOUBLE"
    type = "DOUBLE"
  }
}

运行terraform plan时,我得到以下输出:

$ terraform plan -out=terraform.tfplan
Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but will not be
persisted to local or remote state storage.

platform_type.my-type: Refreshing state... (ID: XYZ)
------------------------------------------------------------------------
No changes. Infrastructure is up-to-date.
This means that Terraform did not detect any differences between your
configuration and real physical resources that exist. As a result, no
actions need to be performed.

我想我在读取函数中弄乱了一些东西,但我不知道有什么不同。t

0 个答案:

没有答案
相关问题