Skip to content

Generalize terraform to bundle conversion, prepare for direct deployment - #3134

Merged
denik merged 14 commits into
mainfrom
denik/improve-terraform-load
Jul 2, 2025
Merged

Generalize terraform to bundle conversion, prepare for direct deployment#3134
denik merged 14 commits into
mainfrom
denik/improve-terraform-load

Conversation

@denik

@denikdenik commented Jun 27, 2025

Copy link
Copy Markdown
Contributor

Changes

  • Introduce ExportedResourcesMap type that is deployment-method neutral. Modify terraform.ParseResourcesState to return this type instead of struct matching terraform state format.
  • Modify terraform.TerraformToBundle() to rely on this new format.
  • Make terraform.TerraformToBundle() handle all resources automatically and operate on dynamic bundle structure.
  • Remove ModifedStatusUpdated constant and usage in apps.
  • Fix Secret scopes resource to properly set modified_status. Previously it was always "created".

Why

ExportedResourcesMap allows implementing terraform.Load() and thus bundle summary/run/open with direct deployment method (#2926) as it is not tied to terraform resource names or internal state structure.

When implementing new resource, we no longer need to add an entry in TerraformToBundle, this both saves time and avoids bugs.

ModifiedStatusUpdated is removed because it's not implemented. Only app resource ever sets it and it sets it always, not based on the actual situation.

Tests

summary/modified_status is expanded to handle both cases where resources: block is present and not present (regression during development of this PR).

@denik
deniktemporarily deployed to test-trigger-is June 27, 2025 09:16 — with GitHub Actions Inactive
@denikdenik changed the title Denik/improve terraform loadRewrite terraform.Load() to use dyn value and not depend on terraformJun 27, 2025
@denikdenik changed the title Rewrite terraform.Load() to use dyn value and not depend on terraformGeneric and independent from terraform state to bundle conversionJun 27, 2025
denik added a commit that referenced this pull request Jun 27, 2025
## Tests
For jobs, dashboards, secret scopes check that "id" and
"modified_status" fields are set correctly by printing more output from
"bundle summary".
This highlights the issue with secret scopes - modified_status is not
correct there.
## Why
To support refactoring (#3134) and
adding support for direct deployment to bundle summary.
Base automatically changed from denik/TEST_DEFAULT_WAREHOUSE_ID to mainJune 27, 2025 09:34
@denik
denikforce-pushed the denik/improve-terraform-load branch from 543d521 to 6ad23b8CompareJune 27, 2025 09:49
@denik
deniktemporarily deployed to test-trigger-is June 27, 2025 09:49 — with GitHub Actions Inactive
@eng-dev-ecosystem-bot

eng-dev-ecosystem-bot commented Jun 27, 2025

Copy link
Copy Markdown
Collaborator

Run: 16020926487

Env✅‌pass❌‌FAIL🔄‌flaky🙈‌skip
❌‌aws linux2932371
❌‌aws windows29431370
✅‌aws-ucws linux399271
✅‌aws-ucws windows400270
🔄‌azure linux2952370
✅‌azure windows298369
🔄‌azure-ucws linux3938268
🔄‌azure-ucws windows3993267
✅‌gcp linux296372
✅‌gcp windows297371
14 failing tests:
Test Nameaws linuxaws windowsazure linuxazure-ucws linuxazure-ucws windows
TestAccept✅‌pass❌‌FAIL🔄‌flaky✅‌pass🔄‌flaky
TestAccept/bundle/deploy/dashboard/detect-change✅‌pass✅‌pass🔄‌flaky🔄‌flaky🔄‌flaky
TestAccept/bundle/deploy/dashboard/nested-folders✅‌pass✅‌pass✅‌pass🔄‌flaky✅‌pass
TestAccept/bundle/deploy/dashboard/simple✅‌pass✅‌pass✅‌pass🔄‌flaky✅‌pass
TestAccept/bundle/deploy/dashboard/simple_outside_bundle_root✅‌pass✅‌pass✅‌pass🔄‌flaky✅‌pass
TestAccept/bundle/deploy/dashboard/simple_syncroot✅‌pass✅‌pass✅‌pass🔄‌flaky✅‌pass
TestAccept/bundle/deployment/bind/dashboard✅‌pass✅‌pass✅‌pass🔄‌flaky✅‌pass
TestAccept/bundle/deployment/bind/dashboard/recreation✅‌pass✅‌pass✅‌pass🔄‌flaky✅‌pass
TestAccept/bundle/resources/pipelines✅‌pass❌‌FAIL✅‌pass✅‌pass✅‌pass
TestAccept/bundle/resources/pipelines/DATABRICKS_CLI_DEPLOYMENT=direct-exp✅‌pass❌‌FAIL✅‌pass✅‌pass✅‌pass
TestDashboardAssumptions_WorkspaceImport✅‌pass✅‌pass✅‌pass🔄‌flaky🔄‌flaky
TestFetchRepositoryInfoAPI_FromRepo❌‌FAIL✅‌pass✅‌pass✅‌pass✅‌pass
TestLock❌‌FAIL✅‌pass✅‌pass✅‌pass✅‌pass
TestSyncEnsureRemotePathIsUsableIfRepoExists✅‌pass🔄‌flaky✅‌pass✅‌pass✅‌pass

@denik
denikforce-pushed the denik/improve-terraform-load branch from 6ad23b8 to a2650a4CompareJune 27, 2025 13:08
@denik
deniktemporarily deployed to test-trigger-is June 27, 2025 13:08 — with GitHub Actions Inactive
@denik
deniktemporarily deployed to test-trigger-is June 30, 2025 07:45 — with GitHub Actions Inactive
@denik

denik commented Jun 30, 2025

Copy link
Copy Markdown
ContributorAuthor

Fails this test #3142 -- will investigate.

@denik
denik marked this pull request as draft June 30, 2025 10:27
denik added a commit that referenced this pull request Jun 30, 2025
## Changes
Add an acceptance test covering modified_status lifecycle: "created" ->
"" -> "deleted".
## Why
To support refactoring such as
#3134 and direct deployment method
support in summary.
---------
Co-authored-by: shreyas-goenka <88374338+shreyas-goenka@users.noreply.github.com>
@denik
denikforce-pushed the denik/improve-terraform-load branch from 9360615 to 7e52eb4CompareJune 30, 2025 14:26
@denik
deniktemporarily deployed to test-trigger-is June 30, 2025 14:26 — with GitHub Actions Inactive
@denik
deniktemporarily deployed to test-trigger-is June 30, 2025 14:36 — with GitHub Actions Inactive
@denik
deniktemporarily deployed to test-trigger-is June 30, 2025 15:09 — with GitHub Actions Inactive
@denik
denik marked this pull request as ready for review June 30, 2025 15:09
@denik
denikforce-pushed the denik/improve-terraform-load branch from 45b54a5 to 7139d58CompareJuly 1, 2025 08:06
@denik
deniktemporarily deployed to test-trigger-is July 1, 2025 08:06 — with GitHub Actions Inactive
@denik
denikforce-pushed the denik/improve-terraform-load branch from 7139d58 to 1808a26CompareJuly 1, 2025 09:12
@denik
deniktemporarily deployed to test-trigger-is July 1, 2025 09:12 — with GitHub Actions Inactive
@denik
denikforce-pushed the denik/improve-terraform-load branch from 1808a26 to 29edbecCompareJuly 1, 2025 09:33
@denik
denikforce-pushed the denik/improve-terraform-load branch from fd3c594 to cbe7fc9CompareJuly 2, 2025 07:08
@denik
deniktemporarily deployed to test-trigger-is July 2, 2025 07:09 — with GitHub Actions Inactive

@pieternpietern left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor comment-related-comments.

Nice work, this simplifies things a lot.


const (
ModifiedStatusCreated ModifiedStatus = "created"
ModifiedStatusUpdated ModifiedStatus = "updated"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andrewnester This was only set by apps (in #1928). Did you use it for anything or just completeness?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, not really, only for summary output but this is handled differently now

}
func ensureMap(v dyn.Value, path dyn.Path) (dyn.Value, error) {
item, _ := dyn.GetByPath(v, path)
if !item.IsValid() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Panic or error if it is not a map to be defensive?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If any parents are of invalid type (should not be possible), SetByPath later will return an error. This seems enough.

idPath := dyn.Path{dyn.Key("id")}
statusPath := dyn.Path{dyn.Key("modified_status")}
id, _ := dyn.GetByPath(inner, idPath)
status, _ := dyn.GetByPath(inner, statusPath)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you include a comment here explaining that IDs are set for resources that have already been deployed and that the status is set for resources that were deleted? The remaining resources are yet to be deployed.

for _, src := range config.Resources.Apps {
if src.ModifiedStatus == "" {
src.ModifiedStatus = resources.ModifiedStatusCreated
func TerraformToBundle(ctx context.Context, state ExportedResourcesMap, config *config.Root) error {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reading the rest of this PR, I assume you want to extract this into a separate generic package?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will be move to statemgmt #3161 and extend to support direct deployment.

Comment threadbundle/deploy/terraform/util.go Outdated

switch groupName {
case "apps":
fallthrough

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL, didn't know Go supported this. I would prefer duplication though, because updating secret scopes in isolation now affects apps as well. Duplication keeps it simple.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough, in this case duplication is okay as well ca58ff3

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 to duplication

Comment threadbundle/statemgmt/resourcestate/resourcestate.go Outdated
// This is in a separate package to avoid import cycles because it is imported by both terraform and statemgmt.
package resourcestate

type ResourceState struct {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add type comment.


func localStateFile(t *testing.T, ctx context.Context, b *bundle.Bundle) string {
dir, err := tf.Dir(ctx, b)
dir, err := b.CacheDir(ctx, "terraform")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leftover from import cycle?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was an import cycle between statemgmt and terraform but it was resolved by creating statemgmt/resourcestate package.

Still nice not to add this dependency if we can avoid, especially given that it's just a test.

@pieternpietern left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw, please take a look at the PR title and summary.

Some names are out of sync with the actual implementation.

@denik
deniktemporarily deployed to test-trigger-is July 2, 2025 09:06 — with GitHub Actions Inactive
@denikdenik changed the title Generic and independent from terraform state to bundle conversionGeneralize terraform to bundle conversion, prepare for direct deploymentJul 2, 2025
Comment threadbundle/deploy/terraform/util.go Outdated

switch groupName {
case "apps":
fallthrough

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 to duplication

@denik
denik merged commit 8442924 into mainJul 2, 2025
@denik
denik deleted the denik/improve-terraform-load branch July 2, 2025 09:21
denik added a commit that referenced this pull request Jul 3, 2025
## Changes
Move terraform.Load to statemgmt.Load
Move terraform.TerraformToBundle to statemgmt.StateToBundle.
Move related unit tests.
Pure move, no functional changes.
Stacked on top of #3134
## Why
Preparation for making it work with direct deployment.
denik added a commit that referenced this pull request Jul 3, 2025
## Changes
- Fix resource deletion in direct backend: resource removed from the
config are now deleted.
- Implement bundle summary/run/open in direct backend.
## Depends on
- #3134
- #3161
## Tests
Enabled a bunch of tests & added more precise comments on remaining
disabled.
denik added a commit that referenced this pull request May 20, 2026
## Tests
For jobs, dashboards, secret scopes check that "id" and
"modified_status" fields are set correctly by printing more output from
"bundle summary".
This highlights the issue with secret scopes - modified_status is not
correct there.
## Why
To support refactoring (#3134) and
adding support for direct deployment to bundle summary.
denik added a commit that referenced this pull request May 20, 2026
## Changes
Add an acceptance test covering modified_status lifecycle: "created" ->
"" -> "deleted".
## Why
To support refactoring such as
#3134 and direct deployment method
support in summary.
---------
Co-authored-by: shreyas-goenka <88374338+shreyas-goenka@users.noreply.github.com>
denik added a commit that referenced this pull request May 20, 2026
…ent (#3134)
## Changes
- Introduce ExportedResourcesMap type that is deployment-method neutral.
Modify terraform.ParseResourcesState to return this type instead of
struct matching terraform state format.
- Modify terraform.TerraformToBundle() to rely on this new format.
- Make terraform.TerraformToBundle() handle all resources automatically
and operate on dynamic bundle structure.
- Remove ModifedStatusUpdated constant and usage in apps.
- Fix Secret scopes resource to properly set modified_status. Previously
it was always "created".
## Why
ExportedResourcesMap allows implementing terraform.Load() and thus
bundle summary/run/open with direct deployment method
(#2926) as it is not tied to
terraform resource names or internal state structure.
When implementing new resource, we no longer need to add an entry in
TerraformToBundle, this both saves time and avoids bugs.
ModifiedStatusUpdated is removed because it's not implemented. Only app
resource ever sets it and it sets it always, not based on the actual
situation.
## Tests
summary/modified_status is expanded to handle both cases where
resources: block is present and not present (regression during
development of this PR).
denik added a commit that referenced this pull request May 20, 2026
## Changes
Move terraform.Load to statemgmt.Load
Move terraform.TerraformToBundle to statemgmt.StateToBundle.
Move related unit tests.
Pure move, no functional changes.
Stacked on top of #3134
## Why
Preparation for making it work with direct deployment.
denik added a commit that referenced this pull request May 20, 2026
## Changes
- Fix resource deletion in direct backend: resource removed from the
config are now deleted.
- Implement bundle summary/run/open in direct backend.
## Depends on
- #3134
- #3161
## Tests
Enabled a bunch of tests & added more precise comments on remaining
disabled.
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@denik@eng-dev-ecosystem-bot@pietern@andrewnester