Skip to content

Commit

Permalink
move stack models
Browse files Browse the repository at this point in the history
  • Loading branch information
maciaszczykm committed Aug 8, 2024
1 parent 45cc1a1 commit f9364f4
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package resource
package model

import (
"context"
Expand All @@ -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"`
Expand All @@ -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(),
Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package resource
package model

import (
"context"
Expand All @@ -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"`
Expand All @@ -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()),
Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -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))
Expand Down
9 changes: 5 additions & 4 deletions internal/resource/custom_stack_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
9 changes: 5 additions & 4 deletions internal/resource/infrastructure_stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit f9364f4

Please sign in to comment.