Skip to content

Commit f57370f

Browse files
committed
feat: Terraform version detected from project config
old projects are backward compatible
1 parent 975e4d5 commit f57370f

4 files changed

Lines changed: 19 additions & 2 deletions

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
.idea
22
src/build/
3+
src/build*/
34
config.tf
45
environment.tf
56
.env
6-
bin
7+
bin

src/command_backend.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bytes"
55
"gopkg.in/alecthomas/kingpin.v2"
66
"path/filepath"
7+
"strconv"
78
"strings"
89
"text/template"
910
)
@@ -36,6 +37,7 @@ type BackendConfig struct {
3637
TerraformStateKey string
3738
TerraformLockTable string
3839
KmsKeyArn string
40+
TerraformVersion int
3941
}
4042

4143
type dotEnv struct {
@@ -161,6 +163,10 @@ func (c *BackendCommand) applyInvoker(config *BackendConfig) {
161163
c.log.ShowOpts("Invoker", "enabled")
162164
config.TerraformStateKey = strings.Join([]string{config.TerraformStateKey, defaultTerraformInvokerSuffix}, "-")
163165
}
166+
167+
if config.TerraformVersion >= 2 {
168+
config.TerraformStateKey = config.TerraformStateKey + "/v" + strconv.Itoa(config.TerraformVersion)
169+
}
164170
}
165171

166172
func (c *BackendCommand) dotEnvMapper(env *dotEnv) *BackendConfig {
@@ -172,6 +178,7 @@ func (c *BackendCommand) dotEnvMapper(env *dotEnv) *BackendConfig {
172178
KmsKeyArn: env.environment["KMS_KEY_ARN"],
173179
TerraformStateKey: env.project["TERRAFORM_STATE_KEY"],
174180
Domain: env.project["DOMAIN"],
181+
TerraformVersion: c.app.IntResolver(env.project["TERRAFORM_VERSION"]),
175182
}
176183
}
177184

src/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package main
22

3-
const Version = "v0.5.0"
3+
const Version = "v0.5.1"
44

55
const CiEnvVar = "CI"
66
const EnvVersionVar = "TF_ENV_VERSION"

src/utils.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"github.com/joho/godotenv"
66
"os"
77
"path/filepath"
8+
"strconv"
89
"strings"
910
"text/template"
1011
)
@@ -125,6 +126,14 @@ func (a *App) BoolResolver(text string) bool {
125126
return false
126127
}
127128

129+
func (a *App) IntResolver(text string) int {
130+
if strings.EqualFold(text, "") || strings.EqualFold(text, "1") {
131+
return 1
132+
}
133+
intVar, _ := strconv.Atoi(text)
134+
return intVar
135+
}
136+
128137
func (a *App) isNewEnvVersion() bool {
129138
if strings.EqualFold(a.envVersion, "2") {
130139
return true

0 commit comments

Comments
 (0)