mirror of https://github.com/databricks/cli.git
Fix summary command when internal terraform config doesn't exist (#1242)
Check if `bundle.tf.json` doesn't exist and create it before executing `terraform init` (inside `terraform.Load`) Fixes a problem when during `terraform.Load` it fails with: ``` Error: Failed to load plugin schemas Error while loading schemas for plugin components: Failed to obtain provider schema: Could not load the schema for provider registry.terraform.io/databricks/databricks: failed to instantiate provider "registry.terraform.io/databricks/databricks" to obtain schema: unavailable provider "registry.terraform.io/databricks/databricks".. ```
This commit is contained in:
parent
0839e6f66a
commit
d12f88e24d
|
@ -1,3 +1,4 @@
|
|||
package terraform
|
||||
|
||||
const TerraformStateFileName = "terraform.tfstate"
|
||||
const TerraformConfigFileName = "bundle.tf.json"
|
||||
|
|
|
@ -32,7 +32,7 @@ func (w *write) Apply(ctx context.Context, b *bundle.Bundle) error {
|
|||
return err
|
||||
}
|
||||
|
||||
f, err := os.Create(filepath.Join(dir, "bundle.tf.json"))
|
||||
f, err := os.Create(filepath.Join(dir, TerraformConfigFileName))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -42,11 +42,16 @@ func newSummaryCommand() *cobra.Command {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = os.Stat(filepath.Join(cacheDir, terraform.TerraformStateFileName))
|
||||
noCache := errors.Is(err, os.ErrNotExist)
|
||||
_, stateFileErr := os.Stat(filepath.Join(cacheDir, terraform.TerraformStateFileName))
|
||||
_, configFileErr := os.Stat(filepath.Join(cacheDir, terraform.TerraformConfigFileName))
|
||||
noCache := errors.Is(stateFileErr, os.ErrNotExist) || errors.Is(configFileErr, os.ErrNotExist)
|
||||
|
||||
if forcePull || noCache {
|
||||
err = bundle.Apply(cmd.Context(), b, terraform.StatePull())
|
||||
err = bundle.Apply(cmd.Context(), b, bundle.Seq(
|
||||
terraform.StatePull(),
|
||||
terraform.Interpolate(),
|
||||
terraform.Write(),
|
||||
))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue