diff --git a/internal/schema/tests/1.11/mock_data_block.go b/internal/schema/tests/1.11/mock_data_block.go new file mode 100644 index 00000000..2a4df67b --- /dev/null +++ b/internal/schema/tests/1.11/mock_data_block.go @@ -0,0 +1,11 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package schema + +import "github.com/hashicorp/hcl-lang/schema" + +func patchMockDataBlockSchema(bs *schema.BlockSchema) *schema.BlockSchema { + bs.Body.Attributes["override_during"] = overrideDuringAttributeSchema() + return bs +} diff --git a/internal/schema/tests/1.11/mock_provider_block.go b/internal/schema/tests/1.11/mock_provider_block.go new file mode 100644 index 00000000..fd10c479 --- /dev/null +++ b/internal/schema/tests/1.11/mock_provider_block.go @@ -0,0 +1,16 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package schema + +import "github.com/hashicorp/hcl-lang/schema" + +func patchMockProviderBlockSchema(bs *schema.BlockSchema) *schema.BlockSchema { + bs.Body.Attributes["override_during"] = overrideDuringAttributeSchema() + + bs.Body.Blocks["mock_resource"] = patchMockResourceBlockSchema(bs.Body.Blocks["mock_resource"]) + bs.Body.Blocks["mock_data"] = patchMockDataBlockSchema(bs.Body.Blocks["mock_data"]) + bs.Body.Blocks["override_resource"].Body.Attributes["override_during"] = overrideDuringAttributeSchema() + bs.Body.Blocks["override_data"].Body.Attributes["override_during"] = overrideDuringAttributeSchema() + return bs +} diff --git a/internal/schema/tests/1.11/mock_resource_block.go b/internal/schema/tests/1.11/mock_resource_block.go new file mode 100644 index 00000000..1816ab34 --- /dev/null +++ b/internal/schema/tests/1.11/mock_resource_block.go @@ -0,0 +1,11 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package schema + +import "github.com/hashicorp/hcl-lang/schema" + +func patchMockResourceBlockSchema(bs *schema.BlockSchema) *schema.BlockSchema { + bs.Body.Attributes["override_during"] = overrideDuringAttributeSchema() + return bs +} diff --git a/internal/schema/tests/1.11/override_data_block.go b/internal/schema/tests/1.11/override_data_block.go new file mode 100644 index 00000000..29794b7a --- /dev/null +++ b/internal/schema/tests/1.11/override_data_block.go @@ -0,0 +1,13 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package schema + +import ( + "github.com/hashicorp/hcl-lang/schema" +) + +func patchOverrideDataBlockSchema(bs *schema.BlockSchema) *schema.BlockSchema { + bs.Body.Attributes["override_during"] = overrideDuringAttributeSchema() + return bs +} diff --git a/internal/schema/tests/1.11/override_during_attribute.go b/internal/schema/tests/1.11/override_during_attribute.go new file mode 100644 index 00000000..ab19bf97 --- /dev/null +++ b/internal/schema/tests/1.11/override_during_attribute.go @@ -0,0 +1,26 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package schema + +import ( + "github.com/hashicorp/hcl-lang/lang" + "github.com/hashicorp/hcl-lang/schema" +) + +func overrideDuringAttributeSchema() *schema.AttributeSchema { + return &schema.AttributeSchema{ + Description: lang.Markdown("Allows overriding the point in time where terraform generates data"), + IsOptional: true, + Constraint: schema.OneOf{ + schema.Keyword{ + Keyword: "apply", + Description: lang.Markdown("Default behavior where data is generated during the apply operation and (known after apply) is returned during the plan"), + }, + schema.Keyword{ + Keyword: "plan", + Description: lang.Markdown("Allows to generate data during the plan operation. The same data will be used during the apply"), + }, + }, + } +} diff --git a/internal/schema/tests/1.11/override_module_block.go b/internal/schema/tests/1.11/override_module_block.go new file mode 100644 index 00000000..e2d888e9 --- /dev/null +++ b/internal/schema/tests/1.11/override_module_block.go @@ -0,0 +1,13 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package schema + +import ( + "github.com/hashicorp/hcl-lang/schema" +) + +func patchOverrideModuleBlockSchema(bs *schema.BlockSchema) *schema.BlockSchema { + bs.Body.Attributes["override_during"] = overrideDuringAttributeSchema() + return bs +} diff --git a/internal/schema/tests/1.11/override_resource_block.go b/internal/schema/tests/1.11/override_resource_block.go new file mode 100644 index 00000000..75388387 --- /dev/null +++ b/internal/schema/tests/1.11/override_resource_block.go @@ -0,0 +1,13 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package schema + +import ( + "github.com/hashicorp/hcl-lang/schema" +) + +func patchOverrideResourceBlockSchema(bs *schema.BlockSchema) *schema.BlockSchema { + bs.Body.Attributes["override_during"] = overrideDuringAttributeSchema() + return bs +} diff --git a/internal/schema/tests/1.11/root.go b/internal/schema/tests/1.11/root.go new file mode 100644 index 00000000..51039579 --- /dev/null +++ b/internal/schema/tests/1.11/root.go @@ -0,0 +1,25 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package schema + +import ( + "github.com/hashicorp/go-version" + "github.com/hashicorp/hcl-lang/schema" + + v1_9_test "github.com/hashicorp/terraform-schema/internal/schema/tests/1.9" +) + +// TestSchema returns the static schema for a test +// configuration (*.tftest.hcl) file. +func TestSchema(v *version.Version) *schema.BodySchema { + bs := v1_9_test.TestSchema(v) + + bs.Blocks["run"] = patchRunBlockSchema(bs.Blocks["run"]) + bs.Blocks["mock_provider"] = patchMockProviderBlockSchema(bs.Blocks["mock_provider"]) + bs.Blocks["override_module"] = patchOverrideModuleBlockSchema(bs.Blocks["override_module"]) + bs.Blocks["override_resource"] = patchOverrideResourceBlockSchema(bs.Blocks["override_resource"]) + bs.Blocks["override_data"] = patchOverrideDataBlockSchema(bs.Blocks["override_data"]) + + return bs +} diff --git a/internal/schema/tests/1.11/run_block.go b/internal/schema/tests/1.11/run_block.go new file mode 100644 index 00000000..c7f9da38 --- /dev/null +++ b/internal/schema/tests/1.11/run_block.go @@ -0,0 +1,24 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package schema + +import ( + "github.com/hashicorp/hcl-lang/lang" + "github.com/hashicorp/hcl-lang/schema" + "github.com/zclconf/go-cty/cty" +) + +func patchRunBlockSchema(bs *schema.BlockSchema) *schema.BlockSchema { + bs.Body.Attributes["state_key"] = &schema.AttributeSchema{ + Description: lang.Markdown("An optional key to override the default state file used for this run block. Setting this value forces Terraform to use a specific state file identified by the given key, allowing state to be shared between run blocks. Read more on [module states](https://developer.hashicorp.com/terraform/language/tests#modules-state)"), + Constraint: schema.AnyExpression{OfType: cty.String}, + IsOptional: true, + } + + bs.Body.Blocks["override_resource"].Body.Attributes["override_during"] = overrideDuringAttributeSchema() + bs.Body.Blocks["override_data"].Body.Attributes["override_during"] = overrideDuringAttributeSchema() + bs.Body.Blocks["override_module"].Body.Attributes["override_during"] = overrideDuringAttributeSchema() + + return bs +} diff --git a/schema/tests/test_schema.go b/schema/tests/test_schema.go index f150ba71..7dd01588 100644 --- a/schema/tests/test_schema.go +++ b/schema/tests/test_schema.go @@ -6,6 +6,7 @@ package schema import ( "github.com/hashicorp/go-version" "github.com/hashicorp/hcl-lang/schema" + test_v1_11 "github.com/hashicorp/terraform-schema/internal/schema/tests/1.11" test_v1_6 "github.com/hashicorp/terraform-schema/internal/schema/tests/1.6" test_v1_7 "github.com/hashicorp/terraform-schema/internal/schema/tests/1.7" test_v1_9 "github.com/hashicorp/terraform-schema/internal/schema/tests/1.9" @@ -13,9 +14,10 @@ import ( ) var ( - v1_6 = version.Must(version.NewVersion("1.6")) - v1_7 = version.Must(version.NewVersion("1.7")) - v1_9 = version.Must(version.NewVersion("1.9")) + v1_6 = version.Must(version.NewVersion("1.6")) + v1_7 = version.Must(version.NewVersion("1.7")) + v1_9 = version.Must(version.NewVersion("1.9")) + v1_11 = version.Must(version.NewVersion("1.11")) ) // CoreTestSchemaForVersion finds a schema for test configuration files @@ -24,6 +26,9 @@ var ( func CoreTestSchemaForVersion(v *version.Version) (*schema.BodySchema, error) { ver := v.Core() + if ver.GreaterThanOrEqual(v1_11) { + return test_v1_11.TestSchema(ver), nil + } if ver.GreaterThanOrEqual(v1_9) { return test_v1_9.TestSchema(ver), nil }