From 51ec30cce145ff7989930fdedc494f737d46b7b3 Mon Sep 17 00:00:00 2001 From: domenicsim1 <87625140+domenicsim1@users.noreply.github.com> Date: Fri, 1 Nov 2024 11:40:11 +1100 Subject: [PATCH] feat: machine proxy resource and data source (#809) --- docs/data-sources/machine_proxies.md | 43 ++++++ docs/resources/machine_proxy.md | 34 +++++ go.mod | 2 +- go.sum | 4 +- .../datasource_machine_proxy.go | 86 +++++++++++ octopusdeploy_framework/framework_provider.go | 2 + .../resource_machine_proxy.go | 143 ++++++++++++++++++ .../resource_machine_proxy_test.go | 95 ++++++++++++ .../schemas/machine_proxy.go | 123 +++++++++++++++ .../util/resource_attribute_builder.go | 29 ++++ 10 files changed, 558 insertions(+), 3 deletions(-) create mode 100644 docs/data-sources/machine_proxies.md create mode 100644 docs/resources/machine_proxy.md create mode 100644 octopusdeploy_framework/datasource_machine_proxy.go create mode 100644 octopusdeploy_framework/resource_machine_proxy.go create mode 100644 octopusdeploy_framework/resource_machine_proxy_test.go create mode 100644 octopusdeploy_framework/schemas/machine_proxy.go diff --git a/docs/data-sources/machine_proxies.md b/docs/data-sources/machine_proxies.md new file mode 100644 index 000000000..6219f250b --- /dev/null +++ b/docs/data-sources/machine_proxies.md @@ -0,0 +1,43 @@ +--- +# generated by https://github.com/hashicorp/terraform-plugin-docs +page_title: "octopusdeploy_machine_proxies Data Source - terraform-provider-octopusdeploy" +subcategory: "" +description: |- + Provides information about existing Octopus Deploy machine proxies. +--- + +# octopusdeploy_machine_proxies (Data Source) + +Provides information about existing Octopus Deploy machine proxies. + + + + +## Schema + +### Optional + +- `ids` (List of String) A filter to search by a list of IDs. +- `partial_name` (String) A filter to search by a partial name. +- `skip` (Number) A filter to specify the number of items to skip in the response. +- `space_id` (String) A Space ID to filter by. Will revert what is specified on the provider if not set +- `take` (Number) A filter to specify the number of items to take (or return) in the response. + +### Read-Only + +- `id` (String) An auto-generated identifier that includes the timestamp when this data source was last modified. +- `machine_proxies` (Attributes List) A list of machine proxies that match the filter(s). (see [below for nested schema](#nestedatt--machine_proxies)) + + +### Nested Schema for `machine_proxies` + +Read-Only: + +- `host` (String) DNS hostname of the proxy server +- `id` (String) +- `name` (String) +- `port` (Number) The port number for the proxy server. +- `space_id` (String) The space ID associated with this machine proxy. +- `username` (String) Username for the proxy server + + diff --git a/docs/resources/machine_proxy.md b/docs/resources/machine_proxy.md new file mode 100644 index 000000000..e2cffb1c8 --- /dev/null +++ b/docs/resources/machine_proxy.md @@ -0,0 +1,34 @@ +--- +# generated by https://github.com/hashicorp/terraform-plugin-docs +page_title: "octopusdeploy_machine_proxy Resource - terraform-provider-octopusdeploy" +subcategory: "" +description: |- + This resource manages machine proxies in Octopus Deploy. +--- + +# octopusdeploy_machine_proxy (Resource) + +This resource manages machine proxies in Octopus Deploy. + + + + +## Schema + +### Required + +- `host` (String) DNS hostname of the proxy server +- `name` (String) The name of this resource. +- `password` (String, Sensitive) Password of the proxy server +- `username` (String) Username of the proxy server + +### Optional + +- `port` (Number) The port number for the proxy server. +- `space_id` (String) The space ID associated with this machine_proxy. + +### Read-Only + +- `id` (String) The unique ID for this resource. + + diff --git a/go.mod b/go.mod index d04cf17c4..8dcc68c27 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/OctopusDeploy/terraform-provider-octopusdeploy go 1.21 require ( - github.com/OctopusDeploy/go-octopusdeploy/v2 v2.53.1 + github.com/OctopusDeploy/go-octopusdeploy/v2 v2.55.0 github.com/OctopusSolutionsEngineering/OctopusTerraformTestFramework v0.0.0-20240729041805-46db6fb717b4 github.com/google/uuid v1.6.0 github.com/hashicorp/go-cty v1.4.1-0.20200723130312-85980079f637 diff --git a/go.sum b/go.sum index 178816a3a..7a39471c6 100644 --- a/go.sum +++ b/go.sum @@ -20,8 +20,8 @@ github.com/Microsoft/hcsshim v0.12.4 h1:Ev7YUMHAHoWNm+aDSPzc5W9s6E2jyL1szpVDJeZ/ github.com/Microsoft/hcsshim v0.12.4/go.mod h1:Iyl1WVpZzr+UkzjekHZbV8o5Z9ZkxNGx6CtY2Qg/JVQ= github.com/OctopusDeploy/go-octodiff v1.0.0 h1:U+ORg6azniwwYo+O44giOw6TiD5USk8S4VDhOQ0Ven0= github.com/OctopusDeploy/go-octodiff v1.0.0/go.mod h1:Mze0+EkOWTgTmi8++fyUc6r0aLZT7qD9gX+31t8MmIU= -github.com/OctopusDeploy/go-octopusdeploy/v2 v2.53.1 h1:9c5qKji5R/sFmjqVQ1Nxt+vKITsj42CCCs0bfqJvETc= -github.com/OctopusDeploy/go-octopusdeploy/v2 v2.53.1/go.mod h1:ggvOXzMnq+w0pLg6C9zdjz6YBaHfO3B3tqmmB7JQdaw= +github.com/OctopusDeploy/go-octopusdeploy/v2 v2.55.0 h1:kX6qRRy8AgbqTiYdenqVNe69pGhntwJGEgJx9rtn9/8= +github.com/OctopusDeploy/go-octopusdeploy/v2 v2.55.0/go.mod h1:ggvOXzMnq+w0pLg6C9zdjz6YBaHfO3B3tqmmB7JQdaw= github.com/OctopusSolutionsEngineering/OctopusTerraformTestFramework v0.0.0-20240729041805-46db6fb717b4 h1:QfbVf0bOIRMp/WHAWsuVDB7KHoWnRsGbvDuOf2ua7k4= github.com/OctopusSolutionsEngineering/OctopusTerraformTestFramework v0.0.0-20240729041805-46db6fb717b4/go.mod h1:Oq9KbiRNDBB5jFmrwnrgLX0urIqR/1ptY18TzkqXm7M= github.com/ProtonMail/go-crypto v1.1.0-alpha.2 h1:bkyFVUP+ROOARdgCiJzNQo2V2kiB97LyUpzH9P6Hrlg= diff --git a/octopusdeploy_framework/datasource_machine_proxy.go b/octopusdeploy_framework/datasource_machine_proxy.go new file mode 100644 index 000000000..d219269d1 --- /dev/null +++ b/octopusdeploy_framework/datasource_machine_proxy.go @@ -0,0 +1,86 @@ +package octopusdeploy_framework + +import ( + "context" + "fmt" + "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/proxies" + "github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/schemas" + "github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/util" + "github.com/hashicorp/terraform-plugin-framework/datasource" + "github.com/hashicorp/terraform-plugin-framework/types" + "time" +) + +var _ datasource.DataSource = &machineProxyDataSource{} + +type machineProxyDataSource struct { + *Config +} + +func NewMachineProxyDataSource() datasource.DataSource { + return &machineProxyDataSource{} +} + +func (p *machineProxyDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { + resp.TypeName = util.GetTypeName(schemas.MachineProxyDataSourceName) +} + +func (p *machineProxyDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) { + resp.Schema = schemas.MachineProxySchema{}.GetDatasourceSchema() +} + +func (p *machineProxyDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) { + p.Config = DataSourceConfiguration(req, resp) +} + +func (p *machineProxyDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { + var data schemas.MachineProxyDataSourceModel + resp.Diagnostics.Append(req.Config.Get(ctx, &data)...) + if resp.Diagnostics.HasError() { + return + } + + query := proxies.ProxiesQuery{ + PartialName: data.PartialName.ValueString(), + Skip: int(data.Skip.ValueInt64()), + Take: int(data.Take.ValueInt64()), + } + + util.DatasourceReading(ctx, "machine proxies", query) + + if !data.IDs.IsNull() { + var ids []string + resp.Diagnostics.Append(data.IDs.ElementsAs(ctx, &ids, false)...) + if resp.Diagnostics.HasError() { + return + } + query.IDs = ids + } + + spaceID := data.SpaceID.ValueString() + + proxiesData, err := proxies.Get(p.Client, spaceID, query) + if err != nil { + resp.Diagnostics.AddError("Unable to query proxies", err.Error()) + return + } + + util.DatasourceResultCount(ctx, "proxies", len(proxiesData.Items)) + + data.Proxies = make([]schemas.ProxyDatasourceModel, 0, len(proxiesData.Items)) + for _, proxy := range proxiesData.Items { + proxyModel := mapMachineProxyRequestToModel(proxy, &schemas.MachineProxyResourceModel{}) + data.Proxies = append(data.Proxies, schemas.ProxyDatasourceModel{ + ID: proxyModel.ID, + SpaceID: proxyModel.SpaceID, + Name: proxyModel.Name, + Host: proxyModel.Host, + Username: proxyModel.Username, + Port: proxyModel.Port, + }) + } + + data.ID = types.StringValue(fmt.Sprintf("Proxies-%s", time.Now().UTC().String())) + + resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) +} diff --git a/octopusdeploy_framework/framework_provider.go b/octopusdeploy_framework/framework_provider.go index 0664dfaef..700e8c629 100644 --- a/octopusdeploy_framework/framework_provider.go +++ b/octopusdeploy_framework/framework_provider.go @@ -71,6 +71,7 @@ func (p *octopusDeployFrameworkProvider) DataSources(ctx context.Context) []func NewLibraryVariableSetDataSource, NewVariablesDataSource, NewProjectsDataSource, + NewMachineProxyDataSource, NewTenantsDataSource, NewTagSetsDataSource, NewScriptModuleDataSource, @@ -103,6 +104,7 @@ func (p *octopusDeployFrameworkProvider) Resources(ctx context.Context) []func() NewLibraryVariableSetFeedResource, NewVariableResource, NewProjectResource, + NewMachineProxyResource, NewTagResource, NewDockerContainerRegistryFeedResource, NewTagSetResource, diff --git a/octopusdeploy_framework/resource_machine_proxy.go b/octopusdeploy_framework/resource_machine_proxy.go new file mode 100644 index 000000000..af8eeea2e --- /dev/null +++ b/octopusdeploy_framework/resource_machine_proxy.go @@ -0,0 +1,143 @@ +package octopusdeploy_framework + +import ( + "context" + "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/core" + "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/proxies" + "github.com/OctopusDeploy/terraform-provider-octopusdeploy/internal/errors" + "github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/schemas" + "github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/util" + "github.com/hashicorp/terraform-plugin-framework/resource" + "github.com/hashicorp/terraform-plugin-framework/types" +) + +var _ resource.Resource = &machineProxyResource{} + +type machineProxyResource struct { + *Config +} + +func NewMachineProxyResource() resource.Resource { + return &machineProxyResource{} +} + +func (r *machineProxyResource) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { + resp.TypeName = util.GetTypeName(schemas.MachineProxyResourceName) +} + +func (r *machineProxyResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) { + resp.Schema = schemas.MachineProxySchema{}.GetResourceSchema() +} + +func (r *machineProxyResource) Configure(_ context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { + r.Config = ResourceConfiguration(req, resp) +} + +func (r *machineProxyResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { + var plan schemas.MachineProxyResourceModel + resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...) + if resp.Diagnostics.HasError() { + return + } + + machineProxy := mapMachineProxyModelToRequest(&plan) + createdProxy, err := proxies.Add(r.Client, machineProxy) + if err != nil { + resp.Diagnostics.AddError("Error creating machine proxy", err.Error()) + return + } + + proxyModel := mapMachineProxyRequestToModel(createdProxy, &plan) + + diags := resp.State.Set(ctx, proxyModel) + resp.Diagnostics.Append(diags...) +} + +func (r *machineProxyResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { + var state schemas.MachineProxyResourceModel + diags := req.State.Get(ctx, &state) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } + + machineProxy, err := proxies.GetByID(r.Client, state.SpaceID.ValueString(), state.ID.ValueString()) + if err != nil { + if err := errors.ProcessApiErrorV2(ctx, resp, state, err, "machine proxy"); err != nil { + resp.Diagnostics.AddError("Error reading machine proxy", err.Error()) + } + return + } + + proxyModel := mapMachineProxyRequestToModel(machineProxy, &state) + + resp.Diagnostics.Append(resp.State.Set(ctx, proxyModel)...) +} + +func (r *machineProxyResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { + var plan schemas.MachineProxyResourceModel + resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...) + if resp.Diagnostics.HasError() { + return + } + + existingProxy, err := proxies.GetByID(r.Client, plan.SpaceID.ValueString(), plan.ID.ValueString()) + if err != nil { + resp.Diagnostics.AddError("Error retrieving machine proxy", err.Error()) + return + } + + updatedProxy := mapMachineProxyModelToRequest(&plan) + updatedProxy.ID = existingProxy.ID + updatedProxy.Links = existingProxy.Links + + updatedProxy, err = proxies.Update(r.Client, updatedProxy) + if err != nil { + resp.Diagnostics.AddError("Error updating machine proxy", err.Error()) + return + } + + proxyModel := mapMachineProxyRequestToModel(updatedProxy, &plan) + + diags := resp.State.Set(ctx, proxyModel) + resp.Diagnostics.Append(diags...) +} + +func (r *machineProxyResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { + var state schemas.MachineProxyResourceModel + resp.Diagnostics.Append(req.State.Get(ctx, &state)...) + if resp.Diagnostics.HasError() { + return + } + + err := proxies.DeleteByID(r.Client, state.SpaceID.ValueString(), state.ID.ValueString()) + if err != nil { + resp.Diagnostics.AddError("Error deleting machine proxy", err.Error()) + return + } + + resp.State.RemoveResource(ctx) +} + +func mapMachineProxyModelToRequest(model *schemas.MachineProxyResourceModel) *proxies.Proxy { + password := core.NewSensitiveValue(model.Password.ValueString()) + proxy := proxies.NewProxy(model.Name.ValueString(), model.Host.ValueString(), model.Username.ValueString(), password) + proxy.SpaceID = model.SpaceID.ValueString() + portNumber := model.Port.ValueInt32() + proxy.Port = int(portNumber) + return proxy +} + +func mapMachineProxyRequestToModel(proxy *proxies.Proxy, state *schemas.MachineProxyResourceModel) *schemas.MachineProxyResourceModel { + proxyModel := &schemas.MachineProxyResourceModel{ + SpaceID: types.StringValue(proxy.SpaceID), + Name: types.StringValue(proxy.Name), + Host: types.StringValue(proxy.Host), + Username: types.StringValue(proxy.Username), + Password: types.StringValue(state.Password.ValueString()), + Port: types.Int32Value(int32(proxy.Port)), + } + proxyModel.ID = types.StringValue(proxy.ID) + + return proxyModel +} diff --git a/octopusdeploy_framework/resource_machine_proxy_test.go b/octopusdeploy_framework/resource_machine_proxy_test.go new file mode 100644 index 000000000..c068516c2 --- /dev/null +++ b/octopusdeploy_framework/resource_machine_proxy_test.go @@ -0,0 +1,95 @@ +package octopusdeploy_framework + +import ( + "fmt" + "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/core" + "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/proxies" + "github.com/hashicorp/terraform-plugin-testing/helper/acctest" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" + "testing" +) + +func TestAccMachineProxyBasic(t *testing.T) { + localName := acctest.RandStringFromCharSet(20, acctest.CharSetAlpha) + prefix := "octopusdeploy_machine_proxy." + localName + + data := &proxies.Proxy{ + Name: "Test Proxy", + Host: "127.0.0.1", + Port: 8080, + Username: "admin", + Password: core.NewSensitiveValue("safepass"), + ProxyType: "HTTP", + } + + resource.Test(t, resource.TestCase{ + CheckDestroy: testMachineProxyDestroy, + PreCheck: func() { TestAccPreCheck(t) }, + ProtoV6ProviderFactories: ProtoV6ProviderFactories(), + Steps: []resource.TestStep{ + { + Config: testMachineProxyBasic(data, localName), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(prefix, "name", data.Name), + ), + }, + { + Config: testMachineProxyUpdate(*data, localName), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(prefix, "name", data.Name+"-updated"), + ), + }, + }, + }) +} + +func testMachineProxyBasic(data *proxies.Proxy, localName string) string { + return fmt.Sprintf(` + resource "octopusdeploy_machine_proxy" "%s" { + name = "%s" + host = "%s" + username = "%s" + password = "%s" + port = %d + } +`, + localName, + data.Name, + data.Host, + data.Username, + *data.Password.NewValue, + data.Port, + ) +} + +func testMachineProxyUpdate(data proxies.Proxy, localName string) string { + data.Name = data.Name + "-updated" + + return testMachineProxyBasic(&data, localName) +} + +func testMachineProxyDestroy(s *terraform.State) error { + var machineProxyID string + + for _, rs := range s.RootModule().Resources { + if rs.Type != "octopusdeploy_machine_proxy" { + continue + } + + machineProxyID = rs.Primary.ID + break + } + if machineProxyID == "" { + return fmt.Errorf("no octopusdeploy_machine_proxy resource found") + } + + machineProxy, err := proxies.GetByID(octoClient, octoClient.GetSpaceID(), machineProxyID) + if err == nil { + if machineProxy != nil { + return fmt.Errorf("machine proxy (%s) still exists", machineProxy.Name) + } + } + + return nil +} diff --git a/octopusdeploy_framework/schemas/machine_proxy.go b/octopusdeploy_framework/schemas/machine_proxy.go new file mode 100644 index 000000000..6fd6471da --- /dev/null +++ b/octopusdeploy_framework/schemas/machine_proxy.go @@ -0,0 +1,123 @@ +package schemas + +import ( + "github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/util" + 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/stringplanmodifier" + "github.com/hashicorp/terraform-plugin-framework/types" +) + +type MachineProxyResourceModel struct { + SpaceID types.String `tfsdk:"space_id"` + Name types.String `tfsdk:"name"` + Host types.String `tfsdk:"host"` + Username types.String `tfsdk:"username"` + Port types.Int32 `tfsdk:"port"` + Password types.String `tfsdk:"password"` + ResourceModel +} + +type MachineProxyDataSourceModel struct { + ID types.String `tfsdk:"id"` + SpaceID types.String `tfsdk:"space_id"` + IDs types.List `tfsdk:"ids"` + PartialName types.String `tfsdk:"partial_name"` + Skip types.Int64 `tfsdk:"skip"` + Take types.Int64 `tfsdk:"take"` + Proxies []ProxyDatasourceModel `tfsdk:"machine_proxies"` +} + +type ProxyDatasourceModel struct { + ID types.String `tfsdk:"id"` + SpaceID types.String `tfsdk:"space_id"` + Name types.String `tfsdk:"name"` + Host types.String `tfsdk:"host"` + Username types.String `tfsdk:"username"` + Port types.Int32 `tfsdk:"port"` +} + +const ( + MachineProxyResourceName = "machine_proxy" + MachineProxyDataSourceName = "machine_proxies" +) + +type MachineProxySchema struct{} + +var _ EntitySchema = MachineProxySchema{} + +func (p MachineProxySchema) GetResourceSchema() resourceSchema.Schema { + return resourceSchema.Schema{ + Description: "This resource manages machine proxies in Octopus Deploy.", + Attributes: map[string]resourceSchema.Attribute{ + "id": GetIdResourceSchema(), + "space_id": GetSpaceIdResourceSchema(MachineProxyResourceName), + "name": GetNameResourceSchema(true), + "host": util.ResourceString(). + Required(). + Description("DNS hostname of the proxy server"). + Build(), + "username": util.ResourceString(). + Required(). + Description("Username of the proxy server"). + Build(), + "password": util.ResourceString(). + Required(). + Description("Password of the proxy server"). + Sensitive(). + PlanModifiers(stringplanmodifier.UseStateForUnknown()). + Build(), + "port": util.ResourceInt32(). + Optional(). + Computed(). + Default(80). + Description("The port number for the proxy server."). + Build(), + }, + } +} + +func (p MachineProxySchema) GetDatasourceSchema() datasourceSchema.Schema { + return datasourceSchema.Schema{ + Description: "Provides information about existing Octopus Deploy machine proxies.", + Attributes: map[string]datasourceSchema.Attribute{ + "id": util.DataSourceString().Computed().Description("An auto-generated identifier that includes the timestamp when this data source was last modified.").Build(), + "space_id": util.DataSourceString().Optional().Description("A Space ID to filter by. Will revert what is specified on the provider if not set").Build(), + "ids": GetQueryIDsDatasourceSchema(), + "partial_name": GetQueryPartialNameDatasourceSchema(), + "skip": GetQuerySkipDatasourceSchema(), + "take": GetQueryTakeDatasourceSchema(), + "machine_proxies": getMachineProxiesDataSourceAttribute(), + }, + } +} + +func getMachineProxiesDataSourceAttribute() datasourceSchema.ListNestedAttribute { + return datasourceSchema.ListNestedAttribute{ + Description: "A list of machine proxies that match the filter(s).", + Computed: true, + Optional: false, + NestedObject: datasourceSchema.NestedAttributeObject{ + Attributes: map[string]datasourceSchema.Attribute{ + "id": util.DataSourceString().Computed().Build(), + "space_id": util.DataSourceString(). + Computed(). + Description("The space ID associated with this machine proxy."). + Build(), + "name": util.DataSourceString().Computed().Build(), + "host": util.DataSourceString(). + Computed(). + Description("DNS hostname of the proxy server"). + Build(), + "username": util.DataSourceString(). + Computed(). + Description("Username for the proxy server"). + Build(), + "port": util.DataSourceInt64(). + Computed(). + Description("The port number for the proxy server."). + Build(), + }, + }, + } +} diff --git a/octopusdeploy_framework/util/resource_attribute_builder.go b/octopusdeploy_framework/util/resource_attribute_builder.go index 908f07929..ba70aa3f7 100644 --- a/octopusdeploy_framework/util/resource_attribute_builder.go +++ b/octopusdeploy_framework/util/resource_attribute_builder.go @@ -5,6 +5,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault" "github.com/hashicorp/terraform-plugin-framework/resource/schema/float64default" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/int32default" "github.com/hashicorp/terraform-plugin-framework/resource/schema/int64default" "github.com/hashicorp/terraform-plugin-framework/resource/schema/listdefault" "github.com/hashicorp/terraform-plugin-framework/resource/schema/mapdefault" @@ -31,6 +32,8 @@ func (b *AttributeBuilder[T]) Optional() *AttributeBuilder[T] { a.Optional = true case *schema.Int64Attribute: a.Optional = true + case *schema.Int32Attribute: + a.Optional = true case *schema.Float64Attribute: a.Optional = true case *schema.NumberAttribute: @@ -55,6 +58,8 @@ func (b *AttributeBuilder[T]) Deprecated(deprecationMessage string) *AttributeBu a.DeprecationMessage = deprecationMessage case *schema.Int64Attribute: a.DeprecationMessage = deprecationMessage + case *schema.Int32Attribute: + a.DeprecationMessage = deprecationMessage case *schema.Float64Attribute: a.DeprecationMessage = deprecationMessage case *schema.NumberAttribute: @@ -79,6 +84,8 @@ func (b *AttributeBuilder[T]) Computed() *AttributeBuilder[T] { a.Computed = true case *schema.Int64Attribute: a.Computed = true + case *schema.Int32Attribute: + a.Computed = true case *schema.Float64Attribute: a.Computed = true case *schema.NumberAttribute: @@ -103,6 +110,8 @@ func (b *AttributeBuilder[T]) Required() *AttributeBuilder[T] { a.Required = true case *schema.Int64Attribute: a.Required = true + case *schema.Int32Attribute: + a.Required = true case *schema.Float64Attribute: a.Required = true case *schema.NumberAttribute: @@ -127,6 +136,8 @@ func (b *AttributeBuilder[T]) Description(desc string) *AttributeBuilder[T] { a.Description = desc case *schema.Int64Attribute: a.Description = desc + case *schema.Int32Attribute: + a.Description = desc case *schema.Float64Attribute: a.Description = desc case *schema.NumberAttribute: @@ -157,6 +168,10 @@ func (b *AttributeBuilder[T]) Default(defaultValue interface{}) *AttributeBuilde if intDefault, ok := defaultValue.(int64); ok { a.Default = int64default.StaticInt64(intDefault) } + case *schema.Int32Attribute: + if intDefault, ok := defaultValue.(int32); ok { + a.Default = int32default.StaticInt32(intDefault) + } case *schema.NumberAttribute: case *schema.Float64Attribute: if floatDefault, ok := defaultValue.(float64); ok { @@ -180,6 +195,8 @@ func (b *AttributeBuilder[T]) Sensitive() *AttributeBuilder[T] { a.Sensitive = true case *schema.Int64Attribute: a.Sensitive = true + case *schema.Int32Attribute: + a.Sensitive = true case *schema.Float64Attribute: a.Sensitive = true case *schema.NumberAttribute: @@ -233,6 +250,10 @@ func (b *AttributeBuilder[T]) PlanModifiers(modifiers ...any) *AttributeBuilder[ if int64Modifiers, ok := convertToTypedSlice[planmodifier.Int64](modifiers); ok { a.PlanModifiers = append(a.PlanModifiers, int64Modifiers...) } + case *schema.Int32Attribute: + if int32Modifiers, ok := convertToTypedSlice[planmodifier.Int32](modifiers); ok { + a.PlanModifiers = append(a.PlanModifiers, int32Modifiers...) + } case *schema.Float64Attribute: if float64Modifiers, ok := convertToTypedSlice[planmodifier.Float64](modifiers); ok { a.PlanModifiers = append(a.PlanModifiers, float64Modifiers...) @@ -266,6 +287,10 @@ func (b *AttributeBuilder[T]) Validators(validators ...any) *AttributeBuilder[T] if int64Validators, ok := convertToTypedSlice[validator.Int64](validators); ok { a.Validators = append(a.Validators, int64Validators...) } + case *schema.Int32Attribute: + if int32Validators, ok := convertToTypedSlice[validator.Int32](validators); ok { + a.Validators = append(a.Validators, int32Validators...) + } case *schema.Float64Attribute: if float64Validators, ok := convertToTypedSlice[validator.Float64](validators); ok { a.Validators = append(a.Validators, float64Validators...) @@ -305,6 +330,10 @@ func ResourceBool() *AttributeBuilder[schema.BoolAttribute] { return NewAttributeBuilder[schema.BoolAttribute]() } +func ResourceInt32() *AttributeBuilder[schema.Int32Attribute] { + return NewAttributeBuilder[schema.Int32Attribute]() +} + func ResourceInt64() *AttributeBuilder[schema.Int64Attribute] { return NewAttributeBuilder[schema.Int64Attribute]() }