Skip to content

Commit

Permalink
schema: Introduce 1.1 terraform cloud block
Browse files Browse the repository at this point in the history
  • Loading branch information
radeksimko committed Jun 28, 2022
1 parent 01dad3e commit 4e918b9
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 2 deletions.
14 changes: 14 additions & 0 deletions internal/schema/1.1/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package schema

import (
"github.com/hashicorp/go-version"
"github.com/hashicorp/hcl-lang/schema"

v015_mod "github.com/hashicorp/terraform-schema/internal/schema/0.15"
)

func ModuleSchema(v *version.Version) *schema.BodySchema {
bs := v015_mod.ModuleSchema(v)
bs.Blocks["terraform"] = patchTerraformBlockSchema(bs.Blocks["terraform"], v)
return bs
}
67 changes: 67 additions & 0 deletions internal/schema/1.1/terraform.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
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["cloud"] = &schema.BlockSchema{
Description: lang.PlainText("Terraform Cloud configuration"),
MaxItems: 1,
Body: &schema.BodySchema{
Attributes: map[string]*schema.AttributeSchema{
"hostname": {
Expr: schema.LiteralTypeOnly(cty.String),
IsOptional: true,
Description: lang.Markdown("The Terraform Enterprise hostname to connect to. " +
"This optional argument defaults to `app.terraform.io` for use with Terraform Cloud."),
},
"organization": {
Expr: schema.LiteralTypeOnly(cty.String),
IsRequired: true,
Description: lang.PlainText("The name of the organization containing the targeted workspace(s)."),
},
"token": {
Expr: schema.LiteralTypeOnly(cty.String),
IsOptional: true,
Description: lang.Markdown("The token used to authenticate with Terraform Cloud/Enterprise. " +
"Typically this argument should not be set, and `terraform login` used instead; " +
"your credentials will then be fetched from your CLI configuration file " +
"or configured credential helper."),
},
},
Blocks: map[string]*schema.BlockSchema{
"workspaces": {
Description: lang.Markdown("Workspace mapping strategy, either workspace `tags` or `name` is required."),
MaxItems: 1,
Body: &schema.BodySchema{
Attributes: map[string]*schema.AttributeSchema{
"name": {
Expr: schema.LiteralTypeOnly(cty.String),
IsOptional: true,
Description: lang.Markdown("The name of a single Terraform Cloud workspace " +
"to be used with this configuration When configured only the specified workspace " +
"can be used. This option conflicts with `tags`."),
},
"tags": {
Expr: schema.ExprConstraints{
schema.SetExpr{Elem: schema.LiteralTypeOnly(cty.String)},
},
IsOptional: true,
Description: lang.Markdown("A set of tags used to select remote Terraform Cloud workspaces" +
" to be used for this single configuration. New workspaces will automatically be tagged " +
"with these tag values. Generally, this is the primary and recommended strategy to use. " +
"This option conflicts with `name`."),
},
},
},
},
},
},
}

return bs
}
4 changes: 2 additions & 2 deletions internal/schema/1.2/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import (
"github.com/hashicorp/hcl-lang/schema"
"github.com/zclconf/go-cty/cty"

v015_mod "github.com/hashicorp/terraform-schema/internal/schema/0.15"
v1_1_mod "github.com/hashicorp/terraform-schema/internal/schema/1.1"
)

var v1_2 = version.Must(version.NewVersion("1.2.0"))

func ModuleSchema(v *version.Version) *schema.BodySchema {
bs := v015_mod.ModuleSchema(v)
bs := v1_1_mod.ModuleSchema(v)
if v.GreaterThanOrEqual(v1_2) {
bs.Blocks["data"].Body.Blocks = map[string]*schema.BlockSchema{
"lifecycle": datasourceLifecycleBlock,
Expand Down
5 changes: 5 additions & 0 deletions schema/core_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
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"
mod_v1_1 "github.com/hashicorp/terraform-schema/internal/schema/1.1"
mod_v1_2 "github.com/hashicorp/terraform-schema/internal/schema/1.2"
universal "github.com/hashicorp/terraform-schema/internal/schema/universal"
)
Expand All @@ -18,6 +19,7 @@ var (
v0_13 = version.Must(version.NewVersion("0.13"))
v0_14 = version.Must(version.NewVersion("0.14"))
v0_15 = version.Must(version.NewVersion("0.15"))
v1_1 = version.Must(version.NewVersion("1.1"))
v1_2 = version.Must(version.NewVersion("1.2"))
)

Expand All @@ -33,6 +35,9 @@ func CoreModuleSchemaForVersion(v *version.Version) (*schema.BodySchema, error)
if ver.GreaterThanOrEqual(v1_2) {
return mod_v1_2.ModuleSchema(ver), nil
}
if ver.GreaterThanOrEqual(v1_1) {
return mod_v1_1.ModuleSchema(ver), nil
}
if ver.GreaterThanOrEqual(v0_15) {
return mod_v0_15.ModuleSchema(ver), nil
}
Expand Down

0 comments on commit 4e918b9

Please sign in to comment.