Skip to content

Commit

Permalink
refactored tenant project schema
Browse files Browse the repository at this point in the history
  • Loading branch information
benPearce1 committed Aug 29, 2024
1 parent 24f25c1 commit cff29a6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 29 deletions.
26 changes: 1 addition & 25 deletions octopusdeploy_framework/resource_tenant_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,31 +34,7 @@ func (t *tenantProjectResource) Metadata(ctx context.Context, req resource.Metad
}

func (t *tenantProjectResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) {
resp.Schema = schema.Schema{
Attributes: map[string]schema.Attribute{
"id": schemas.GetIdResourceSchema(),
"tenant_id": schema.StringAttribute{
Description: "The tenant ID associated with this tenant.",
Required: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.RequiresReplace(),
},
},
"project_id": schema.StringAttribute{
Description: "The project ID associated with this tenant.",
Required: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.RequiresReplace(),
},
},
"environment_ids": schema.ListAttribute{
Description: "The environment IDs associated with this tenant.",
ElementType: types.StringType,
Optional: true,
},
"space_id": schemas.GetSpaceIdResourceSchema("project tenant"),
}}
resp.Schema = schemas.GetTenantProjectsResourceSchema()
resp.Schema = schemas.TenantProjectsSchema{}.GetResourceSchema()
}

func (t *tenantProjectResource) Configure(_ context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) {
Expand Down
1 change: 1 addition & 0 deletions octopusdeploy_framework/schemas/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ var testableSchemas = []EntitySchema{
VariableSchema{},
TenantProjectVariableSchema{},
TenantSchema{},
TenantProjectsSchema{},
}

func TestDatasourceSchemaDefinitionIsUsingCorrectTypes(t *testing.T) {
Expand Down
11 changes: 7 additions & 4 deletions octopusdeploy_framework/schemas/tenant_projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package schemas
import (
"fmt"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/tenants"
"github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/util"
"github.com/hashicorp/terraform-plugin-framework/attr"
datasourceSchema "github.com/hashicorp/terraform-plugin-framework/datasource/schema"
resourceSchema "github.com/hashicorp/terraform-plugin-framework/resource/schema"
Expand All @@ -29,7 +28,11 @@ type TenantProjectResourceModel struct {
ResourceModel
}

func GetTenantProjectsDataSourceSchema() datasourceSchema.Schema {
type TenantProjectsSchema struct{}

var _ EntitySchema = TenantProjectsSchema{}

func (t TenantProjectsSchema) GetDatasourceSchema() datasourceSchema.Schema {
return datasourceSchema.Schema{
Description: "Provides information about existing tenants.",
Attributes: map[string]datasourceSchema.Attribute{
Expand Down Expand Up @@ -64,10 +67,10 @@ func GetTenantProjectsDataSourceSchema() datasourceSchema.Schema {
}
}

func GetTenantProjectsResourceSchema() resourceSchema.Schema {
func (t TenantProjectsSchema) GetResourceSchema() resourceSchema.Schema {
return resourceSchema.Schema{
Attributes: map[string]resourceSchema.Attribute{
"id": util.GetIdResourceSchema(),
"id": GetIdResourceSchema(),
"tenant_id": resourceSchema.StringAttribute{
Description: "The tenant ID associated with this tenant.",
Required: true,
Expand Down

0 comments on commit cff29a6

Please sign in to comment.