From f9364f47d15af0d74269879b1b0c7a4aa4596746 Mon Sep 17 00:00:00 2001 From: Marcin Maciaszczyk Date: Thu, 8 Aug 2024 12:40:58 +0200 Subject: [PATCH] move stack models --- .../custom_stack_run.go} | 12 ++++++------ .../infrastructure_stack.go} | 12 ++++++------ internal/resource/custom_stack_run.go | 9 +++++---- internal/resource/infrastructure_stack.go | 9 +++++---- 4 files changed, 22 insertions(+), 20 deletions(-) rename internal/{resource/custom_stack_run_model.go => model/custom_stack_run.go} (96%) rename internal/{resource/infrastructure_stack_model.go => model/infrastructure_stack.go} (98%) diff --git a/internal/resource/custom_stack_run_model.go b/internal/model/custom_stack_run.go similarity index 96% rename from internal/resource/custom_stack_run_model.go rename to internal/model/custom_stack_run.go index 1fd4bad..d5d31d8 100644 --- a/internal/resource/custom_stack_run_model.go +++ b/internal/model/custom_stack_run.go @@ -1,4 +1,4 @@ -package resource +package model import ( "context" @@ -13,7 +13,7 @@ import ( "github.com/pluralsh/polly/algorithms" ) -type customStackRun struct { +type CustomStackRun struct { Id types.String `tfsdk:"id"` Name types.String `tfsdk:"name"` Documentation types.String `tfsdk:"documentation"` @@ -22,7 +22,7 @@ type customStackRun struct { Configuration types.Set `tfsdk:"configuration"` } -func (csr *customStackRun) Attributes(ctx context.Context, d diag.Diagnostics, client *client.Client) (*gqlclient.CustomStackRunAttributes, error) { +func (csr *CustomStackRun) Attributes(ctx context.Context, d diag.Diagnostics, client *client.Client) (*gqlclient.CustomStackRunAttributes, error) { return &gqlclient.CustomStackRunAttributes{ Name: csr.Name.ValueString(), Documentation: csr.Documentation.ValueStringPointer(), @@ -32,7 +32,7 @@ func (csr *customStackRun) Attributes(ctx context.Context, d diag.Diagnostics, c }, nil } -func (csr *customStackRun) commandsAttribute(ctx context.Context, d diag.Diagnostics) []*gqlclient.CommandAttributes { +func (csr *CustomStackRun) commandsAttribute(ctx context.Context, d diag.Diagnostics) []*gqlclient.CommandAttributes { if csr.Commands.IsNull() { return nil } @@ -55,7 +55,7 @@ func (csr *customStackRun) commandsAttribute(ctx context.Context, d diag.Diagnos return result } -func (csr *customStackRun) configurationAttribute(ctx context.Context, d diag.Diagnostics) []*gqlclient.PrConfigurationAttributes { +func (csr *CustomStackRun) configurationAttribute(ctx context.Context, d diag.Diagnostics) []*gqlclient.PrConfigurationAttributes { if csr.Configuration.IsNull() { return nil } @@ -80,7 +80,7 @@ func (csr *customStackRun) configurationAttribute(ctx context.Context, d diag.Di return result } -func (csr *customStackRun) From(customStackRun *gqlclient.CustomStackRunFragment, ctx context.Context, d diag.Diagnostics) { +func (csr *CustomStackRun) From(customStackRun *gqlclient.CustomStackRunFragment, ctx context.Context, d diag.Diagnostics) { csr.Id = types.StringValue(customStackRun.ID) csr.Name = types.StringValue(customStackRun.Name) csr.Documentation = types.StringPointerValue(customStackRun.Documentation) diff --git a/internal/resource/infrastructure_stack_model.go b/internal/model/infrastructure_stack.go similarity index 98% rename from internal/resource/infrastructure_stack_model.go rename to internal/model/infrastructure_stack.go index 69e7c10..799f681 100644 --- a/internal/resource/infrastructure_stack_model.go +++ b/internal/model/infrastructure_stack.go @@ -1,4 +1,4 @@ -package resource +package model import ( "context" @@ -14,7 +14,7 @@ import ( "github.com/pluralsh/polly/algorithms" ) -type infrastructureStack struct { +type InfrastructureStack struct { Id types.String `tfsdk:"id"` Name types.String `tfsdk:"name"` Type types.String `tfsdk:"type"` @@ -31,7 +31,7 @@ type infrastructureStack struct { Bindings *common.Bindings `tfsdk:"bindings"` } -func (is *infrastructureStack) Attributes(ctx context.Context, d diag.Diagnostics, client *client.Client) (*gqlclient.StackAttributes, error) { +func (is *InfrastructureStack) Attributes(ctx context.Context, d diag.Diagnostics, client *client.Client) (*gqlclient.StackAttributes, error) { attr := &gqlclient.StackAttributes{ Name: is.Name.ValueString(), Type: gqlclient.StackType(is.Type.ValueString()), @@ -58,7 +58,7 @@ func (is *infrastructureStack) Attributes(ctx context.Context, d diag.Diagnostic return attr, nil } -func (is *infrastructureStack) FilesAttributes(ctx context.Context, d diag.Diagnostics) []*gqlclient.StackFileAttributes { +func (is *InfrastructureStack) FilesAttributes(ctx context.Context, d diag.Diagnostics) []*gqlclient.StackFileAttributes { if is.Files.IsNull() { return nil } @@ -74,7 +74,7 @@ func (is *infrastructureStack) FilesAttributes(ctx context.Context, d diag.Diagn return result } -func (is *infrastructureStack) EnvironmentAttributes(ctx context.Context, d diag.Diagnostics) []*gqlclient.StackEnvironmentAttributes { +func (is *InfrastructureStack) EnvironmentAttributes(ctx context.Context, d diag.Diagnostics) []*gqlclient.StackEnvironmentAttributes { if is.Environment.IsNull() { return nil } @@ -94,7 +94,7 @@ func (is *infrastructureStack) EnvironmentAttributes(ctx context.Context, d diag return result } -func (is *infrastructureStack) From(stack *gqlclient.InfrastructureStackFragment, ctx context.Context, d diag.Diagnostics) { +func (is *InfrastructureStack) From(stack *gqlclient.InfrastructureStackFragment, ctx context.Context, d diag.Diagnostics) { is.Id = types.StringPointerValue(stack.ID) is.Name = types.StringValue(stack.Name) is.Type = types.StringValue(string(stack.Type)) diff --git a/internal/resource/custom_stack_run.go b/internal/resource/custom_stack_run.go index 2b58264..c385bfa 100644 --- a/internal/resource/custom_stack_run.go +++ b/internal/resource/custom_stack_run.go @@ -6,6 +6,7 @@ import ( "terraform-provider-plural/internal/client" "terraform-provider-plural/internal/common" + "terraform-provider-plural/internal/model" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" @@ -50,7 +51,7 @@ func (r *CustomStackRunResource) Configure(_ context.Context, req resource.Confi } func (r *CustomStackRunResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { - data := new(customStackRun) + data := new(model.CustomStackRun) resp.Diagnostics.Append(req.Plan.Get(ctx, data)...) if resp.Diagnostics.HasError() { return @@ -72,7 +73,7 @@ func (r *CustomStackRunResource) Create(ctx context.Context, req resource.Create } func (r *CustomStackRunResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { - data := new(customStackRun) + data := new(model.CustomStackRun) resp.Diagnostics.Append(req.State.Get(ctx, data)...) if resp.Diagnostics.HasError() { return @@ -89,7 +90,7 @@ func (r *CustomStackRunResource) Read(ctx context.Context, req resource.ReadRequ } func (r *CustomStackRunResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { - data := new(customStackRun) + data := new(model.CustomStackRun) resp.Diagnostics.Append(req.Plan.Get(ctx, data)...) if resp.Diagnostics.HasError() { return @@ -110,7 +111,7 @@ func (r *CustomStackRunResource) Update(ctx context.Context, req resource.Update } func (r *CustomStackRunResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { - data := new(customStackRun) + data := new(model.CustomStackRun) resp.Diagnostics.Append(req.State.Get(ctx, data)...) if resp.Diagnostics.HasError() { return diff --git a/internal/resource/infrastructure_stack.go b/internal/resource/infrastructure_stack.go index f30f895..7c0ebd1 100644 --- a/internal/resource/infrastructure_stack.go +++ b/internal/resource/infrastructure_stack.go @@ -7,6 +7,7 @@ import ( "terraform-provider-plural/internal/client" "terraform-provider-plural/internal/common" + "terraform-provider-plural/internal/model" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" @@ -52,7 +53,7 @@ func (r *InfrastructureStackResource) Configure(_ context.Context, req resource. } func (r *InfrastructureStackResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { - data := new(infrastructureStack) + data := new(model.InfrastructureStack) resp.Diagnostics.Append(req.Plan.Get(ctx, data)...) if resp.Diagnostics.HasError() { return @@ -74,7 +75,7 @@ func (r *InfrastructureStackResource) Create(ctx context.Context, req resource.C } func (r *InfrastructureStackResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { - data := new(infrastructureStack) + data := new(model.InfrastructureStack) resp.Diagnostics.Append(req.State.Get(ctx, data)...) if resp.Diagnostics.HasError() { return @@ -91,7 +92,7 @@ func (r *InfrastructureStackResource) Read(ctx context.Context, req resource.Rea } func (r *InfrastructureStackResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { - data := new(infrastructureStack) + data := new(model.InfrastructureStack) resp.Diagnostics.Append(req.Plan.Get(ctx, data)...) if resp.Diagnostics.HasError() { return @@ -112,7 +113,7 @@ func (r *InfrastructureStackResource) Update(ctx context.Context, req resource.U } func (r *InfrastructureStackResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { - data := new(infrastructureStack) + data := new(model.InfrastructureStack) resp.Diagnostics.Append(req.State.Get(ctx, data)...) if resp.Diagnostics.HasError() { return