-
Notifications
You must be signed in to change notification settings - Fork 184
Add "bundle summary" command #1123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
8a53604
Add "bundle remote-state" command
ilia-db f0840f0
Replace config resources in the terraform.Load mutator
ilia-db 03d5d9b
Summarise command
ilia-db a2b90ea
Merge branch 'main' into remote-state
ilia-db e0e9306
Print json to stdout
ilia-db 58fa444
Rename to summary, mark new fields as internal
ilia-db 80d3a7d
Improve tests
ilia-db ccf3329
Explain ModifiedStatus enum
ilia-db d133130
Explicitly require json output
ilia-db b4054de
Remove early return to properly set created statuses
ilia-db File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| package bundle | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "errors" | ||
| "os" | ||
| "path/filepath" | ||
|
|
||
| "github.com/databricks/cli/bundle" | ||
| "github.com/databricks/cli/bundle/config" | ||
| "github.com/databricks/cli/bundle/deploy/terraform" | ||
| "github.com/databricks/cli/cmd/root" | ||
|
|
||
| "github.com/databricks/cli/bundle/phases" | ||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| func newRemoteStateCommand() *cobra.Command { | ||
| cmd := &cobra.Command{ | ||
| Use: "remote-state", | ||
| Short: "Pull and print deployed state of the bundle", | ||
|
andrewnester marked this conversation as resolved.
Outdated
|
||
|
|
||
| PreRunE: root.MustWorkspaceClient, | ||
|
|
||
| // This command is currently intended only for the Databricks VSCode extension | ||
| Hidden: true, | ||
| } | ||
|
|
||
| var forcePull bool | ||
| cmd.Flags().BoolVar(&forcePull, "force-pull", false, "Skip local cache and load the state from the remote workspace") | ||
|
|
||
| cmd.RunE = func(cmd *cobra.Command, args []string) error { | ||
|
ilia-db marked this conversation as resolved.
|
||
| b := bundle.Get(cmd.Context()) | ||
|
|
||
| err := bundle.Apply(cmd.Context(), b, phases.Initialize()) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| cacheDir, err := terraform.Dir(cmd.Context(), b) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| _, err = os.Stat(filepath.Join(cacheDir, terraform.TerraformStateFileName)) | ||
| noCache := errors.Is(err, os.ErrNotExist) | ||
|
|
||
| if forcePull || noCache { | ||
| err = bundle.Apply(cmd.Context(), b, terraform.StatePull()) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| } | ||
|
|
||
| // After the initialization phase the local bundle configuration is no longer necessary. | ||
| // We want to populate the config with the remote state only. | ||
| b.Config.Resources = config.Resources{} | ||
|
|
||
| err = bundle.Apply(cmd.Context(), b, terraform.Load()) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| buf, err := json.MarshalIndent(b.Config, "", " ") | ||
|
ilia-db marked this conversation as resolved.
Outdated
|
||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| cmd.OutOrStdout().Write(buf) | ||
|
ilia-db marked this conversation as resolved.
Outdated
|
||
| return nil | ||
| } | ||
|
|
||
| return cmd | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.