如何从 Terratest Go 脚本调用 Terragrunt HCL 文件?

How to call Terragrunt HCL files from Terratest Go script?

我有一个 terragrunt 脚本,在 运行 terragrunt apply-all 命令行后工作正常,但同样的事情我 无法 do/invoke 形成 Go 脚本。 使用 TgApplyAll 函数

下面是我的 Go 脚本 工作的 terragrunt 脚本保存在 D:\vertica-terragrunt-US-286094-Modules\with-infra 位置,它与手动 terragrunt apply-all 命令一起工作正常但是从 Go 脚本我得到错误

报错如下

''' github.com/gruntwork-io/terratest/modules/terraform.TgInvalidBinary.Error(...) c:/go/pkg/mod/github.com/gruntwork-io/terratest@v0.30.15/modules/terraform/errors.go:12

详细错误 func (err TgInvalidBinary) Error() 字符串 { return fmt.Sprintf(“必须将 terragrunt 设置为 TerraformBinary 才能使用此函数。[TerraformBinary:%s]”,错误) } '''

我使用了与从 terratest Go 脚本调用 terraform 代码相同的代码来调用 terragrunt 代码,但它不起作用

任何人都可以帮助我/指导我如何从 terratest Go 脚本调用工作 terragrunt 代码这样的位置吗?

您好,您需要在 terraform 选项中将 TerraformBinary 设置为 terragrunt,如下所示:

terraformOptions := &terraform.Options{

    TerraformDir: "D:/vertica-terragrunt-US-286094-Modules/with-infra",
    TerraformBinary : "terragrunt",
}

因为默认二进制文件是 terraform,当调用 terragrunt 函数并且 TerraformBinary 设置为 terragrunt 以外的值时会发生 TgInvalidBinary。

这是参考

https://godoc.org/github.com/gruntwork-io/terratest/modules/terraform#TgInvalidBinary

https://github.com/gruntwork-io/terratest/blob/master/modules/terraform/cmd.go