diff --git a/go.mod b/go.mod index c0968703..ebb6e02b 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/google/go-cmp v0.5.5 github.com/hashicorp/go-multierror v1.1.0 github.com/hashicorp/go-version v1.2.1 - github.com/hashicorp/hcl-lang v0.0.0-20210305083102-791d1fc99bad + github.com/hashicorp/hcl-lang v0.0.0-20210310132837-df95a1d6c312 github.com/hashicorp/hcl/v2 v2.9.0 github.com/hashicorp/terraform-config-inspect v0.0.0-20201102131242-0c45ba392e51 github.com/hashicorp/terraform-json v0.8.0 diff --git a/go.sum b/go.sum index 21a77ba6..f5440c79 100644 --- a/go.sum +++ b/go.sum @@ -31,8 +31,8 @@ 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-20210305083102-791d1fc99bad h1:ynQREphl/QqetQnYIWergBwcuxunJYwhaGxGALgwjzU= -github.com/hashicorp/hcl-lang v0.0.0-20210305083102-791d1fc99bad/go.mod h1:Ga5F2eYh9HyR2eHBYBa49VdoTkkC/7ob1cV8Mpvhg5M= +github.com/hashicorp/hcl-lang v0.0.0-20210310132837-df95a1d6c312 h1:/L/NtivZi3ZjLbPmD7mJy6TKsrYNjJWvL1yMI6KUqO8= +github.com/hashicorp/hcl-lang v0.0.0-20210310132837-df95a1d6c312/go.mod h1:Ga5F2eYh9HyR2eHBYBa49VdoTkkC/7ob1cV8Mpvhg5M= github.com/hashicorp/hcl/v2 v2.0.0/go.mod h1:oVVDG71tEinNGYCxinCYadcmKU9bglqW9pV3txagJ90= github.com/hashicorp/hcl/v2 v2.9.0 h1:7kJiMiKBqGHASbDJuFAMlpRMJLyhuLg/IsU/3EzwniA= github.com/hashicorp/hcl/v2 v2.9.0/go.mod h1:FwWsfWEjyV/CMj8s/gqAuiviY72rJ1/oayI9WftqcKg= diff --git a/internal/schema/0.12/resource_block.go b/internal/schema/0.12/resource_block.go index e6a3fc3f..3e607fde 100644 --- a/internal/schema/0.12/resource_block.go +++ b/internal/schema/0.12/resource_block.go @@ -86,6 +86,11 @@ var lifecycleBlock = &schema.BlockSchema{ "ignore_changes": { Expr: schema.ExprConstraints{ schema.TupleConsExpr{}, + schema.KeywordExpr{ + Keyword: "all", + Description: lang.Markdown("Ignore all attributes, which means that Terraform can create" + + " and destroy the remote object but will never propose updates to it"), + }, }, IsOptional: true, Description: lang.Markdown("A set of fields (references) of which to ignore changes to, e.g. `tags`"), diff --git a/internal/schema/0.12/terraform_block.go b/internal/schema/0.12/terraform_block.go index ba64e29d..661b680e 100644 --- a/internal/schema/0.12/terraform_block.go +++ b/internal/schema/0.12/terraform_block.go @@ -70,9 +70,15 @@ func terraformBlockSchema(v *version.Version) *schema.BlockSchema { bs.Body.Blocks["required_providers"].Body = &schema.BodySchema{ AnyAttribute: &schema.AttributeSchema{ Expr: schema.ExprConstraints{ - schema.LiteralTypeExpr{Type: cty.Object(map[string]cty.Type{ - "version": cty.String, - })}, + schema.ObjectExpr{ + Attributes: schema.ObjectExprAttributes{ + "version": schema.ObjectAttribute{ + Expr: schema.LiteralTypeOnly(cty.String), + Description: lang.Markdown("Version constraint specifying which subset of " + + "available provider versions the module is compatible with, e.g. `~> 1.0`"), + }, + }, + }, schema.LiteralTypeExpr{Type: cty.String}, }, Description: lang.Markdown("Version constraint"), diff --git a/internal/schema/0.13/terraform_block.go b/internal/schema/0.13/terraform_block.go index f4b19d4d..14e8113b 100644 --- a/internal/schema/0.13/terraform_block.go +++ b/internal/schema/0.13/terraform_block.go @@ -54,10 +54,20 @@ var terraformBlockSchema = &schema.BlockSchema{ Body: &schema.BodySchema{ AnyAttribute: &schema.AttributeSchema{ Expr: schema.ExprConstraints{ - schema.LiteralTypeExpr{Type: cty.Object(map[string]cty.Type{ - "source": cty.String, - "version": cty.String, - })}, + schema.ObjectExpr{ + Attributes: schema.ObjectExprAttributes{ + "source": schema.ObjectAttribute{ + Expr: schema.LiteralTypeOnly(cty.String), + Description: lang.Markdown("The global source address for the provider " + + "you intend to use, such as `hashicorp/aws`"), + }, + "version": schema.ObjectAttribute{ + Expr: schema.LiteralTypeOnly(cty.String), + Description: lang.Markdown("Version constraint specifying which subset of " + + "available provider versions the module is compatible with, e.g. `~> 1.0`"), + }, + }, + }, schema.LiteralTypeExpr{Type: cty.String}, }, Description: lang.Markdown("Provider source and version constraint"), diff --git a/internal/schema/0.14/terraform.go b/internal/schema/0.14/terraform.go index dee940f4..d941decd 100644 --- a/internal/schema/0.14/terraform.go +++ b/internal/schema/0.14/terraform.go @@ -66,10 +66,20 @@ func terraformBlockSchema(v *version.Version) *schema.BlockSchema { Body: &schema.BodySchema{ AnyAttribute: &schema.AttributeSchema{ Expr: schema.ExprConstraints{ - schema.LiteralTypeExpr{Type: cty.Object(map[string]cty.Type{ - "source": cty.String, - "version": cty.String, - })}, + schema.ObjectExpr{ + Attributes: schema.ObjectExprAttributes{ + "source": schema.ObjectAttribute{ + Expr: schema.LiteralTypeOnly(cty.String), + Description: lang.Markdown("The global source address for the provider " + + "you intend to use, such as `hashicorp/aws`"), + }, + "version": schema.ObjectAttribute{ + Expr: schema.LiteralTypeOnly(cty.String), + Description: lang.Markdown("Version constraint specifying which subset of " + + "available provider versions the module is compatible with, e.g. `~> 1.0`"), + }, + }, + }, schema.LiteralTypeExpr{Type: cty.String}, }, Description: lang.Markdown("Provider source and version constraint"), diff --git a/internal/schema/0.15/root.go b/internal/schema/0.15/root.go new file mode 100644 index 00000000..ad95143f --- /dev/null +++ b/internal/schema/0.15/root.go @@ -0,0 +1,14 @@ +package schema + +import ( + "github.com/hashicorp/go-version" + "github.com/hashicorp/hcl-lang/schema" + + v014_mod "github.com/hashicorp/terraform-schema/internal/schema/0.14" +) + +func ModuleSchema(v *version.Version) *schema.BodySchema { + bs := v014_mod.ModuleSchema(v) + bs.Blocks["terraform"] = patchTerraformBlockSchema(bs.Blocks["terraform"], v) + return bs +} diff --git a/internal/schema/0.15/terraform.go b/internal/schema/0.15/terraform.go new file mode 100644 index 00000000..7fa3ace6 --- /dev/null +++ b/internal/schema/0.15/terraform.go @@ -0,0 +1,43 @@ +package schema + +import ( + "github.com/hashicorp/go-version" + "github.com/hashicorp/hcl-lang/lang" + "github.com/hashicorp/hcl-lang/schema" + "github.com/zclconf/go-cty/cty" +) + +func patchTerraformBlockSchema(bs *schema.BlockSchema, v *version.Version) *schema.BlockSchema { + bs.Body.Blocks["required_providers"].Body = &schema.BodySchema{ + AnyAttribute: &schema.AttributeSchema{ + Expr: schema.ExprConstraints{ + schema.ObjectExpr{ + Attributes: schema.ObjectExprAttributes{ + "source": schema.ObjectAttribute{ + Expr: schema.LiteralTypeOnly(cty.String), + Description: lang.Markdown("The global source address for the provider " + + "you intend to use, such as `hashicorp/aws`"), + }, + "version": schema.ObjectAttribute{ + Expr: schema.LiteralTypeOnly(cty.String), + Description: lang.Markdown("Version constraint specifying which subset of " + + "available provider versions the module is compatible with, e.g. `~> 1.0`"), + }, + "configuration_aliases": schema.ObjectAttribute{ + Expr: schema.ExprConstraints{ + schema.TupleConsExpr{ + Name: "set of aliases", + }, + }, + Description: lang.Markdown("Aliases under which to make the provider available, " + + "such as `[ aws.eu-west, aws.us-east ]`"), + }, + }, + }, + schema.LiteralTypeExpr{Type: cty.String}, + }, + Description: lang.Markdown("Provider source, version constraint and its aliases"), + }, + } + return bs +} diff --git a/schema/core_schema.go b/schema/core_schema.go index b7feb79f..483b8908 100644 --- a/schema/core_schema.go +++ b/schema/core_schema.go @@ -8,6 +8,7 @@ import ( mod_v0_12 "github.com/hashicorp/terraform-schema/internal/schema/0.12" mod_v0_13 "github.com/hashicorp/terraform-schema/internal/schema/0.13" mod_v0_14 "github.com/hashicorp/terraform-schema/internal/schema/0.14" + mod_v0_15 "github.com/hashicorp/terraform-schema/internal/schema/0.15" universal "github.com/hashicorp/terraform-schema/internal/schema/universal" ) @@ -15,6 +16,7 @@ var ( v0_12 = version.Must(version.NewVersion("0.12")) v0_13 = version.Must(version.NewVersion("0.13")) v0_14 = version.Must(version.NewVersion("0.14")) + v0_15 = version.Must(version.NewVersion("0.15")) ) // CoreModuleSchemaForVersion finds a module schema which is relevant @@ -26,6 +28,9 @@ func CoreModuleSchemaForVersion(v *version.Version) (*schema.BodySchema, error) return nil, fmt.Errorf("invalid version: %w", err) } + if ver.GreaterThanOrEqual(v0_15) { + return mod_v0_15.ModuleSchema(ver), nil + } if ver.GreaterThanOrEqual(v0_14) { return mod_v0_14.ModuleSchema(ver), nil }