github.com/databricks/cli@v0.203.0/bundle/deploy/terraform/apply.go (about) 1 package terraform 2 3 import ( 4 "context" 5 "fmt" 6 7 "github.com/databricks/cli/bundle" 8 "github.com/databricks/cli/libs/cmdio" 9 "github.com/hashicorp/terraform-exec/tfexec" 10 ) 11 12 type apply struct{} 13 14 func (w *apply) Name() string { 15 return "terraform.Apply" 16 } 17 18 func (w *apply) Apply(ctx context.Context, b *bundle.Bundle) error { 19 tf := b.Terraform 20 if tf == nil { 21 return fmt.Errorf("terraform not initialized") 22 } 23 24 cmdio.LogString(ctx, "Starting resource deployment") 25 26 err := tf.Init(ctx, tfexec.Upgrade(true)) 27 if err != nil { 28 return fmt.Errorf("terraform init: %w", err) 29 } 30 31 err = tf.Apply(ctx) 32 if err != nil { 33 return fmt.Errorf("terraform apply: %w", err) 34 } 35 36 cmdio.LogString(ctx, "Resource deployment completed!") 37 return nil 38 } 39 40 // Apply returns a [bundle.Mutator] that runs the equivalent of `terraform apply` 41 // from the bundle's ephemeral working directory for Terraform. 42 func Apply() bundle.Mutator { 43 return &apply{} 44 }