-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
schema: add versioned schemas for some blocks
- Loading branch information
1 parent
3b7b040
commit 2a2e42c
Showing
24 changed files
with
1,068 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
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 datasourceBlockSchema(v *version.Version) *schema.BlockSchema { | ||
bs := &schema.BlockSchema{ | ||
Labels: []*schema.LabelSchema{ | ||
{ | ||
Name: "type", | ||
Description: lang.PlainText("Data Source Type"), | ||
IsDepKey: true, | ||
}, | ||
{ | ||
Name: "name", | ||
Description: lang.PlainText("Reference Name"), | ||
}, | ||
}, | ||
Description: lang.PlainText("A data block requests that Terraform read from a given data source and export the result " + | ||
"under the given local name. The name is used to refer to this resource from elsewhere in the same " + | ||
"Terraform module, but has no significance outside of the scope of a module."), | ||
Body: &schema.BodySchema{ | ||
Attributes: map[string]*schema.AttributeSchema{ | ||
"provider": { | ||
ValueType: cty.DynamicPseudoType, | ||
Description: lang.Markdown("Reference to a `provider` configuration block, e.g. `mycloud.west` or `mycloud`"), | ||
IsDepKey: true, | ||
}, | ||
"count": { | ||
ValueType: cty.Number, | ||
Description: lang.Markdown("Number of instances of this data source, e.g. `3`"), | ||
}, | ||
"depends_on": { | ||
ValueType: cty.Set(cty.DynamicPseudoType), | ||
Description: lang.Markdown("Set of references to hidden dependencies, e.g. other resources or data sources"), | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
if v.GreaterThanOrEqual(v0_12_6) { | ||
bs.Body.Attributes["for_each"] = &schema.AttributeSchema{ | ||
ValueTypes: schema.ValueTypes{ | ||
cty.Set(cty.DynamicPseudoType), | ||
cty.Map(cty.DynamicPseudoType), | ||
}, | ||
Description: lang.Markdown("A set or a map where each item represents an instance of this data source"), | ||
} | ||
} | ||
|
||
return bs | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package schema | ||
|
||
import ( | ||
"github.com/hashicorp/hcl-lang/lang" | ||
"github.com/hashicorp/hcl-lang/schema" | ||
) | ||
|
||
var localsBlockSchema = &schema.BlockSchema{ | ||
Description: lang.Markdown("Local values assigning names to expressions, so you can use these multiple times without repetition\n" + | ||
"e.g. `service_name = \"forum\"`"), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package schema | ||
|
||
import ( | ||
"github.com/hashicorp/hcl-lang/lang" | ||
"github.com/hashicorp/hcl-lang/schema" | ||
"github.com/zclconf/go-cty/cty" | ||
) | ||
|
||
var moduleBlockSchema = &schema.BlockSchema{ | ||
Labels: []*schema.LabelSchema{ | ||
{ | ||
Name: "name", | ||
Description: lang.PlainText("Reference Name"), | ||
}, | ||
}, | ||
Description: lang.PlainText("TODO"), | ||
Body: &schema.BodySchema{ | ||
Attributes: map[string]*schema.AttributeSchema{ | ||
"source": { | ||
ValueType: cty.String, | ||
Description: lang.Markdown("TODO"), | ||
IsRequired: true, | ||
IsDepKey: true, | ||
}, | ||
"version": { | ||
ValueType: cty.String, | ||
Description: lang.Markdown("TODO"), | ||
}, | ||
"providers": { | ||
ValueType: cty.Map(cty.DynamicPseudoType), | ||
Description: lang.Markdown("TODO"), | ||
}, | ||
}, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package schema | ||
|
||
import ( | ||
"github.com/hashicorp/hcl-lang/lang" | ||
"github.com/hashicorp/hcl-lang/schema" | ||
"github.com/zclconf/go-cty/cty" | ||
) | ||
|
||
var outputBlockSchema = &schema.BlockSchema{ | ||
Labels: []*schema.LabelSchema{ | ||
{ | ||
Name: "name", | ||
Description: lang.PlainText("Output Name"), | ||
}, | ||
}, | ||
Description: lang.PlainText("Output value for consumption by another module or a human interacting via the UI"), | ||
Body: &schema.BodySchema{ | ||
Attributes: map[string]*schema.AttributeSchema{ | ||
"description": { | ||
ValueType: cty.String, | ||
Description: lang.PlainText("Human-readable description of the output (for documentation and UI)"), | ||
}, | ||
"value": { | ||
ValueType: cty.DynamicPseudoType, | ||
IsRequired: true, | ||
Description: lang.PlainText("Value, typically a reference to an attribute of a resource or a data source"), | ||
}, | ||
"sensitive": { | ||
ValueType: cty.Bool, | ||
Description: lang.PlainText("Whether the output contains sensitive material and should be hidden in the UI"), | ||
}, | ||
"depends_on": { | ||
ValueType: cty.Set(cty.DynamicPseudoType), | ||
Description: lang.PlainText("Set of references to hidden dependencies (e.g. resources or data sources)"), | ||
}, | ||
}, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
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 providerBlockSchema(v *version.Version) *schema.BlockSchema { | ||
return &schema.BlockSchema{ | ||
Labels: []*schema.LabelSchema{ | ||
{ | ||
Name: "name", | ||
Description: lang.PlainText("Provider Name"), | ||
IsDepKey: true, | ||
}, | ||
}, | ||
Description: lang.PlainText("A provider block is used to specify a provider configuration"), | ||
Body: &schema.BodySchema{ | ||
Attributes: map[string]*schema.AttributeSchema{ | ||
"alias": { | ||
ValueType: cty.String, | ||
Description: lang.Markdown("Alias for using the same provider with different configurations for different resources, e.g. `eu-west`"), | ||
}, | ||
"version": { | ||
ValueType: cty.String, | ||
Description: lang.Markdown("Specifies a version constraint for the provider, e.g. `~> 1.0`"), | ||
}, | ||
}, | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
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 resourceBlockSchema(v *version.Version) *schema.BlockSchema { | ||
bs := &schema.BlockSchema{ | ||
Labels: []*schema.LabelSchema{ | ||
{ | ||
Name: "type", | ||
Description: lang.PlainText("Resource Type"), | ||
IsDepKey: true, | ||
}, | ||
{ | ||
Name: "name", | ||
Description: lang.PlainText("Reference Name"), | ||
}, | ||
}, | ||
Description: lang.PlainText("A resource block declares a resource of a given type with a given local name. The name is " + | ||
"used to refer to this resource from elsewhere in the same Terraform module, but has no significance " + | ||
"outside of the scope of a module."), | ||
Body: &schema.BodySchema{ | ||
Attributes: map[string]*schema.AttributeSchema{ | ||
"provider": { | ||
ValueType: cty.DynamicPseudoType, | ||
Description: lang.Markdown("Reference to a `provider` configuration block, e.g. `mycloud.west` or `mycloud`"), | ||
IsDepKey: true, | ||
}, | ||
"count": { | ||
ValueType: cty.Number, | ||
Description: lang.Markdown("Number of instances of this resource, e.g. `3`"), | ||
}, | ||
"depends_on": { | ||
ValueType: cty.Set(cty.DynamicPseudoType), | ||
Description: lang.Markdown("Set of references to hidden dependencies, e.g. other resources or data sources"), | ||
}, | ||
}, | ||
Blocks: map[string]*schema.BlockSchema{ | ||
"lifecycle": lifecycleBlock, | ||
"connection": connectionBlock, | ||
}, | ||
}, | ||
} | ||
|
||
if v.GreaterThanOrEqual(v0_12_6) { | ||
bs.Body.Attributes["for_each"] = &schema.AttributeSchema{ | ||
ValueTypes: schema.ValueTypes{ | ||
cty.Set(cty.DynamicPseudoType), | ||
cty.Map(cty.DynamicPseudoType), | ||
}, | ||
Description: lang.Markdown("A set or a map where each item represents an instance of this resource"), | ||
} | ||
} | ||
|
||
return bs | ||
} | ||
|
||
var lifecycleBlock = &schema.BlockSchema{ | ||
Description: lang.Markdown("Lifecycle customizations to change default resource behaviours during apply"), | ||
Body: &schema.BodySchema{ | ||
Attributes: map[string]*schema.AttributeSchema{ | ||
"create_before_destroy": { | ||
ValueType: cty.Bool, | ||
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, | ||
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), | ||
Description: lang.Markdown("A set of fields (references) of which to ignore changes to, e.g. `tags`"), | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
var provisionerBlock = &schema.BlockSchema{ | ||
Description: lang.Markdown("Provisioner to model specific actions on the local machine or on a remote machine " + | ||
"in order to prepare servers or other infrastructure objects for service"), | ||
Labels: []*schema.LabelSchema{ | ||
{ | ||
Name: "type", | ||
Description: lang.PlainText("Type of provisioner to use, e.g. `remote-exec` or `file`"), | ||
IsDepKey: true, | ||
}, | ||
}, | ||
Body: &schema.BodySchema{ | ||
Attributes: map[string]*schema.AttributeSchema{ | ||
"when": { | ||
ValueType: cty.DynamicPseudoType, | ||
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, | ||
Description: lang.Markdown("What to do when the provisioner run fails to finish - `fail` (default), " + | ||
"or `continue` (ignore the error)"), | ||
}, | ||
}, | ||
Blocks: map[string]*schema.BlockSchema{ | ||
"connection": connectionBlock, | ||
}, | ||
}, | ||
} | ||
|
||
var connectionBlock = &schema.BlockSchema{ | ||
Description: lang.Markdown("Connection block describing how the provisioner connects to the given instance"), | ||
MaxItems: 1, | ||
Body: &schema.BodySchema{ | ||
Attributes: map[string]*schema.AttributeSchema{ | ||
"type": { | ||
ValueType: cty.String, | ||
Description: lang.Markdown("Connection type to use - `ssh` (default) or `winrm`"), | ||
}, | ||
}, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package schema | ||
|
||
import ( | ||
"github.com/hashicorp/go-version" | ||
"github.com/hashicorp/hcl-lang/schema" | ||
) | ||
|
||
var ( | ||
v0_12_6 = version.Must(version.NewVersion("0.12.6")) | ||
v0_12_18 = version.Must(version.NewVersion("0.12.18")) | ||
v0_12_20 = version.Must(version.NewVersion("0.12.20")) | ||
) | ||
|
||
func ModuleSchema(v *version.Version) *schema.BodySchema { | ||
return &schema.BodySchema{ | ||
Blocks: map[string]*schema.BlockSchema{ | ||
"data": datasourceBlockSchema(v), | ||
"locals": localsBlockSchema, | ||
"module": moduleBlockSchema, | ||
"output": outputBlockSchema, | ||
"provider": providerBlockSchema(v), | ||
"resource": resourceBlockSchema(v), | ||
"variable": variableBlockSchema(v), | ||
"terraform": terraformBlockSchema(v), | ||
}, | ||
} | ||
} |
Oops, something went wrong.