Skip to content

Commit 451dfea

Browse files
authored
structaccess: accept dyn.Path directly (#3503)
## Changes Make structaccess.Get accept dyn.Path rather than string. Follow up to #3466 ## Why I plan to check more than one struct (config and remote state) and it's good to reuse parsed path between those. ## Tests Existing tests. There is also a new test added but it's not a regression test for this PR (the bad syntax never reaches NewPathFromString), just on related topic.
1 parent 6a90341 commit 451dfea

File tree

13 files changed

+96
-19
lines changed

13 files changed

+96
-19
lines changed

.wsignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ acceptance/bundle/templates-machinery/helpers-error/output.txt
2828
acceptance/bundle/apps/config_section/output.txt
2929
integration/bundle/testdata/apps/bundle_deploy.txt
3030

31+
# Extra whitespace in test output:
32+
acceptance/bundle/resource_deps/bad_syntax/out.plan.terraform.txt
33+
3134
# Extra whitespace in command help:
3235
acceptance/cmd/workspace/apps/output.txt
3336

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
resources:
2+
volumes:
3+
bar:
4+
catalog_name: mycatalog
5+
schema_name: myschema
6+
name: barname
7+
foo:
8+
catalog_name: ${resources.volumes.bar.bad..syntax}
9+
schema_name: ${resources.volumes.bar.schema_name}
10+
name: myname
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files...
2+
Deploying resources...
3+
Updating deployment state...
4+
Deployment complete!
5+
6+
Unexpected success
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
create volumes.bar
2+
create volumes.foo
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Error: exit status 1
2+
3+
Error: Invalid attribute name
4+
5+
on bundle.tf.json line 22, in resource.databricks_volume.foo:
6+
22: "catalog_name": "${resources.volumes.bar.bad..syntax}",
7+
8+
An attribute name is required after a dot.
9+
10+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Local = true
2+
Cloud = false
3+
4+
[EnvMatrix]
5+
DATABRICKS_CLI_DEPLOYMENT = ["terraform", "direct-exp"]
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
>>> [CLI] bundle validate -o json
3+
{
4+
"volumes": {
5+
"bar": {
6+
"catalog_name": "mycatalog",
7+
"name": "barname",
8+
"schema_name": "myschema",
9+
"volume_type": "MANAGED"
10+
},
11+
"foo": {
12+
"catalog_name": "${resources.volumes.bar.bad..syntax}",
13+
"name": "myname",
14+
"schema_name": "${resources.volumes.bar.schema_name}",
15+
"volume_type": "MANAGED"
16+
}
17+
}
18+
}
19+
20+
Exit code: 1
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
trace $CLI bundle validate -o json | jq .resources
2+
$CLI bundle plan &> out.plan.$DATABRICKS_CLI_DEPLOYMENT.txt
3+
musterr $CLI bundle deploy &> out.deploy.$DATABRICKS_CLI_DEPLOYMENT.txt
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Badness = "In validate we dont detect issue; in direct we dont detect syntax issue, skipping the reference completely"
2+
RecordRequests = false

bundle/terranova/plan.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/databricks/cli/bundle/deployplan"
1212
"github.com/databricks/cli/bundle/terranova/tnstate"
1313
"github.com/databricks/cli/libs/dagrun"
14+
"github.com/databricks/cli/libs/dyn"
1415
"github.com/databricks/cli/libs/dyn/dynvar"
1516
"github.com/databricks/cli/libs/logdiag"
1617
"github.com/databricks/cli/libs/structaccess"
@@ -171,7 +172,12 @@ func CalculatePlanForDeploy(ctx context.Context, b *bundle.Bundle) error {
171172
}
172173
continue
173174
}
174-
value, err := structaccess.Get(config, fieldPath)
175+
dynPath, err := dyn.NewPathFromString(fieldPath)
176+
if err != nil {
177+
logdiag.LogError(ctx, fmt.Errorf("cannot parse path %s: %w", fieldPath, err))
178+
return false
179+
}
180+
value, err := structaccess.Get(config, dynPath)
175181
if err != nil {
176182
logdiag.LogError(ctx, fmt.Errorf("cannot resolve %s: %w", reference, err))
177183
return false

0 commit comments

Comments
 (0)