Skip to content

Commit 5f7e41e

Browse files
authored
Merge pull request #32 from gruntwork-io/terraform-0_9
Replace terraform remote config with terraform init for Terraform 0.9.
2 parents 7f2c072 + 49a5783 commit 5f7e41e

File tree

4 files changed

+8
-9
lines changed

4 files changed

+8
-9
lines changed

apply.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func Apply(options *TerratestOptions) (string, error) {
2121
return output, fmt.Errorf("Test failed because the S3 Bucket '%s' does not exist in the '%s' region.\n", options.TfRemoteStateS3BucketName, options.TfRemoteStateS3BucketRegion)
2222
}
2323

24-
terraform.ConfigureRemoteState(options.TemplatePath, options.TfRemoteStateS3BucketName, options.GetTfStateFileName(), options.TfRemoteStateS3BucketRegion, logger)
24+
terraform.Init(options.TemplatePath, logger)
2525

2626
// TERRAFORM APPLY
2727
// Download all the Terraform modules

terraform/apply.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ var terraformDebugEnv = map[string]string{}
2222

2323
// Call Terraform Apply on the template at "templatePath" with the given "vars"
2424
func Apply(templatePath string, vars map[string]interface{}, logger *log.Logger) error {
25-
return shell.RunCommand(shell.Command { Command: "terraform", Args: FormatArgs(vars, "apply", "-input=false"), WorkingDir: templatePath, Env: terraformDebugEnv }, logger)
25+
return shell.RunCommand(shell.Command { Command: "terraform", Args: FormatArgs(vars, "apply", "-input=false", "-lock=false"), WorkingDir: templatePath, Env: terraformDebugEnv }, logger)
2626
}
2727

2828
// Call Terraform Apply on the template at "templatePath" with the given "vars", and return the output as a string
2929
func ApplyAndGetOutput(terraformPath string, vars map[string]interface{}, logger *log.Logger) (string, error) {
3030
logger.Println("Applying Terraform templates in folder", terraformPath)
31-
return shell.RunCommandAndGetOutput( shell.Command { Command: "terraform", Args: FormatArgs(vars, "apply", "-input=false"), WorkingDir: terraformPath, Env: terraformDebugEnv }, logger)
31+
return shell.RunCommandAndGetOutput( shell.Command { Command: "terraform", Args: FormatArgs(vars, "apply", "-input=false", "-lock=false"), WorkingDir: terraformPath, Env: terraformDebugEnv }, logger)
3232
}
3333

3434
// Regrettably Terraform has many bugs. Often, just re-running terraform apply will resolve the issue.

terraform/destroy.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ import (
1010
// Call Terraform Destroy on the template at "templatePath" with the given "vars"
1111
func Destroy(templatePath string, vars map[string]interface{}, logger *log.Logger) error {
1212
logger.Println("Destroy Terraform changes in folder", templatePath)
13-
return shell.RunCommand(shell.Command { Command: "terraform", Args: FormatArgs(vars, "destroy", "-force", "-input=false"), WorkingDir: templatePath, Env: terraformDebugEnv }, logger)
13+
return shell.RunCommand(shell.Command { Command: "terraform", Args: FormatArgs(vars, "destroy", "-force", "-input=false", "-lock=false"), WorkingDir: templatePath, Env: terraformDebugEnv }, logger)
1414
}
1515

1616
// Call Terraform Destroy on the template at "templatePath" with the given "vars", and return the output as a string
1717
func DestroyAndGetOutput(templatePath string, vars map[string]interface{}, logger *log.Logger) (string, error) {
1818
logger.Println("Destroy Terraform changes in folder", templatePath)
19-
return shell.RunCommandAndGetOutput(shell.Command { Command: "terraform", Args: FormatArgs(vars, "destroy", "-force", "-input=false"), WorkingDir: templatePath, Env: terraformDebugEnv }, logger)
19+
return shell.RunCommandAndGetOutput(shell.Command { Command: "terraform", Args: FormatArgs(vars, "destroy", "-force", "-input=false", "-lock=false"), WorkingDir: templatePath, Env: terraformDebugEnv }, logger)
2020
}

terraform/init.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ import (
88
"github.com/gruntwork-io/terratest/shell"
99
)
1010

11-
func ConfigureRemoteState(templatePath string, s3BucketName string, tfStateFileName string, awsRegion string, logger *log.Logger) error {
12-
logger.Println("Setting up Terraform remote state storage in S3 bucket", s3BucketName, "with tfstate file name", tfStateFileName, "for folder", templatePath)
13-
args := []string{"remote", "config", "-backend=s3", "-backend-config=bucket=" + s3BucketName, "-backend-config=key=" + tfStateFileName, "-backend-config=encrypt=true", "-backend-config=region=" + awsRegion}
11+
func Init(templatePath string, logger *log.Logger) error {
12+
logger.Println("Running terraform init")
13+
args := []string{"init"}
1414
return shell.RunCommand(shell.Command{ Command: "terraform", Args: args, WorkingDir: templatePath, Env: terraformDebugEnv }, logger)
1515
}
16-

0 commit comments

Comments
 (0)