github.com/databricks/cli@v0.203.0/bundle/deploy/terraform/write.go (about) 1 package terraform 2 3 import ( 4 "context" 5 "encoding/json" 6 "os" 7 "path/filepath" 8 9 "github.com/databricks/cli/bundle" 10 ) 11 12 type write struct{} 13 14 func (w *write) Name() string { 15 return "terraform.Write" 16 } 17 18 func (w *write) Apply(ctx context.Context, b *bundle.Bundle) error { 19 dir, err := Dir(b) 20 if err != nil { 21 return err 22 } 23 24 root := BundleToTerraform(&b.Config) 25 f, err := os.Create(filepath.Join(dir, "bundle.tf.json")) 26 if err != nil { 27 return err 28 } 29 30 defer f.Close() 31 32 enc := json.NewEncoder(f) 33 enc.SetIndent("", " ") 34 err = enc.Encode(root) 35 if err != nil { 36 return err 37 } 38 39 return nil 40 } 41 42 // Write returns a [bundle.Mutator] that converts resources in a bundle configuration 43 // to the equivalent Terraform JSON representation and writes the result to a file. 44 func Write() bundle.Mutator { 45 return &write{} 46 }