Skip to content

Commit

Permalink
Merge pull request #202 from banzaicloud/terraform-init-backend-config
Browse files Browse the repository at this point in the history
Terraform init backend config
  • Loading branch information
sagikazarmark authored Feb 19, 2020
2 parents 8cd1775 + 6969f97 commit c4ecbb4
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/build/
/dist/
/vendor/
/tmp/
.DS_Store

# packr files https://github.com/gobuffalo/packr/tree/master/v2
Expand Down
4 changes: 4 additions & 0 deletions internal/cli/command/controlplane/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ func runTerraform(command string, options *cpContext, env map[string]string, tar
}
} else {
cmd = append(cmd, "-input=false", "-force-copy")

if fileExists(filepath.Join(options.workspace, "state.tfvars")) {
cmd = append(cmd, "-backend-config", "/workspace/state.tfvars")
}
}

return runTerraformCommandGeneric(options, cmd, cmdEnv)
Expand Down
26 changes: 26 additions & 0 deletions internal/cli/command/controlplane/utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright © 2020 Banzai Cloud
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package controlplane

import "os"

func fileExists(filename string) bool {
info, err := os.Stat(filename)
if os.IsNotExist(err) {
return false
}

return !info.IsDir()
}

0 comments on commit c4ecbb4

Please sign in to comment.