From 1048510fec2ccfc549470dc04dbf7fbf1472a293 Mon Sep 17 00:00:00 2001 From: Samsondeen <40821565+dsa0x@users.noreply.github.com> Date: Tue, 16 Sep 2025 13:39:59 +0200 Subject: [PATCH] tf query: disable depends_on for list blocks (#37618) --- internal/configs/parser_config_dir_test.go | 9 +++++++ internal/configs/query_file.go | 18 ++++++++++---- .../invalid/with-depends-on/main.tfquery.hcl | 24 +++++++++++++++++++ 3 files changed, 46 insertions(+), 5 deletions(-) create mode 100644 internal/configs/testdata/query-files/invalid/with-depends-on/main.tfquery.hcl diff --git a/internal/configs/parser_config_dir_test.go b/internal/configs/parser_config_dir_test.go index 4c6e4ec827..b1921a794e 100644 --- a/internal/configs/parser_config_dir_test.go +++ b/internal/configs/parser_config_dir_test.go @@ -197,6 +197,15 @@ func TestParserLoadConfigDirWithQueries(t *testing.T) { }, allowExperiments: true, }, + { + name: "with-depends-on", + directory: "testdata/query-files/invalid/with-depends-on", + diagnostics: []string{ + "testdata/query-files/invalid/with-depends-on/main.tfquery.hcl:23,3-13: Unsupported argument; An argument named \"depends_on\" is not expected here.", + }, + listResources: 2, + allowExperiments: true, + }, } for _, test := range tests { diff --git a/internal/configs/query_file.go b/internal/configs/query_file.go index 13c2f3935f..3fdd79823a 100644 --- a/internal/configs/query_file.go +++ b/internal/configs/query_file.go @@ -194,15 +194,23 @@ func decodeQueryListBlock(block *hcl.Block) (*Resource, hcl.Diagnostics) { // QueryListResourceBlockSchema is the schema for a list resource type within // a terraform query file. var QueryListResourceBlockSchema = &hcl.BodySchema{ - Attributes: append( - commonResourceAttributes, - hcl.AttributeSchema{ + Attributes: []hcl.AttributeSchema{ + { + Name: "count", + }, + { + Name: "for_each", + }, + { + Name: "provider", + }, + { Name: "include_resource", }, - hcl.AttributeSchema{ + { Name: "limit", }, - ), + }, } // queryFileSchema is the schema for a terraform query file. It defines the diff --git a/internal/configs/testdata/query-files/invalid/with-depends-on/main.tfquery.hcl b/internal/configs/testdata/query-files/invalid/with-depends-on/main.tfquery.hcl new file mode 100644 index 0000000000..2eb3de5d49 --- /dev/null +++ b/internal/configs/testdata/query-files/invalid/with-depends-on/main.tfquery.hcl @@ -0,0 +1,24 @@ +list "aws_instance" "test" { + provider = aws + count = 1 + include_resource = true + limit = 5 + config { + tags = { + Name = "test" + } + } +} +list "aws_instance" "test2" { + provider = aws + count = 1 + config { + tags = { + Name = join("-", ["test2", list.aws_instance.test.data[0]]) + } + } +} +list "aws_instance" "test3" { + provider = aws + depends_on = [list.aws_instance.test2] +}