Skip to content

Commit 1048510

Browse files
authored
tf query: disable depends_on for list blocks (#37618)
1 parent 0b15151 commit 1048510

File tree

3 files changed

+46
-5
lines changed

3 files changed

+46
-5
lines changed

internal/configs/parser_config_dir_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,15 @@ func TestParserLoadConfigDirWithQueries(t *testing.T) {
197197
},
198198
allowExperiments: true,
199199
},
200+
{
201+
name: "with-depends-on",
202+
directory: "testdata/query-files/invalid/with-depends-on",
203+
diagnostics: []string{
204+
"testdata/query-files/invalid/with-depends-on/main.tfquery.hcl:23,3-13: Unsupported argument; An argument named \"depends_on\" is not expected here.",
205+
},
206+
listResources: 2,
207+
allowExperiments: true,
208+
},
200209
}
201210

202211
for _, test := range tests {

internal/configs/query_file.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -194,15 +194,23 @@ func decodeQueryListBlock(block *hcl.Block) (*Resource, hcl.Diagnostics) {
194194
// QueryListResourceBlockSchema is the schema for a list resource type within
195195
// a terraform query file.
196196
var QueryListResourceBlockSchema = &hcl.BodySchema{
197-
Attributes: append(
198-
commonResourceAttributes,
199-
hcl.AttributeSchema{
197+
Attributes: []hcl.AttributeSchema{
198+
{
199+
Name: "count",
200+
},
201+
{
202+
Name: "for_each",
203+
},
204+
{
205+
Name: "provider",
206+
},
207+
{
200208
Name: "include_resource",
201209
},
202-
hcl.AttributeSchema{
210+
{
203211
Name: "limit",
204212
},
205-
),
213+
},
206214
}
207215

208216
// queryFileSchema is the schema for a terraform query file. It defines the
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
list "aws_instance" "test" {
2+
provider = aws
3+
count = 1
4+
include_resource = true
5+
limit = 5
6+
config {
7+
tags = {
8+
Name = "test"
9+
}
10+
}
11+
}
12+
list "aws_instance" "test2" {
13+
provider = aws
14+
count = 1
15+
config {
16+
tags = {
17+
Name = join("-", ["test2", list.aws_instance.test.data[0]])
18+
}
19+
}
20+
}
21+
list "aws_instance" "test3" {
22+
provider = aws
23+
depends_on = [list.aws_instance.test2]
24+
}

0 commit comments

Comments
 (0)