如何将 `ApplyConfig` 传递给 `hashicorp / terraform-exec` 中的 `tf.Apply()`?
Feb 09, 2024 am 10:50 AMphp小编柚子为您解答如何将 `ApplyConfig` 传递给 `hashicorp / terraform-exec` 中的 `tf.Apply()`。在使用 `hashicorp / terraform-exec` 进行 Terraform 部署时,可以通过创建一个 `ApplyConfig` 对象来配置 `tf.Apply()` 的行为。然后,将该对象传递给 `tf.Apply()` 方法,以便进行相应的部署操作。通过这种方式,您可以灵活地控制部署过程,并实现自定义的配置需求。在实际应用中,您可以根据具体的业务需求来设置 `ApplyConfig` 对象的属性,以达到最佳的部署效果。
问题内容
我正在尝试使用 golang sdk 在 hashicorp/terraform-exec 中使用 golang sdk 将目标添加到 terraform apply 命令中
理想情况下,cli 的等效命令是 terraform apply --auto-approve --target 'module.example'
但是,当我将 applyoptions{}
中的 targets
传递给 apply()
函数时,出现以下错误。
有人能指出我在这里做什么吗?
package main import ( "context" "github.com/hashicorp/terraform-exec/tfexec" ) func main() { // create a new tfexec.executor instance tf, err := tfexec.newterraform("/path/to/terraform/binary") if err != nil { panic(err) } err = tf.init(context.background(), tfexec.upgrade(true)) if err != nil { panic(err) } // define the targets you want to apply targets := []string{"module.example", "module.another_example"} // create an applyoption with the targets applyoption := tfexec.applyoption{ targets: targets, } // apply the terraform configuration with the defined targets err = tf.apply(context.background(), applyoption) if err != nil { panic(err) } }
登录后复制
错误显示,invalid 复合文字类型 tfexec.applyoptioncompiler
go run test.go # command-line-arguments ./test.go:23:17: invalid composite literal type tfexec.ApplyOption
登录后复制
解决方法
我认为以下应该有效:
targets := []tfexec.ApplyOption{ tfexec.Target("module.example"), tfexec.Target("module.another_example"), } // Apply the Terraform configuration with the defined targets err = tf.Apply(context.Background(), targets...) if err != nil { panic(err) }
登录后复制
以上是如何将 `ApplyConfig` 传递给 `hashicorp / terraform-exec` 中的 `tf.Apply()`?的详细内容。更多信息请关注PHP中文网其他相关文章!
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热门文章
击败分裂小说需要多长时间?
3 周前
By DDD
仓库:如何复兴队友
3 周前
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒险:如何获得巨型种子
3 周前
By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.能量晶体解释及其做什么(黄色晶体)
1 周前
By 尊渡假赌尊渡假赌尊渡假赌
公众号网页更新缓存难题:如何避免版本更新后旧缓存影响用户体验?
3 周前
By 王林

热门文章
击败分裂小说需要多长时间?
3 周前
By DDD
仓库:如何复兴队友
3 周前
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒险:如何获得巨型种子
3 周前
By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.能量晶体解释及其做什么(黄色晶体)
1 周前
By 尊渡假赌尊渡假赌尊渡假赌
公众号网页更新缓存难题:如何避免版本更新后旧缓存影响用户体验?
3 周前
By 王林

热门文章标签

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)