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

Add project attribute to workspaces block #257

Merged
merged 3 commits into from
Sep 26, 2023
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
6 changes: 3 additions & 3 deletions internal/schema/1.1/terraform.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func patchTerraformBlockSchema(bs *schema.BlockSchema) *schema.BlockSchema {
Constraint: schema.LiteralType{Type: 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 " +
"to be used with this configuration. When configured only the specified workspace " +
"can be used. This option conflicts with `tags`."),
},
"tags": {
Expand All @@ -54,8 +54,8 @@ func patchTerraformBlockSchema(bs *schema.BlockSchema) *schema.BlockSchema {
},
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. " +
" 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`."),
},
},
Expand Down
17 changes: 17 additions & 0 deletions internal/schema/1.6/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package schema

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

v1_5_mod "github.com/hashicorp/terraform-schema/internal/schema/1.5"
)

func ModuleSchema(v *version.Version) *schema.BodySchema {
bs := v1_5_mod.ModuleSchema(v)
bs.Blocks["terraform"] = patchTerraformBlockSchema(bs.Blocks["terraform"])
return bs
}
41 changes: 41 additions & 0 deletions internal/schema/1.6/terraform.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package schema

import (
"github.com/hashicorp/hcl-lang/lang"
"github.com/hashicorp/hcl-lang/schema"
"github.com/zclconf/go-cty/cty"
)

func patchTerraformBlockSchema(bs *schema.BlockSchema) *schema.BlockSchema {
bs.Body.Blocks["cloud"].Body.Blocks["workspaces"].Body = &schema.BodySchema{
Attributes: map[string]*schema.AttributeSchema{
"name": {
Constraint: schema.LiteralType{Type: 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`."),
},
"project": {
Constraint: schema.LiteralType{Type: cty.String},
IsOptional: true,
Description: lang.PlainText("The name of a Terraform Cloud project. Workspaces that need creating will be created within this project."),
},
"tags": {
Constraint: schema.Set{
Elem: schema.LiteralType{Type: 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
}
5 changes: 5 additions & 0 deletions schema/core_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
mod_v1_2 "github.com/hashicorp/terraform-schema/internal/schema/1.2"
mod_v1_4 "github.com/hashicorp/terraform-schema/internal/schema/1.4"
mod_v1_5 "github.com/hashicorp/terraform-schema/internal/schema/1.5"
mod_v1_6 "github.com/hashicorp/terraform-schema/internal/schema/1.6"
)

var (
Expand All @@ -26,13 +27,17 @@ var (
v1_3 = version.Must(version.NewVersion("1.3"))
v1_4 = version.Must(version.NewVersion("1.4"))
v1_5 = version.Must(version.NewVersion("1.5"))
v1_6 = version.Must(version.NewVersion("1.6"))
)

// CoreModuleSchemaForVersion finds a module schema which is relevant
// for the given Terraform version.
// It will return error if such schema cannot be found.
func CoreModuleSchemaForVersion(v *version.Version) (*schema.BodySchema, error) {
ver := v.Core()
if ver.GreaterThanOrEqual(v1_6) {
return mod_v1_6.ModuleSchema(ver), nil
}
if ver.GreaterThanOrEqual(v1_5) {
return mod_v1_5.ModuleSchema(ver), nil
}
Expand Down