Skip to content

Commit

Permalink
migrated more to entity schema
Browse files Browse the repository at this point in the history
  • Loading branch information
benPearce1 committed Aug 27, 2024
1 parent 289f3b4 commit 8f6dc41
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 56 deletions.
6 changes: 1 addition & 5 deletions octopusdeploy_framework/resource_maven_feed.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/util"
"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-log/tflog"
)
Expand All @@ -32,10 +31,7 @@ func (r *mavenFeedTypeResource) Metadata(ctx context.Context, req resource.Metad
}

func (r *mavenFeedTypeResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) {
resp.Schema = schema.Schema{
Attributes: schemas.GetMavenFeedResourceSchema(),
Description: "This resource manages a Maven feed in Octopus Deploy.",
}
resp.Schema = schemas.MavenFeedSchema{}.GetResourceSchema()
}

func (r *mavenFeedTypeResource) Configure(_ context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) {
Expand Down
106 changes: 72 additions & 34 deletions octopusdeploy_framework/schemas/action_template_parameter.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/core"
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
"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"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringdefault"
Expand All @@ -13,6 +14,10 @@ import (
"github.com/hashicorp/terraform-plugin-framework/types"
)

type ActionTemplateParameterSchema struct{}

var _ EntitySchema = ActionTemplateParameterSchema{}

func expandActionTemplateParameter(tfTemplate map[string]attr.Value) actiontemplates.ActionTemplateParameter {
actionTemplateParameter := actiontemplates.NewActionTemplateParameter()

Expand Down Expand Up @@ -67,44 +72,77 @@ func TemplateObjectType() map[string]attr.Type {
}
}

func GetActionTemplateParameterSchema() map[string]resourceSchema.Attribute {
return map[string]resourceSchema.Attribute{
"default_value": resourceSchema.StringAttribute{
Description: "A default value for the parameter, if applicable. This can be a hard-coded value or a variable reference.",
Optional: true,
Computed: true,
Default: stringdefault.StaticString(""),
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
func (a ActionTemplateParameterSchema) GetDatasourceSchema() datasourceSchema.Schema {
return datasourceSchema.Schema{}
}

func (a ActionTemplateParameterSchema) GetResourceSchema() resourceSchema.Schema {
return resourceSchema.Schema{
Attributes: map[string]resourceSchema.Attribute{
"description": GetDescriptionResourceSchema("library variable set"),
"id": GetIdResourceSchema(),
"name": GetNameResourceSchema(true),
"space_id": GetSpaceIdResourceSchema("library variable set"),
"template_ids": resourceSchema.MapAttribute{
ElementType: types.StringType,
Computed: true,
},
},
"display_settings": resourceSchema.MapAttribute{
Description: "The display settings for the parameter.",
Optional: true,
ElementType: types.StringType,
},
"help_text": resourceSchema.StringAttribute{
Description: "The help presented alongside the parameter input.",
Optional: true,
Computed: true,
Default: stringdefault.StaticString(""),
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
"variable_set_id": resourceSchema.StringAttribute{
Computed: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
},
},
"id": GetIdResourceSchema(),
"label": resourceSchema.StringAttribute{
Description: "The label shown beside the parameter when presented in the deployment process. Example: `Server name`.",
Optional: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
Description: "This resource manages library variable sets in Octopus Deploy.",
Blocks: map[string]resourceSchema.Block{
"template": GetActionTemplateParameterSchema(),
},
"name": resourceSchema.StringAttribute{
Description: "The name of the variable set by the parameter. The name can contain letters, digits, dashes and periods. Example: `ServerName`",
Required: true,
Validators: []validator.String{
stringvalidator.LengthAtLeast(1),
}
}

func GetActionTemplateParameterSchema() resourceSchema.ListNestedBlock {
return resourceSchema.ListNestedBlock{
NestedObject: resourceSchema.NestedBlockObject{
Attributes: map[string]resourceSchema.Attribute{
"default_value": resourceSchema.StringAttribute{
Description: "A default value for the parameter, if applicable. This can be a hard-coded value or a variable reference.",
Optional: true,
Computed: true,
Default: stringdefault.StaticString(""),
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
},
"display_settings": resourceSchema.MapAttribute{
Description: "The display settings for the parameter.",
Optional: true,
ElementType: types.StringType,
},
"help_text": resourceSchema.StringAttribute{
Description: "The help presented alongside the parameter input.",
Optional: true,
Computed: true,
Default: stringdefault.StaticString(""),
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
},
"id": GetIdResourceSchema(),
"label": resourceSchema.StringAttribute{
Description: "The label shown beside the parameter when presented in the deployment process. Example: `Server name`.",
Optional: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
},
"name": resourceSchema.StringAttribute{
Description: "The name of the variable set by the parameter. The name can contain letters, digits, dashes and periods. Example: `ServerName`",
Required: true,
Validators: []validator.String{
stringvalidator.LengthAtLeast(1),
},
},
},
},
}
Expand Down
1 change: 0 additions & 1 deletion octopusdeploy_framework/schemas/entity_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@ import (
type EntitySchema interface {
GetResourceSchema() resourceSchema.Schema
GetDatasourceSchema() datasourceSchema.Schema
//GetDatasourceSchemaAttributes() map[string]datasourceSchema.Attribute
}
6 changes: 1 addition & 5 deletions octopusdeploy_framework/schemas/library_variable_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,7 @@ func (l LibraryVariableSetSchema) GetResourceSchema() resourceSchema.Schema {
},
Description: "This resource manages library variable sets in Octopus Deploy.",
Blocks: map[string]resourceSchema.Block{
"template": resourceSchema.ListNestedBlock{
NestedObject: resourceSchema.NestedBlockObject{
Attributes: GetActionTemplateParameterSchema(),
},
},
"template": GetActionTemplateParameterSchema(),
},
}
}
Expand Down
34 changes: 23 additions & 11 deletions octopusdeploy_framework/schemas/maven_feed.go
Original file line number Diff line number Diff line change
@@ -1,26 +1,38 @@
package schemas

import (
datasourceSchema "github.com/hashicorp/terraform-plugin-framework/datasource/schema"
resourceSchema "github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/types"
)

const mavenFeedDescription = "maven feed"

func GetMavenFeedResourceSchema() map[string]resourceSchema.Attribute {
return map[string]resourceSchema.Attribute{
"download_attempts": GetDownloadAttemptsResourceSchema(),
"download_retry_backoff_seconds": GetDownloadRetryBackoffSecondsResourceSchema(),
"feed_uri": GetFeedUriResourceSchema(),
"id": GetIdResourceSchema(),
"name": GetNameResourceSchema(true),
"package_acquisition_location_options": GetPackageAcquisitionLocationOptionsResourceSchema(),
"password": GetPasswordResourceSchema(false),
"space_id": GetSpaceIdResourceSchema(mavenFeedDescription),
"username": GetUsernameResourceSchema(false),
type MavenFeedSchema struct{}

func (m MavenFeedSchema) GetResourceSchema() resourceSchema.Schema {
return resourceSchema.Schema{
Description: "This resource manages a Maven feed in Octopus Deploy.",
Attributes: map[string]resourceSchema.Attribute{
"download_attempts": GetDownloadAttemptsResourceSchema(),
"download_retry_backoff_seconds": GetDownloadRetryBackoffSecondsResourceSchema(),
"feed_uri": GetFeedUriResourceSchema(),
"id": GetIdResourceSchema(),
"name": GetNameResourceSchema(true),
"package_acquisition_location_options": GetPackageAcquisitionLocationOptionsResourceSchema(),
"password": GetPasswordResourceSchema(false),
"space_id": GetSpaceIdResourceSchema(mavenFeedDescription),
"username": GetUsernameResourceSchema(false),
},
}
}

func (m MavenFeedSchema) GetDatasourceSchema() datasourceSchema.Schema {
return datasourceSchema.Schema{}
}

var _ EntitySchema = MavenFeedSchema{}

type MavenFeedTypeResourceModel struct {
DownloadAttempts types.Int64 `tfsdk:"download_attempts"`
DownloadRetryBackoffSeconds types.Int64 `tfsdk:"download_retry_backoff_seconds"`
Expand Down
2 changes: 2 additions & 0 deletions octopusdeploy_framework/schemas/project_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (

const projectGroupDescription = "project group"

type

func GetProjectGroupDatasourceSchema() map[string]datasourceSchema.Attribute {

Check warning on line 13 in octopusdeploy_framework/schemas/project_group.go

View workflow job for this annotation

GitHub Actions / build

invalid file octopusdeploy_framework/schemas/project_group.go: octopusdeploy_framework/schemas/project_group.go:13:1: expected 'IDENT', found 'func' (and 1 more errors)

Check failure on line 13 in octopusdeploy_framework/schemas/project_group.go

View workflow job for this annotation

GitHub Actions / build

syntax error: unexpected func, expected name

Check failure on line 13 in octopusdeploy_framework/schemas/project_group.go

View workflow job for this annotation

GitHub Actions / build

syntax error: unexpected func, expected name
return map[string]datasourceSchema.Attribute{
"id": GetIdResourceSchema(),
Expand Down
2 changes: 2 additions & 0 deletions octopusdeploy_framework/schemas/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ var testableSchemas = []EntitySchema{
SpaceSchema{},
ScriptModuleSchema{},
LibraryVariableSetSchema{},
ActionTemplateParameterSchema{},
MavenFeedSchema{},
}

func TestDatasourceSchemaDefinitionIsUsingCorrectTypes(t *testing.T) {
Expand Down

0 comments on commit 8f6dc41

Please sign in to comment.