@@ -23,13 +23,7 @@ import (
2323 "golang.org/x/exp/maps"
2424)
2525
26- type initialize struct {}
27-
28- func (m * initialize ) Name () string {
29- return "terraform.Initialize"
30- }
31-
32- func (m * initialize ) findExecPath (ctx context.Context , b * bundle.Bundle , tf * config.Terraform , installer Installer ) (string , error ) {
26+ func findExecPath (ctx context.Context , b * bundle.Bundle , tf * config.Terraform , installer Installer ) (string , error ) {
3327 // If set, pass it through [exec.LookPath] to resolve its absolute path.
3428 if tf .ExecPath != "" {
3529 execPath , err := exec .LookPath (tf .ExecPath )
@@ -303,14 +297,14 @@ func getTerraformExec(ctx context.Context, b *bundle.Bundle, execPath string) (*
303297 return tfexec .NewTerraform (workingDir , execPath )
304298}
305299
306- func ( m * initialize ) Apply (ctx context.Context , b * bundle.Bundle ) diag.Diagnostics {
300+ func Initialize (ctx context.Context , b * bundle.Bundle ) diag.Diagnostics {
307301 tfConfig := b .Config .Bundle .Terraform
308302 if tfConfig == nil {
309303 tfConfig = & config.Terraform {}
310304 b .Config .Bundle .Terraform = tfConfig
311305 }
312306
313- execPath , err := m . findExecPath (ctx , b , tfConfig , tfInstaller {})
307+ execPath , err := findExecPath (ctx , b , tfConfig , tfInstaller {})
314308 if err != nil {
315309 return diag .FromErr (err )
316310 }
@@ -354,10 +348,12 @@ func (m *initialize) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnosti
354348 return diag .FromErr (err )
355349 }
356350
351+ err = tfe .Init (ctx , tfexec .Upgrade (true ))
352+ if err != nil {
353+ return diag .Errorf ("terraform init: %v" , err )
354+ }
355+
357356 b .Terraform = tfe
358- return nil
359- }
360357
361- func Initialize () bundle.Mutator {
362- return & initialize {}
358+ return nil
363359}
0 commit comments