diff --git a/go.mod b/go.mod index 18b1f1f1..a9f3aeb1 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/google/go-cmp v0.5.9 github.com/hashicorp/go-cleanhttp v0.5.2 github.com/hashicorp/go-version v1.6.0 - github.com/hashicorp/hcl-lang v0.0.0-20221014125844-7eceda07a779 + github.com/hashicorp/hcl-lang v0.0.0-20221031081328-b20d6288c7f3 github.com/hashicorp/hcl/v2 v2.14.1 github.com/hashicorp/terraform-json v0.14.0 github.com/hashicorp/terraform-registry-address v0.0.0-20220623143253-7d51757b572c diff --git a/go.sum b/go.sum index f4f4e8a7..d29e7d60 100644 --- a/go.sum +++ b/go.sum @@ -27,8 +27,8 @@ github.com/hashicorp/go-version v1.2.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09 github.com/hashicorp/go-version v1.5.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= github.com/hashicorp/go-version v1.6.0 h1:feTTfFNnjP967rlCxM/I9g701jU+RN74YKx2mOkIeek= github.com/hashicorp/go-version v1.6.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= -github.com/hashicorp/hcl-lang v0.0.0-20221014125844-7eceda07a779 h1:xzrUeFJXnrQ3U7sNrPLdtY8d2kmYr1BqY8X2fCagsl0= -github.com/hashicorp/hcl-lang v0.0.0-20221014125844-7eceda07a779/go.mod h1:olv+pM633vw0rXvyHIPjw62ur/FNqqNV7b5TfSxLY6E= +github.com/hashicorp/hcl-lang v0.0.0-20221031081328-b20d6288c7f3 h1:vGYvIZ5vznlnvJp4lmTz0yvkE6P7by+myhKPXJhC61c= +github.com/hashicorp/hcl-lang v0.0.0-20221031081328-b20d6288c7f3/go.mod h1:rn5V4b1/658M3g1o+MtdIUl/ZNoCVasB9T31j8XllMM= github.com/hashicorp/hcl/v2 v2.14.1 h1:x0BpjfZ+CYdbiz+8yZTQ+gdLO7IXvOut7Da+XJayx34= github.com/hashicorp/hcl/v2 v2.14.1/go.mod h1:e4z5nxYlWNPdDSNYX+ph14EvWYMFm3eP0zIUqPc2jr0= github.com/hashicorp/terraform-json v0.14.0 h1:sh9iZ1Y8IFJLx+xQiKHGud6/TSUCM0N8e17dKDpqV7s= diff --git a/internal/schema/0.12/data_block.go b/internal/schema/0.12/data_block.go index e22ba5f6..24b624e2 100644 --- a/internal/schema/0.12/data_block.go +++ b/internal/schema/0.12/data_block.go @@ -6,7 +6,6 @@ import ( "github.com/hashicorp/hcl-lang/schema" "github.com/hashicorp/terraform-schema/internal/schema/refscope" "github.com/hashicorp/terraform-schema/internal/schema/tokmod" - "github.com/zclconf/go-cty/cty" ) func datasourceBlockSchema(v *version.Version) *schema.BlockSchema { @@ -43,7 +42,8 @@ func datasourceBlockSchema(v *version.Version) *schema.BlockSchema { "Terraform module, but has no significance outside of the scope of a module."), Body: &schema.BodySchema{ Extensions: &schema.BodyExtensions{ - Count: true, + Count: true, + ForEach: true, // for_each was introduced in 0.12.6, but for simplicity we report it for all 0.12+ }, Attributes: map[string]*schema.AttributeSchema{ "provider": { @@ -73,18 +73,5 @@ func datasourceBlockSchema(v *version.Version) *schema.BlockSchema { }, } - if v.GreaterThanOrEqual(v0_12_6) { - bs.Body.Attributes["for_each"] = &schema.AttributeSchema{ - Expr: schema.ExprConstraints{ - schema.TraversalExpr{OfType: cty.Set(cty.DynamicPseudoType)}, - schema.TraversalExpr{OfType: cty.Map(cty.DynamicPseudoType)}, - schema.LiteralTypeExpr{Type: cty.Set(cty.DynamicPseudoType)}, - schema.LiteralTypeExpr{Type: cty.Map(cty.DynamicPseudoType)}, - }, - IsOptional: true, - Description: lang.Markdown("A set or a map where each item represents an instance of this data source"), - } - } - return bs } diff --git a/internal/schema/0.12/resource_block.go b/internal/schema/0.12/resource_block.go index f1e47cb6..18842ac3 100644 --- a/internal/schema/0.12/resource_block.go +++ b/internal/schema/0.12/resource_block.go @@ -42,7 +42,8 @@ func resourceBlockSchema(v *version.Version) *schema.BlockSchema { "outside of the scope of a module."), Body: &schema.BodySchema{ Extensions: &schema.BodyExtensions{ - Count: true, + Count: true, + ForEach: true, // for_each was introduced in 0.12.6, but for simplicity we report it for all 0.12+ }, Attributes: map[string]*schema.AttributeSchema{ "provider": { @@ -77,19 +78,6 @@ func resourceBlockSchema(v *version.Version) *schema.BlockSchema { }, } - if v.GreaterThanOrEqual(v0_12_6) { - bs.Body.Attributes["for_each"] = &schema.AttributeSchema{ - Expr: schema.ExprConstraints{ - schema.TraversalExpr{OfType: cty.Set(cty.DynamicPseudoType)}, - schema.TraversalExpr{OfType: cty.Map(cty.DynamicPseudoType)}, - schema.LiteralTypeExpr{Type: cty.Set(cty.DynamicPseudoType)}, - schema.LiteralTypeExpr{Type: cty.Map(cty.DynamicPseudoType)}, - }, - IsOptional: true, - Description: lang.Markdown("A set or a map where each item represents an instance of this resource"), - } - } - return bs } diff --git a/internal/schema/0.13/module_block.go b/internal/schema/0.13/module_block.go index 322f2845..47fe5d46 100644 --- a/internal/schema/0.13/module_block.go +++ b/internal/schema/0.13/module_block.go @@ -31,7 +31,8 @@ func moduleBlockSchema() *schema.BlockSchema { Description: lang.PlainText("Module block to call a locally or remotely stored module"), Body: &schema.BodySchema{ Extensions: &schema.BodyExtensions{ - Count: true, + Count: true, + ForEach: true, }, Attributes: map[string]*schema.AttributeSchema{ "source": { @@ -75,16 +76,6 @@ func moduleBlockSchema() *schema.BlockSchema { IsOptional: true, Description: lang.Markdown("Explicit mapping of providers which the module uses"), }, - "for_each": { - Expr: schema.ExprConstraints{ - schema.TraversalExpr{OfType: cty.Set(cty.DynamicPseudoType)}, - schema.TraversalExpr{OfType: cty.Map(cty.DynamicPseudoType)}, - schema.LiteralTypeExpr{Type: cty.Set(cty.DynamicPseudoType)}, - schema.LiteralTypeExpr{Type: cty.Map(cty.DynamicPseudoType)}, - }, - IsOptional: true, - Description: lang.Markdown("A set or a map where each item represents an instance of this module"), - }, "depends_on": { Expr: schema.ExprConstraints{ schema.TupleConsExpr{