Skip to content

Commit

Permalink
up: mount original tfstate for migrate (#224)
Browse files Browse the repository at this point in the history
Signed-off-by: Nandor Kracser <[email protected]>
  • Loading branch information
bonifaido authored Mar 30, 2020
1 parent 89c53bc commit f501798
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
6 changes: 6 additions & 0 deletions internal/cli/command/controlplane/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,9 @@ func runTerraformCommandGeneric(options *cpContext, cmd []string, cmdEnv map[str
"-v", fmt.Sprintf("%s:/terraform/state.tf.json", options.workspace+"/state.tf.json"),
"-v", fmt.Sprintf("%s:/terraform/.terraform/terraform.tfstate", options.workspace+"/.terraform/terraform.tfstate"),
}
if options.tfstateExists() {
args = append(args, "-v", fmt.Sprintf("%s:/terraform/terraform.tfstate", options.tfstatePath()))
}
if options.banzaiCli.Interactive() {
args = append(args, "-ti")
}
Expand All @@ -275,6 +278,9 @@ func runTerraformCommandGeneric(options *cpContext, cmd []string, cmdEnv map[str
"--mount", fmt.Sprintf("type=bind,src=%s,dst=/terraform/state.tf.json,options=rbind:rw", options.workspace+"/state.tf.json"),
"--mount", fmt.Sprintf("type=bind,src=%s,dst=/terraform/.terraform/terraform.tfstate,options=rbind:rw", options.workspace+"/.terraform/terraform.tfstate"),
}
if options.tfstateExists() {
args = append(args, "--mount", fmt.Sprintf("type=bind,src=%s,dst=/terraform/terraform.tfstate,options=rbind:rw", options.tfstatePath()))
}
if options.banzaiCli.Interactive() {
args = append(args, "-t")
}
Expand Down
5 changes: 5 additions & 0 deletions internal/cli/command/controlplane/installer_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,11 @@ func (c *cpContext) tfstatePath() string {
return filepath.Join(c.workspace, tfstateFilename)
}

func (c *cpContext) tfstateExists() bool {
_, err := os.Stat(c.tfstatePath())
return err == nil
}

func (c *cpContext) deleteTfstate() error {
_, err := os.Stat(c.tfstatePath())
if os.IsNotExist(err) {
Expand Down

0 comments on commit f501798

Please sign in to comment.