1

我试图弄清楚当 Resource.Schema 属性之一发生更改时是否可以阻止资源更新。

本质上,我正在构建一个管理基础设施的提供商。我有一个更新固件的资源。就像是:

resource "redfish_simple_update" "update" {
    transfer_protocol = "HTTP"
    target_firmware_image = "/home/mikeletux/BIOS_FXC54_WN64_1.15.0.EXE"
}

如您所见,target_firmware_image 确实指的是我的固件包的完整路径。我希望能够在不触发更新的情况下更改目录。例如,通过/home/mikeletux/Downloads/BIOS_FXC54_WN64_1.15.0.EXE更改target_firmware_image以上。

我不知道这是否可能。如果做了我自己的研究,我发现要添加到模式中的 CustomDiff 函数,但我认为这与我的场景不匹配。

你觉得我还能做些什么吗?

谢谢!

4

1 回答 1

0

只是在这里发布我最终是如何做到的。

为了避免在路径更改而不是文件名更改时触发更新,我发现DiffSuppressFunc函数在这里变得非常方便:

"target_firmware_image": {
        Type:     schema.TypeString,
        Required: true,
        Description: "Target firmware image used for firmware update on the redfish instance. " +
            "Make sure you place your firmware packages in the same folder as the module and set it as follows: \"${path.module}/BIOS_FXC54_WN64_1.15.0.EXE\"",
        // DiffSuppressFunc will allow moving fw packages through the filesystem without triggering an update if so.
        // At the moment it uses filename to see if they're the same. We need to strengthen that by somehow using hashing
        DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
            if filepath.Base(old) == filepath.Base(new) {
                return true
            }
            return false
        },
    }

通过使用 filepath.Base() 检查新旧值,我可以确定文件名是否相同,无论文件放在哪个路径中。

我想在未来通过实现文件散列来改进这种行为,所以即使文件名也无关紧要,但这是我将留给新版本的东西。

谢谢!

于 2021-04-22T09:22:38.087 回答