kbry
kbry

Reputation: 133

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.

I am using Terratest to test some Terraform code, and we manage the state remotely in s3. During Terratest i want to use local state but during the "terraform init" state it can'nt find a way to override it.

any help will be appreciated

Upvotes: 1

Views: 1792

Answers (1)

StephenG
StephenG

Reputation: 2881

Terraform allows for command line options to control backend configuration. Since you're using Terratest, you'll have to pass these backend options to 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...)
}

Upvotes: 2

Related Questions