-
-
Notifications
You must be signed in to change notification settings - Fork 981
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix of issue #402: load given state file when specified. #403
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR!
Could you paste the output of running the tests?
remote/terraform_state_file.go
Outdated
@@ -46,7 +46,13 @@ func (state *TerraformState) IsRemote() bool { | |||
|
|||
// Parse the Terraform .tfstate file from the location specified by workingDir. If no location is specified, | |||
// search the current directory. If the file doesn't exist at any of the default locations, return nil. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make sure to update this comment
remote/terraform_state_file.go
Outdated
func ParseTerraformStateFileFromLocation(backend string, config map[string]interface{}, workingDir string) (*TerraformState, error) { | ||
stateFile, ok := config["path"].(string) | ||
if backend == "local" && ok { | ||
if util.FileExists(stateFile) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, not sure what the right behavior is here if the file doesn't exist. Should we just try to read it elsewhere? Return an empty TerraformState
? Return an error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, falling back to original behaviour is not right. I think we should return nil, like in the other cases, so terragrunt carries on and the file gets created.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here you are:
$ go test -parallel 128 $(glide novendor)
ok github.com/gruntwork-io/terragrunt/remote 0.005s
ok github.com/gruntwork-io/terragrunt/shell 6.526s
ok github.com/gruntwork-io/terragrunt/config 0.008s
ok github.com/gruntwork-io/terragrunt/cli 13.238s
? github.com/gruntwork-io/terragrunt/aws_helper [no test files]
ok github.com/gruntwork-io/terragrunt/dynamodb 22.146s
? github.com/gruntwork-io/terragrunt/options [no test files]
ok github.com/gruntwork-io/terragrunt/util 0.008s
ok github.com/gruntwork-io/terragrunt/test 306.521s
? github.com/gruntwork-io/terragrunt/test/helpers [no test files]
? github.com/gruntwork-io/terragrunt/errors [no test files]
ok github.com/gruntwork-io/terragrunt/configstack 0.010s
? github.com/gruntwork-io/terragrunt [no test files]
remote/terraform_state_file.go
Outdated
func ParseTerraformStateFileFromLocation(backend string, config map[string]interface{}, workingDir string) (*TerraformState, error) { | ||
stateFile, ok := config["path"].(string) | ||
if backend == "local" && ok { | ||
if util.FileExists(stateFile) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, falling back to original behaviour is not right. I think we should return nil, like in the other cases, so terragrunt carries on and the file gets created.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thank you!
If the build passes, the new binaries should be here in a few minutes: https://github.com/gruntwork-io/terragrunt/releases/tag/v0.13.25 |
This is a bugfix for "Getting json.SyntaxError unexpected end of JSON input" Issue #402
When using a local backend and a path is given, terragrunt should load that file instead of looking in the default working directory.
As a Go beginner, feel free to suggest any correction or semantic mistake.