Skip to content

Commit

Permalink
Add support for expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
radeksimko committed Feb 23, 2021
1 parent eb86c23 commit f1e5742
Show file tree
Hide file tree
Showing 22 changed files with 466 additions and 316 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ require (
github.com/google/go-cmp v0.5.4
github.com/hashicorp/go-multierror v1.1.0
github.com/hashicorp/go-version v1.2.1
github.com/hashicorp/hcl-lang v0.0.0-20210213170001-bd00c3f68680
github.com/hashicorp/hcl-lang v0.0.0-20210223121820-c8b1a98ac206
github.com/hashicorp/hcl/v2 v2.8.2
github.com/hashicorp/terraform-config-inspect v0.0.0-20201102131242-0c45ba392e51
github.com/hashicorp/terraform-json v0.8.0
github.com/hashicorp/terraform-svchost v0.0.0-20200729002733-f050f53b9734
github.com/mh-cbon/go-fmt-fail v0.0.0-20160815164508-67765b3fbcb5
github.com/zclconf/go-cty v1.7.1-0.20201110003513-1338293a79a9
github.com/zclconf/go-cty v1.8.0
github.com/zclconf/go-cty-debug v0.0.0-20191215020915-b22d67c1ba0b
golang.org/x/net v0.0.0-20200301022130-244492dfa37a
)
22 changes: 10 additions & 12 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ github.com/apparentlymart/go-textseg v1.0.0 h1:rRmlIsPEEhUTIKQb7T++Nz/A5Q6C9IuX2
github.com/apparentlymart/go-textseg v1.0.0/go.mod h1:z96Txxhf3xSFMPmb5X/1W05FF/Nj9VFpLOpjS5yuumk=
github.com/apparentlymart/go-textseg/v12 v12.0.0 h1:bNEQyAGak9tojivJNkoqWErVCQbjdL7GzRt3F8NvfJ0=
github.com/apparentlymart/go-textseg/v12 v12.0.0/go.mod h1:S/4uRK2UtaQttw1GenVJEynmyUenKwP++x/+DdGV/Ec=
github.com/apparentlymart/go-textseg/v13 v13.0.0 h1:Y+KvPE1NYz0xl601PVImeQfFyEy6iT90AvPUL1NNfNw=
github.com/apparentlymart/go-textseg/v13 v13.0.0/go.mod h1:ZK2fH7c4NqDTLtiYLvIkEghdlcqw7yxLeM89kiTRPUo=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand All @@ -35,11 +37,9 @@ github.com/hashicorp/go-version v1.2.1 h1:zEfKbn2+PDgroKdiOzqiE8rsmLqU2uwi5PB5pB
github.com/hashicorp/go-version v1.2.1/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/hashicorp/hcl v0.0.0-20170504190234-a4b07c25de5f h1:UdxlrJz4JOnY8W+DbLISwf2B8WXEolNRA8BGCwI9jws=
github.com/hashicorp/hcl v0.0.0-20170504190234-a4b07c25de5f/go.mod h1:oZtUIOe8dh44I2q6ScRibXws4Ajl+d+nod3AaR9vL5w=
github.com/hashicorp/hcl-lang v0.0.0-20210213170001-bd00c3f68680 h1:QjPFluG2uGJCBKIp5sEFx+UZ98QnuxmVsnLIuHz8a2Y=
github.com/hashicorp/hcl-lang v0.0.0-20210213170001-bd00c3f68680/go.mod h1:TZ5tpvmgJSHfmIndN4WP9SpZvyWK8tHPBY8LDRyU+pI=
github.com/hashicorp/hcl-lang v0.0.0-20210223121820-c8b1a98ac206 h1:87Gs29VadGfpNTCgRtgaYeHfOnTH4NHLoLZp+hl40I4=
github.com/hashicorp/hcl-lang v0.0.0-20210223121820-c8b1a98ac206/go.mod h1:UbZYm/NXDtbe6w/hbLFTPfcssORkhQqW28L8KTbqVhQ=
github.com/hashicorp/hcl/v2 v2.0.0/go.mod h1:oVVDG71tEinNGYCxinCYadcmKU9bglqW9pV3txagJ90=
github.com/hashicorp/hcl/v2 v2.6.0 h1:3krZOfGY6SziUXa6H9PJU6TyohHn7I+ARYnhbeNBz+o=
github.com/hashicorp/hcl/v2 v2.6.0/go.mod h1:bQTN5mpo+jewjJgh8jr0JUguIi7qPHUF6yIfAEN3jqY=
github.com/hashicorp/hcl/v2 v2.8.2 h1:wmFle3D1vu0okesm8BTLVDyJ6/OL9DCLUwn0b2OptiY=
github.com/hashicorp/hcl/v2 v2.8.2/go.mod h1:bQTN5mpo+jewjJgh8jr0JUguIi7qPHUF6yIfAEN3jqY=
github.com/hashicorp/terraform-config-inspect v0.0.0-20201102131242-0c45ba392e51 h1:SEGO1vz/pFLfKy4QpABIMCe7wffmtsOiWO4yc1E87cU=
Expand All @@ -53,24 +53,21 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348 h1:MtvEpTB6LX3vkb4ax0b5D2DHbNAUsen0Gx5wZoq3lV4=
github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348/go.mod h1:B69LEHPfb2qLo0BaaOLcbitczOKLWTsrBG9LczfCD4k=
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
github.com/mh-cbon/go-fmt-fail v0.0.0-20160815164508-67765b3fbcb5 h1:shw+DWUaHIyW64Tv30ASCbC6QO6fLy+M5SJb5pJVEI4=
github.com/mh-cbon/go-fmt-fail v0.0.0-20160815164508-67765b3fbcb5/go.mod h1:nHPoxaBUc5CDAMIv0MNmn5PBjWbTs9BI/eh30/n0U6g=
github.com/mitchellh/copystructure v1.0.0/go.mod h1:SNtv71yrdKgLRyLFxmLdkAbkKEFWgYaq1OVrnRcwhnw=
github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7 h1:DpOJ2HYzCv8LZP15IdmG+YdwD2luVPHITV96TkirNBM=
github.com/mitchellh/copystructure v1.1.1/go.mod h1:EBArHfARyrSWO/+Wyr9zwEkc6XMFB9XyNgFNmRkZZU4=
github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo=
github.com/mitchellh/go-wordwrap v1.0.0 h1:6GlHJ/LTGMrIJbwgdqdl2eEH8o+Exx/0m8ir9Gns0u4=
github.com/mitchellh/go-wordwrap v1.0.0/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo=
github.com/mitchellh/reflectwalk v1.0.0/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
github.com/mitchellh/reflectwalk v1.0.1/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ=
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
github.com/spf13/pflag v1.0.2/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
Expand All @@ -82,9 +79,8 @@ github.com/vmihailenco/tagparser v0.1.1/go.mod h1:OeAg3pn3UbLjkWt+rN9oFYB6u/cQgq
github.com/zclconf/go-cty v1.1.0/go.mod h1:xnAOWiHeOqg2nWS62VtQ7pbOu17FtxJNW8RLEih+O3s=
github.com/zclconf/go-cty v1.2.0/go.mod h1:hOPWgoHbaTUnI5k4D2ld+GRpFJSCe6bCM7m1q/N4PQ8=
github.com/zclconf/go-cty v1.2.1/go.mod h1:hOPWgoHbaTUnI5k4D2ld+GRpFJSCe6bCM7m1q/N4PQ8=
github.com/zclconf/go-cty v1.6.1/go.mod h1:VDR4+I79ubFBGm1uJac1226K5yANQFHeauxPBoP54+o=
github.com/zclconf/go-cty v1.7.1-0.20201110003513-1338293a79a9 h1:tx8TRITbZ++EWF1KZ6vr2wwGRGkHinxolIqBPIio48Q=
github.com/zclconf/go-cty v1.7.1-0.20201110003513-1338293a79a9/go.mod h1:VDR4+I79ubFBGm1uJac1226K5yANQFHeauxPBoP54+o=
github.com/zclconf/go-cty v1.8.0 h1:s4AvqaeQzJIu3ndv4gVIhplVD0krU+bgrcLSVUnaWuA=
github.com/zclconf/go-cty v1.8.0/go.mod h1:vVKLxnk3puL4qRAv72AO+W99LUD4da90g3uUAzyuvAk=
github.com/zclconf/go-cty-debug v0.0.0-20191215020915-b22d67c1ba0b h1:FosyBZYxY34Wul7O/MSKey3txpPYyCqVO5ZyceuQJEI=
github.com/zclconf/go-cty-debug v0.0.0-20191215020915-b22d67c1ba0b/go.mod h1:ZRKQfBXbGkpdV6QMzT3rU1kSTAnfu1dO8dPKjYprgj8=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
Expand All @@ -106,6 +102,8 @@ golang.org/x/sys v0.0.0-20190502175342-a43fa875dd82/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.5 h1:i6eZZ+zk0SOf0xgBpEpPD18qWcJda6q1sxt3S0kzyUQ=
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down
18 changes: 12 additions & 6 deletions internal/schema/0.12/data_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,24 @@ func datasourceBlockSchema(v *version.Version) *schema.BlockSchema {
Body: &schema.BodySchema{
Attributes: map[string]*schema.AttributeSchema{
"provider": {
ValueType: cty.DynamicPseudoType,
Expr: schema.ExprConstraints{},
IsOptional: true,
Description: lang.Markdown("Reference to a `provider` configuration block, e.g. `mycloud.west` or `mycloud`"),
IsDepKey: true,
},
"count": {
ValueType: cty.Number,
Expr: schema.ExprConstraints{
schema.LiteralTypeExpr{Type: cty.Number},
},
IsOptional: true,
Description: lang.Markdown("Number of instances of this data source, e.g. `3`"),
},
"depends_on": {
ValueType: cty.Set(cty.DynamicPseudoType),
Expr: schema.ExprConstraints{
schema.TupleConsExpr{
Name: "set of references",
},
},
IsOptional: true,
Description: lang.Markdown("Set of references to hidden dependencies, e.g. other resources or data sources"),
},
Expand All @@ -47,9 +53,9 @@ func datasourceBlockSchema(v *version.Version) *schema.BlockSchema {

if v.GreaterThanOrEqual(v0_12_6) {
bs.Body.Attributes["for_each"] = &schema.AttributeSchema{
ValueTypes: schema.ValueTypes{
cty.Set(cty.DynamicPseudoType),
cty.Map(cty.DynamicPseudoType),
Expr: schema.ExprConstraints{
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"),
Expand Down
10 changes: 7 additions & 3 deletions internal/schema/0.12/module_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var moduleBlockSchema = &schema.BlockSchema{
Body: &schema.BodySchema{
Attributes: map[string]*schema.AttributeSchema{
"source": {
ValueType: cty.String,
Expr: schema.LiteralTypeOnly(cty.String),
Description: lang.Markdown("Source where to load the module from, " +
"a local directory (e.g. `./module`) or a remote address - e.g. " +
"`hashicorp/consul/aws` (Terraform Registry address) or " +
Expand All @@ -26,13 +26,17 @@ var moduleBlockSchema = &schema.BlockSchema{
IsDepKey: true,
},
"version": {
ValueType: cty.String,
Expr: schema.LiteralTypeOnly(cty.String),
IsOptional: true,
Description: lang.Markdown("Constraint to set the version of the module, e.g. `~> 1.0`." +
" Only applicable to modules in a module registry."),
},
"providers": {
ValueType: cty.Map(cty.DynamicPseudoType),
Expr: schema.ExprConstraints{
schema.MapExpr{
Name: "map of provider references",
},
},
IsOptional: true,
Description: lang.Markdown("Explicit mapping of providers which the module uses"),
},
Expand Down
12 changes: 8 additions & 4 deletions internal/schema/0.12/output_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,26 @@ var outputBlockSchema = &schema.BlockSchema{
Body: &schema.BodySchema{
Attributes: map[string]*schema.AttributeSchema{
"description": {
ValueType: cty.String,
Expr: schema.LiteralTypeOnly(cty.String),
IsOptional: true,
Description: lang.PlainText("Human-readable description of the output (for documentation and UI)"),
},
"value": {
ValueType: cty.DynamicPseudoType,
Expr: schema.ExprConstraints{},
IsRequired: true,
Description: lang.PlainText("Value, typically a reference to an attribute of a resource or a data source"),
},
"sensitive": {
ValueType: cty.Bool,
Expr: schema.LiteralTypeOnly(cty.Bool),
IsOptional: true,
Description: lang.PlainText("Whether the output contains sensitive material and should be hidden in the UI"),
},
"depends_on": {
ValueType: cty.Set(cty.DynamicPseudoType),
Expr: schema.ExprConstraints{
schema.TupleConsExpr{
Name: "set of references",
},
},
IsOptional: true,
Description: lang.PlainText("Set of references to hidden dependencies (e.g. resources or data sources)"),
},
Expand Down
4 changes: 2 additions & 2 deletions internal/schema/0.12/provider_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ func providerBlockSchema(v *version.Version) *schema.BlockSchema {
Body: &schema.BodySchema{
Attributes: map[string]*schema.AttributeSchema{
"alias": {
ValueType: cty.String,
Expr: schema.LiteralTypeOnly(cty.String),
IsOptional: true,
Description: lang.Markdown("Alias for using the same provider with different configurations for different resources, e.g. `eu-west`"),
},
"version": {
ValueType: cty.String,
Expr: schema.LiteralTypeOnly(cty.String),
IsOptional: true,
Description: lang.Markdown("Specifies a version constraint for the provider, e.g. `~> 1.0`"),
},
Expand Down
57 changes: 45 additions & 12 deletions internal/schema/0.12/resource_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,22 @@ func resourceBlockSchema(v *version.Version) *schema.BlockSchema {
Body: &schema.BodySchema{
Attributes: map[string]*schema.AttributeSchema{
"provider": {
ValueType: cty.DynamicPseudoType,
Expr: schema.ExprConstraints{},
IsOptional: true,
Description: lang.Markdown("Reference to a `provider` configuration block, e.g. `mycloud.west` or `mycloud`"),
IsDepKey: true,
},
"count": {
ValueType: cty.Number,
Expr: schema.LiteralTypeOnly(cty.Number),
IsOptional: true,
Description: lang.Markdown("Number of instances of this resource, e.g. `3`"),
},
"depends_on": {
ValueType: cty.Set(cty.DynamicPseudoType),
Expr: schema.ExprConstraints{
schema.TupleConsExpr{
Name: "set of references",
},
},
IsOptional: true,
Description: lang.Markdown("Set of references to hidden dependencies, e.g. other resources or data sources"),
},
Expand All @@ -51,9 +55,9 @@ func resourceBlockSchema(v *version.Version) *schema.BlockSchema {

if v.GreaterThanOrEqual(v0_12_6) {
bs.Body.Attributes["for_each"] = &schema.AttributeSchema{
ValueTypes: schema.ValueTypes{
cty.Set(cty.DynamicPseudoType),
cty.Map(cty.DynamicPseudoType),
Expr: schema.ExprConstraints{
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"),
Expand All @@ -68,19 +72,21 @@ var lifecycleBlock = &schema.BlockSchema{
Body: &schema.BodySchema{
Attributes: map[string]*schema.AttributeSchema{
"create_before_destroy": {
ValueType: cty.Bool,
Expr: schema.LiteralTypeOnly(cty.Bool),
IsOptional: true,
Description: lang.Markdown("Whether to reverse the default order of operations (destroy -> create) during apply " +
"when the resource requires replacement (cannot be updated in-place)"),
},
"prevent_destroy": {
ValueType: cty.Bool,
Expr: schema.LiteralTypeOnly(cty.Bool),
IsOptional: true,
Description: lang.Markdown("Whether to prevent accidental destruction of the resource and cause Terraform " +
"to reject with an error any plan that would destroy the resource"),
},
"ignore_changes": {
ValueType: cty.Set(cty.DynamicPseudoType),
Expr: schema.ExprConstraints{
schema.TupleConsExpr{},
},
IsOptional: true,
Description: lang.Markdown("A set of fields (references) of which to ignore changes to, e.g. `tags`"),
},
Expand All @@ -101,14 +107,32 @@ var provisionerBlock = &schema.BlockSchema{
Body: &schema.BodySchema{
Attributes: map[string]*schema.AttributeSchema{
"when": {
ValueType: cty.DynamicPseudoType,
Expr: schema.ExprConstraints{
schema.KeywordExpr{
Keyword: "create",
Description: lang.Markdown("Run the provisioner when the resource is created"),
},
schema.KeywordExpr{
Keyword: "destroy",
Description: lang.Markdown("Run the provisioner when the resource is destroyed"),
},
},
IsOptional: true,
Description: lang.Markdown("When to run the provisioner - `create` or `destroy`, defaults to `create` " +
"(i.e. after creation of the resource)"),
},
"on_failure": {
IsOptional: true,
ValueType: cty.DynamicPseudoType,
Expr: schema.ExprConstraints{
schema.KeywordExpr{
Keyword: "fail",
Description: lang.Markdown("Raise an error and stop applying (the default behavior). If this is a creation provisioner, taint the resource."),
},
schema.KeywordExpr{
Keyword: "continue",
Description: lang.Markdown("Ignore the error and continue with creation or destruction"),
},
},
Description: lang.Markdown("What to do when the provisioner run fails to finish - `fail` (default), " +
"or `continue` (ignore the error)"),
},
Expand All @@ -125,7 +149,16 @@ var connectionBlock = &schema.BlockSchema{
Body: &schema.BodySchema{
Attributes: map[string]*schema.AttributeSchema{
"type": {
ValueType: cty.String,
Expr: schema.ExprConstraints{
schema.LiteralValue{
Val: cty.StringVal("ssh"),
Description: lang.Markdown("Use SSH to connect and provision the instance"),
},
schema.LiteralValue{
Val: cty.StringVal("winrm"),
Description: lang.Markdown("Use WinRM to connect and provision the instance"),
},
},
IsOptional: true,
Description: lang.Markdown("Connection type to use - `ssh` (default) or `winrm`"),
},
Expand Down
26 changes: 19 additions & 7 deletions internal/schema/0.12/terraform_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func terraformBlockSchema(v *version.Version) *schema.BlockSchema {
Body: &schema.BodySchema{
Attributes: map[string]*schema.AttributeSchema{
"required_version": {
ValueType: cty.String,
Expr: schema.LiteralTypeOnly(cty.String),
IsOptional: true,
Description: lang.Markdown("Constraint to specify which versions of Terraform can be used " +
"with this configuration, e.g. `~> 0.12`"),
Expand All @@ -36,7 +36,7 @@ func terraformBlockSchema(v *version.Version) *schema.BlockSchema {
Description: lang.Markdown("What provider version to use within this configuration"),
Body: &schema.BodySchema{
AnyAttribute: &schema.AttributeSchema{
ValueType: cty.String,
Expr: schema.LiteralTypeOnly(cty.String),
Description: lang.Markdown("Version constraint"),
},
},
Expand All @@ -47,8 +47,20 @@ func terraformBlockSchema(v *version.Version) *schema.BlockSchema {
}

if v.GreaterThanOrEqual(v0_12_18) {
experiments := schema.TupleConsExpr{
AnyElem: schema.ExprConstraints{},
Name: "set of features",
}
if v.GreaterThanOrEqual(v0_12_20) {
experiments.AnyElem = append(experiments.AnyElem, schema.KeywordExpr{
Keyword: "variable_validation",
Name: "feature",
})
}
bs.Body.Attributes["experiments"] = &schema.AttributeSchema{
ValueType: cty.Set(cty.DynamicPseudoType),
Expr: schema.ExprConstraints{
experiments,
},
IsOptional: true,
Description: lang.Markdown("A set of experimental language features to enable"),
}
Expand All @@ -57,11 +69,11 @@ func terraformBlockSchema(v *version.Version) *schema.BlockSchema {
if v.GreaterThanOrEqual(v0_12_20) {
bs.Body.Blocks["required_providers"].Body = &schema.BodySchema{
AnyAttribute: &schema.AttributeSchema{
ValueTypes: schema.ValueTypes{
cty.Object(map[string]cty.Type{
Expr: schema.ExprConstraints{
schema.LiteralTypeExpr{Type: cty.Object(map[string]cty.Type{
"version": cty.String,
}),
cty.String,
})},
schema.LiteralTypeExpr{Type: cty.String},
},
Description: lang.Markdown("Version constraint"),
},
Expand Down
Loading

0 comments on commit f1e5742

Please sign in to comment.