Skip to content

Commit

Permalink
Merge pull request gruntwork-io#401 from tamsky/enhance/pull/302
Browse files Browse the repository at this point in the history
Extend remote_state backend check to include *.tf.json files
  • Loading branch information
brikis98 authored Jan 11, 2018
2 parents f4fc5d8 + 0a2106a commit 4123182
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions cli/cli_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,12 +307,24 @@ func checkTerraformCodeDefinesBackend(terragruntOptions *options.TerragruntOptio
if err != nil {
return err
}
if definesBackend {
return nil
}

if !definesBackend {
return errors.WithStackTrace(BackendNotDefined{Opts: terragruntOptions, BackendType: backendType})
terraformJSONBackendRegexp, err := regexp.Compile(fmt.Sprintf(`(?m)"backend":[[:space:]]*{[[:space:]]*"%s"`, backendType))
if err != nil {
return errors.WithStackTrace(err)
}

return nil
definesJSONBackend, err := util.Grep(terraformJSONBackendRegexp, fmt.Sprintf("%s/**/*.tf.json", terragruntOptions.WorkingDir))
if err != nil {
return err
}
if definesJSONBackend {
return nil
}

return errors.WithStackTrace(BackendNotDefined{Opts: terragruntOptions, BackendType: backendType})
}

// Prepare for running any command other than 'terraform init' by
Expand Down

0 comments on commit 4123182

Please sign in to comment.