Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use explicit IsOptional and change ReadOnly to Computed #3

Merged
merged 3 commits into from
Nov 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/google/go-cmp v0.3.1
github.com/hashicorp/go-multierror v1.1.0
github.com/hashicorp/go-version v1.2.0
github.com/hashicorp/hcl-lang v0.0.0-20201106164120-ed150d21ec05
github.com/hashicorp/hcl-lang v0.0.0-20201110071249-4e412924f52b
github.com/hashicorp/hcl/v2 v2.6.0
github.com/hashicorp/terraform-config-inspect v0.0.0-20201021083235-edf96fe612be
github.com/hashicorp/terraform-json v0.6.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ github.com/hashicorp/go-version v1.2.0 h1:3vNe/fWF5CBgRIguda1meWhsZHy3m8gCJ5wx+d
github.com/hashicorp/go-version v1.2.0/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-20201106164120-ed150d21ec05 h1:ww+H+xN5sPYDje6Dur2ChUSlHhGI6fBiZs/PIWmdplU=
github.com/hashicorp/hcl-lang v0.0.0-20201106164120-ed150d21ec05/go.mod h1:A0mcesqbT4EQkWw/CMBBp8pM5kl8wEekshClBJRGeUw=
github.com/hashicorp/hcl-lang v0.0.0-20201110071249-4e412924f52b h1:EjnMRaTQlomBMNRQfyWoLEg9IdqxeN1R2mb3ZZetCBs=
github.com/hashicorp/hcl-lang v0.0.0-20201110071249-4e412924f52b/go.mod h1:vd3BPEDWrYMAgAnB0MRlBdZknrpUXf8Jk2PNaHIbwhg=
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=
Expand Down
4 changes: 4 additions & 0 deletions internal/schema/0.12/data_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,18 @@ func datasourceBlockSchema(v *version.Version) *schema.BlockSchema {
Attributes: map[string]*schema.AttributeSchema{
"provider": {
ValueType: cty.DynamicPseudoType,
IsOptional: true,
Description: lang.Markdown("Reference to a `provider` configuration block, e.g. `mycloud.west` or `mycloud`"),
IsDepKey: true,
},
"count": {
ValueType: cty.Number,
IsOptional: true,
Description: lang.Markdown("Number of instances of this data source, e.g. `3`"),
},
"depends_on": {
ValueType: cty.Set(cty.DynamicPseudoType),
IsOptional: true,
Description: lang.Markdown("Set of references to hidden dependencies, e.g. other resources or data sources"),
},
},
Expand All @@ -48,6 +51,7 @@ func datasourceBlockSchema(v *version.Version) *schema.BlockSchema {
cty.Set(cty.DynamicPseudoType),
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
18 changes: 10 additions & 8 deletions internal/schema/0.12/module_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,23 @@ var moduleBlockSchema = &schema.BlockSchema{
Body: &schema.BodySchema{
Attributes: map[string]*schema.AttributeSchema{
"source": {
ValueType: 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 "+
ValueType: 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 " +
"`github.com/hashicorp/example` (GitHub)"),
IsRequired: true,
IsDepKey: true,
IsRequired: true,
IsDepKey: true,
},
"version": {
ValueType: cty.String,
Description: lang.Markdown("Constraint to set the version of the module, e.g. `~> 1.0`."+
ValueType: 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),
IsOptional: true,
Description: lang.Markdown("Explicit mapping of providers which the module uses"),
},
},
Expand Down
3 changes: 3 additions & 0 deletions internal/schema/0.12/output_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ var outputBlockSchema = &schema.BlockSchema{
Attributes: map[string]*schema.AttributeSchema{
"description": {
ValueType: cty.String,
IsOptional: true,
Description: lang.PlainText("Human-readable description of the output (for documentation and UI)"),
},
"value": {
Expand All @@ -27,10 +28,12 @@ var outputBlockSchema = &schema.BlockSchema{
},
"sensitive": {
ValueType: 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),
IsOptional: true,
Description: lang.PlainText("Set of references to hidden dependencies (e.g. resources or data sources)"),
},
},
Expand Down
2 changes: 2 additions & 0 deletions internal/schema/0.12/provider_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ func providerBlockSchema(v *version.Version) *schema.BlockSchema {
Attributes: map[string]*schema.AttributeSchema{
"alias": {
ValueType: 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,
IsOptional: true,
Description: lang.Markdown("Specifies a version constraint for the provider, e.g. `~> 1.0`"),
},
},
Expand Down
18 changes: 14 additions & 4 deletions internal/schema/0.12/resource_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,18 @@ func resourceBlockSchema(v *version.Version) *schema.BlockSchema {
Attributes: map[string]*schema.AttributeSchema{
"provider": {
ValueType: cty.DynamicPseudoType,
IsOptional: true,
Description: lang.Markdown("Reference to a `provider` configuration block, e.g. `mycloud.west` or `mycloud`"),
IsDepKey: true,
},
"count": {
ValueType: cty.Number,
IsOptional: true,
Description: lang.Markdown("Number of instances of this resource, e.g. `3`"),
},
"depends_on": {
ValueType: cty.Set(cty.DynamicPseudoType),
IsOptional: true,
Description: lang.Markdown("Set of references to hidden dependencies, e.g. other resources or data sources"),
},
},
Expand All @@ -52,6 +55,7 @@ func resourceBlockSchema(v *version.Version) *schema.BlockSchema {
cty.Set(cty.DynamicPseudoType),
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 @@ -64,17 +68,20 @@ var lifecycleBlock = &schema.BlockSchema{
Body: &schema.BodySchema{
Attributes: map[string]*schema.AttributeSchema{
"create_before_destroy": {
ValueType: cty.Bool,
ValueType: 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,
ValueType: 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),
IsOptional: true,
Description: lang.Markdown("A set of fields (references) of which to ignore changes to, e.g. `tags`"),
},
},
Expand All @@ -94,12 +101,14 @@ var provisionerBlock = &schema.BlockSchema{
Body: &schema.BodySchema{
Attributes: map[string]*schema.AttributeSchema{
"when": {
ValueType: cty.DynamicPseudoType,
ValueType: cty.DynamicPseudoType,
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": {
ValueType: cty.DynamicPseudoType,
IsOptional: true,
ValueType: cty.DynamicPseudoType,
Description: lang.Markdown("What to do when the provisioner run fails to finish - `fail` (default), " +
"or `continue` (ignore the error)"),
},
Expand All @@ -117,6 +126,7 @@ var connectionBlock = &schema.BlockSchema{
Attributes: map[string]*schema.AttributeSchema{
"type": {
ValueType: cty.String,
IsOptional: true,
Description: lang.Markdown("Connection type to use - `ssh` (default) or `winrm`"),
},
},
Expand Down
8 changes: 5 additions & 3 deletions internal/schema/0.12/terraform_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ func terraformBlockSchema(v *version.Version) *schema.BlockSchema {
Body: &schema.BodySchema{
Attributes: map[string]*schema.AttributeSchema{
"required_version": {
ValueType: cty.String,
Description: lang.Markdown("Constraint to specify which versions of Terraform can be used "+
ValueType: cty.String,
IsOptional: true,
Description: lang.Markdown("Constraint to specify which versions of Terraform can be used " +
"with this configuration, e.g. `~> 0.12`"),
},
},
Blocks: map[string]*schema.BlockSchema{
"backend": {
Description: lang.Markdown("Backend configuration which defines exactly where and how "+
Description: lang.Markdown("Backend configuration which defines exactly where and how " +
"operations are performed, where state snapshots are stored, etc."),
Labels: []*schema.LabelSchema{
{
Expand Down Expand Up @@ -48,6 +49,7 @@ func terraformBlockSchema(v *version.Version) *schema.BlockSchema {
if v.GreaterThanOrEqual(v0_12_18) {
bs.Body.Attributes["experiments"] = &schema.AttributeSchema{
ValueType: cty.Set(cty.DynamicPseudoType),
IsOptional: true,
Description: lang.Markdown("A set of experimental language features to enable"),
}
}
Expand Down
3 changes: 3 additions & 0 deletions internal/schema/0.12/variable_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,17 @@ func variableBlockSchema(v *version.Version) *schema.BlockSchema {
Attributes: map[string]*schema.AttributeSchema{
"description": {
ValueType: cty.String,
IsOptional: true,
Description: lang.Markdown("Description to document the purpose of the variable and what value is expected"),
},
"type": {
ValueType: cty.DynamicPseudoType,
IsOptional: true,
Description: lang.Markdown("Type constraint restricting the type of value to accept, e.g. `string` or `list(string)`"),
},
"default": {
ValueType: cty.DynamicPseudoType,
IsOptional: true,
Description: lang.Markdown("Default value to use when variable is not explicitly set"),
},
},
Expand Down
21 changes: 13 additions & 8 deletions internal/schema/0.13/module_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,36 +17,41 @@ var moduleBlockSchema = &schema.BlockSchema{
Body: &schema.BodySchema{
Attributes: map[string]*schema.AttributeSchema{
"source": {
ValueType: 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 "+
ValueType: 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 " +
"`github.com/hashicorp/example` (GitHub)"),
IsRequired: true,
IsDepKey: true,
IsRequired: true,
IsDepKey: true,
},
"version": {
ValueType: cty.String,
Description: lang.Markdown("Constraint to set the version of the module, e.g. `~> 1.0`."+
ValueType: 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),
IsOptional: true,
Description: lang.Markdown("Explicit mapping of providers which the module uses"),
},
"count": {
ValueType: cty.Number,
IsOptional: true,
Description: lang.Markdown("Number of instances of this module, e.g. `3`"),
},
"for_each": {
ValueTypes: schema.ValueTypes{
cty.Set(cty.DynamicPseudoType),
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": {
ValueType: cty.Set(cty.DynamicPseudoType),
IsOptional: true,
Description: lang.Markdown("Set of references to hidden dependencies, e.g. other resources or data sources"),
},
},
Expand Down
2 changes: 2 additions & 0 deletions internal/schema/0.13/provider_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ var providerBlockSchema = &schema.BlockSchema{
Attributes: map[string]*schema.AttributeSchema{
"alias": {
ValueType: 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,
IsOptional: true,
IsDeprecated: true,
Description: lang.Markdown("Specifies a version constraint for the provider. e.g. `~> 1.0`.\n" +
"**DEPRECATED:** Use `required_providers` block to manage provider version instead."),
Expand Down
14 changes: 8 additions & 6 deletions internal/schema/0.13/terraform_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,21 @@ var terraformBlockSchema = &schema.BlockSchema{
Body: &schema.BodySchema{
Attributes: map[string]*schema.AttributeSchema{
"required_version": {
ValueType: cty.String,
Description: lang.Markdown("Constraint to specify which versions of Terraform can be used "+
"with this configuration, e.g. `~> 0.12`"),
ValueType: cty.String,
IsOptional: true,
Description: lang.Markdown("Constraint to specify which versions of Terraform can be used " +
"with this configuration, e.g. `~> 0.12`"),
},
"experiments": {
ValueType: cty.Set(cty.DynamicPseudoType),
IsOptional: true,
Description: lang.Markdown("A set of experimental language features to enable"),
},
},
Blocks: map[string]*schema.BlockSchema{
"backend": {
Description: lang.Markdown("Backend configuration which defines exactly where and how "+
"operations are performed, where state snapshots are stored, etc."),
Description: lang.Markdown("Backend configuration which defines exactly where and how " +
"operations are performed, where state snapshots are stored, etc."),
Labels: []*schema.LabelSchema{
{
Name: "type",
Expand All @@ -43,7 +45,7 @@ var terraformBlockSchema = &schema.BlockSchema{
},
},
"required_providers": {
Description: lang.Markdown("What provider version to use within this configuration "+
Description: lang.Markdown("What provider version to use within this configuration " +
"and where to source it from"),
Body: &schema.BodySchema{
AnyAttribute: &schema.AttributeSchema{
Expand Down
6 changes: 5 additions & 1 deletion internal/schema/0.14/variable_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,22 @@ var variableBlockSchema = &schema.BlockSchema{
Attributes: map[string]*schema.AttributeSchema{
"description": {
ValueType: cty.String,
IsOptional: true,
Description: lang.Markdown("Description to document the purpose of the variable and what value is expected"),
},
"type": {
ValueType: cty.DynamicPseudoType,
IsOptional: true,
Description: lang.Markdown("Type constraint restricting the type of value to accept, e.g. `string` or `list(string)`"),
},
"default": {
ValueType: cty.DynamicPseudoType,
IsOptional: true,
Description: lang.Markdown("Default value to use when variable is not explicitly set"),
},
"sensitive": {
ValueType: cty.Bool,
ValueType: cty.Bool,
IsOptional: true,
Description: lang.Markdown("Whether the variable contains sensitive material and should be hidden in the UI"),
},
},
Expand Down
1 change: 1 addition & 0 deletions internal/schema/universal/data_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ var datasourceBlockSchema = &schema.BlockSchema{
Attributes: map[string]*schema.AttributeSchema{
"provider": {
ValueType: cty.DynamicPseudoType,
IsOptional: true,
Description: lang.Markdown("Reference to a `provider` configuration block, e.g. `mycloud.west` or `mycloud`"),
IsDepKey: true,
},
Expand Down
1 change: 1 addition & 0 deletions internal/schema/universal/provider_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ var providerBlockSchema = &schema.BlockSchema{
Attributes: map[string]*schema.AttributeSchema{
"alias": {
ValueType: cty.String,
IsOptional: true,
Description: lang.Markdown("Alias for using the same provider with different configurations for different resources, e.g. `eu-west`"),
},
},
Expand Down
1 change: 1 addition & 0 deletions internal/schema/universal/resource_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ var resourceBlockSchema = &schema.BlockSchema{
Attributes: map[string]*schema.AttributeSchema{
"provider": {
ValueType: cty.DynamicPseudoType,
IsOptional: true,
Description: lang.Markdown("Reference to a `provider` configuration block, e.g. `mycloud.west` or `mycloud`"),
IsDepKey: true,
},
Expand Down
Loading