简体   繁体   English

如何在Terratest Terraform设置中覆盖远程状态

[英]How to override remote state in Terratest Terraform setup

I'm trying to understand how to override the Terraform backend ( in my case remote state ) and use local state when setting up Terratest Terraform test. 我试图了解如何在设置Terratest Terraform测试时覆盖Terraform后端(在我的情况下为remote状态)并使用本地状态。

I am using Terratest to test some Terraform code, and we manage the state remotely in s3. 我正在使用Terratest测试一些Terraform代码,我们在s3中远程管理状态。 During Terratest i want to use local state but during the "terraform init" state it can'nt find a way to override it. 在Terratest期间,我想使用本地状态,但是在“ terraform init”状态下,它找不到覆盖它的方法。

any help will be appreciated 任何帮助将不胜感激

Terraform allows for command line options to control backend configuration . Terraform允许使用命令行选项来控制后端配置 Since you're using Terratest, you'll have to pass these backend options to Init . 由于您使用的是Terratest,因此必须将这些后端选项传递给Init

package terraform

import (
    "fmt"
    "testing"
)

// InitE calls terraform init and return stdout/stderr.
func InitE(t *testing.T, options *Options) (string, error) {
    args := []string{"init", fmt.Sprintf("-upgrade=%t", options.Upgrade)}
    args = append(args, FormatTerraformBackendConfigAsArgs(options.BackendConfig)...)
    return RunTerraformCommandE(t, options, args...)
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM