0
0
mirror of https://github.com/thegeeklab/wp-opentofu.git synced 2024-11-21 04:10:39 +00:00

feat: add init options backend and lockfile (#76)

This commit is contained in:
Robert Kaussow 2024-08-08 08:57:36 +02:00 committed by GitHub
parent c88ab40fcd
commit 3dc0a87342
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -23,9 +23,11 @@ type Tofu struct {
// InitOptions include options for the OpenTofu init command. // InitOptions include options for the OpenTofu init command.
type InitOptions struct { type InitOptions struct {
Backend *bool `json:"backend"`
BackendConfig []string `json:"backend-config"` BackendConfig []string `json:"backend-config"`
Lock *bool `json:"lock"` Lock *bool `json:"lock"`
LockTimeout string `json:"lock-timeout"` LockTimeout string `json:"lock-timeout"`
Lockfile string `json:"lockfile"`
} }
// FmtOptions fmt options for the OpenTofu fmt command. // FmtOptions fmt options for the OpenTofu fmt command.
@ -52,10 +54,26 @@ func (t *Tofu) Init() *plugin_exec.Cmd {
"init", "init",
} }
if t.InitOptions.Backend != nil {
args = append(args, fmt.Sprintf("-backend=%t", *t.InitOptions.Backend))
}
for _, v := range t.InitOptions.BackendConfig { for _, v := range t.InitOptions.BackendConfig {
args = append(args, fmt.Sprintf("-backend-config=%s", v)) args = append(args, fmt.Sprintf("-backend-config=%s", v))
} }
if t.InitOptions.Lock != nil {
args = append(args, fmt.Sprintf("-lock=%t", *t.InitOptions.Lock))
}
if t.InitOptions.Lockfile != "" {
args = append(args, fmt.Sprintf("-lockfile=%s", t.InitOptions.Lockfile))
}
if t.InitOptions.LockTimeout != "" {
args = append(args, fmt.Sprintf("-lock-timeout=%s", t.InitOptions.LockTimeout))
}
// Fail tofu execution on prompt // Fail tofu execution on prompt
args = append(args, "-input=false") args = append(args, "-input=false")