Skip to content

Commit

Permalink
Changed behaviour when file is not present.
Browse files Browse the repository at this point in the history
  • Loading branch information
ColOfAbRiX committed Jan 18, 2018
1 parent aef2b70 commit 1c383e9
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions remote/terraform_state_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,15 @@ func (state *TerraformState) IsRemote() bool {
return state.Backend != nil && state.Backend.Type != "local"
}

// 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.
// Parses the Terraform .tfstate file. If a local backend is used then search the given path, or
// return nil if the file is missing. If the backend is not local then 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.
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) {
return ParseTerraformStateFile(stateFile)
}
}
if util.FileExists(util.JoinPath(workingDir, DEFAULT_PATH_TO_LOCAL_STATE_FILE)) {
if backend == "local" && ok && util.FileExists(stateFile) {
return ParseTerraformStateFile(stateFile)
} else if util.FileExists(util.JoinPath(workingDir, DEFAULT_PATH_TO_LOCAL_STATE_FILE)) {
return ParseTerraformStateFile(util.JoinPath(workingDir, DEFAULT_PATH_TO_LOCAL_STATE_FILE))
} else if util.FileExists(util.JoinPath(workingDir, DEFAULT_PATH_TO_REMOTE_STATE_FILE)) {
return ParseTerraformStateFile(util.JoinPath(workingDir, DEFAULT_PATH_TO_REMOTE_STATE_FILE))
Expand Down

0 comments on commit 1c383e9

Please sign in to comment.