WIP new migration#5399
Draft
denik wants to merge 5 commits into
Draft
Conversation
Collaborator
|
Commit: 82112d7 |
Implement a new `bundle migrate` command that creates the direct state file
from local config + Terraform state attributes, without making any API calls.
Unlike `bundle deployment migrate` which calls DoRead for each resource, this
command reads resolved field values directly from the local TF state file.
Cross-resource references (e.g. ${resources.jobs.src.git_source[0].branch})
are resolved using two independent methods and the results reconciled:
- Method A: look up the field in the TF state of the resource that contains
the reference (e.g. read name from databricks_job.dst TF attributes).
- Method B: evaluate the template by reading each ${resources.*} reference
from the TF state of the referenced resource and interpolating.
If both methods agree, the value is used silently. If only one succeeds, that
value is used. If both succeed but disagree, the longer string is used with a
warning. If both fail, an error is returned.
The bundle/migrate package provides:
- ParseTFStateAttrs: parses the full TF state file (all resource attributes)
- LookupTFField: looks up a field value using DABsPathToTerraform translation
- ResolveFieldRef: reconciles Methods A and B for a single field
Co-authored-by: Isaac
The new migrate command reads only from the local TF state file and never invokes the Terraform engine, so a pre-migration plan check has no place here. The --noplancheck flag is kept but ignored to avoid breaking callers. Co-authored-by: Isaac
…/migrate
MigrateMode was a bool parameter on Apply that forked between "save state
without deploying" and "actually deploy". The two MigrateMode(true) callers
(bundle deployment migrate and upload_state_for_yaml_sync) now use
migrate.BuildStateFromTF directly, reading from the local TF state file
without any API calls.
Changes:
- New bundle/migrate/build_state.go: public BuildStateFromTF extracted from
cmd/bundle/migrate.go, taking *config.Root so callers can pass an
un-interpolated config (needed by upload_state_for_yaml_sync).
- bundle/direct/bundle_apply.go: drop MigrateMode type and parameter; Apply
now only handles real deployments.
- bundle/phases/{deploy,destroy}.go: drop MigrateMode(false) argument.
- upload_state_for_yaml_sync.go: replace CalculatePlan+Apply with
BuildStateFromTF; keep reverseInterpolate since config is TF-interpolated.
- cmd/bundle/deployment/migrate.go: replace CalculatePlan+Apply with
BuildStateFromTF; drop exported RunPlanCheck/GetCommonArgs wrappers.
- cmd/bundle/migrate.go: delegate to migrate.BuildStateFromTF.
Co-authored-by: Isaac
The new approach (BuildStateFromTF, no API calls) has been folded into the existing 'bundle deployment migrate' command. The separate 'bundle migrate' command is removed — it was redundant. Also add resolve_test.go: verify that int and bool cross-resource references work correctly when Method B returns a string value. structaccess.Set already handles string→int and string→bool conversion via strconv, so no bug exists. Co-authored-by: Isaac
The command now reads from the local TF state file without invoking the Terraform binary, so there is nothing for the plan check to verify. Also simplify getCommonArgs to return only the display string (the args slice was only needed to forward to the plan subprocess). Co-authored-by: Isaac
13572c4 to
82112d7
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Changes
Why
Tests