Skip to content

Commit 125a368

Browse files
authored
direct: type checks for path validity (#3504)
## Changes - New function structaccess.Validate for type checking the path against the type. - Make use of it during planning to show better error messages (schema mismatch vs field not provided). ## Why I'm going to add lookups in remote state. Remote state is optional / needs a request to backend. Type checking the path allows checking if reference is valid for remote state without actually having the state. ## Tests New acceptance test to show value-based non-existent field. More non-regression test that cover different types of access and show inconsistencies between terraform and direct.
1 parent f07c491 commit 125a368

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+673
-29
lines changed

acceptance/bundle/bundle_tag/url_ref/out.deploy.direct-exp.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files...
2-
Error: cannot resolve ${resources.jobs.foo.url}: url: field "url" not found in resources.Job
2+
Error: schema mismatch for ${resources.jobs.foo.url}: url: field "url" not found in resources.Job
33

44
Error: cannot plan jobs.bar: dependency failed: jobs.foo
55

acceptance/bundle/bundle_tag/url_ref/out.plan.direct-exp.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Error: cannot resolve ${resources.jobs.foo.url}: url: field "url" not found in resources.Job
1+
Error: schema mismatch for ${resources.jobs.foo.url}: url: field "url" not found in resources.Job
22

33
Error: cannot plan jobs.bar: dependency failed: jobs.foo
44

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
resources:
2+
pipelines:
3+
foo:
4+
name: pfoo
5+
bar:
6+
name: pbar ${resources.pipelines.foo.ingestion_definition.connection_name}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Error: field not set ${resources.pipelines.foo.ingestion_definition.connection_name}: ingestion_definition.connection_name: cannot access key "connection_name" on invalid
2+
3+
Error: cannot plan pipelines.bar: dependency failed: pipelines.foo
4+
5+
Error: planning failed
6+
7+
8+
Exit code (musterr): 1
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Error: exit status 1
2+
3+
Error: Invalid operation
4+
5+
on bundle.tf.json line 22, in resource.databricks_pipeline.bar:
6+
22: "name": "pbar ${databricks_pipeline.foo.ingestion_definition.connection_name}"
7+
8+
Block type "ingestion_definition" is represented by a list of objects, so it
9+
must be indexed using a numeric key, like .ingestion_definition[0].
10+
11+
12+
13+
Exit code (musterr): 1
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"method": "GET",
3+
"path": "/api/2.0/preview/scim/v2/Me"
4+
}
5+
{
6+
"method": "GET",
7+
"path": "/api/2.0/workspace/get-status"
8+
}
9+
{
10+
"method": "POST",
11+
"path": "/api/2.0/workspace/mkdirs",
12+
"body": {
13+
"path": "/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files"
14+
}
15+
}
16+
{
17+
"method": "GET",
18+
"path": "/api/2.0/workspace/get-status"
19+
}
20+
{
21+
"method": "GET",
22+
"path": "/api/2.0/preview/scim/v2/Me"
23+
}
24+
{
25+
"method": "GET",
26+
"path": "/api/2.0/workspace/get-status"
27+
}
28+
{
29+
"method": "GET",
30+
"path": "/api/2.0/workspace/get-status"
31+
}
32+
{
33+
"method": "POST",
34+
"path": "/api/2.0/workspace/delete",
35+
"body": {
36+
"path": "/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/artifacts/.internal",
37+
"recursive": true
38+
}
39+
}
40+
{
41+
"method": "POST",
42+
"path": "/api/2.0/workspace/mkdirs",
43+
"body": {
44+
"path": "/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/artifacts/.internal"
45+
}
46+
}
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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"pbar ${resources.pipelines.foo.ingestion_definition.connection_name}"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
$CLI bundle validate -o json | jq .resources.pipelines.bar.name
2+
musterr $CLI bundle plan &> out.plan.$DATABRICKS_CLI_DEPLOYMENT.txt
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Badness = "In TF error message talks about ingestion_definition being a list which is not the case. In direct error message says 'on invalid' which is confusing, should say about ingestion_definition being nil"

0 commit comments

Comments
 (0)