Skip to content
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

Merged
merged 2 commits into from
Jan 19, 2018

Conversation

ColOfAbRiX
Copy link
Contributor

@ColOfAbRiX ColOfAbRiX commented Jan 17, 2018

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.

Copy link
Member

@brikis98 brikis98 left a 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?

@@ -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.
Copy link
Member

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

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) {
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

@ColOfAbRiX ColOfAbRiX left a 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]

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) {
Copy link
Contributor Author

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.

Copy link
Member

@brikis98 brikis98 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you!

@brikis98 brikis98 merged commit 9ee518b into gruntwork-io:master Jan 19, 2018
@brikis98
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants