Skip to content

Commit

Permalink
start adding model
Browse files Browse the repository at this point in the history
  • Loading branch information
maciaszczykm committed Apr 19, 2024
1 parent 1dcd452 commit 0b81d26
Showing 1 changed file with 74 additions and 0 deletions.
74 changes: 74 additions & 0 deletions internal/resource/infrastructure_stack_model.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package resource

import (
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/types"
gqlclient "github.com/pluralsh/console-client-go"
)

type InfrastructureStack struct {
Id types.String `tfsdk:"id"`
Name types.String `tfsdk:"name"`
Type types.String `tfsdk:"type"`
ClusterId types.String `tfsdk:"cluster_id"`
Repository *InfrastructureStackRepository `tfsdk:"repository"`
Approval types.Bool `tfsdk:"protect"`
Configuration *InfrastructureStackConfiguration `tfsdk:"configuration"`
Files []*InfrastructureStackFile `tfsdk:"environment"`
Environemnt []*InfrastructureStackEnvironment `tfsdk:"files"`
Bindings *InfrastructureStackBindings `tfsdk:"bindings"`
// TODO: JobSpec *GateJobAttributes `json:"jobSpec,omitempty"`
}

type InfrastructureStackRepository struct {
Id types.String `tfsdk:"id"`
Ref types.String `tfsdk:"ref"`
Folder types.String `tfsdk:"folder"`
}

func (isr *InfrastructureStackRepository) From(repository *gqlclient.GitRepository, ref gqlclient.GitRef) {
if isr == nil {
return
}

isr.Id = types.StringValue(repository.ID)
isr.Ref = types.StringValue(ref.Ref)
isr.Folder = types.StringValue(ref.Folder)
}

type InfrastructureStackConfiguration struct {
Image types.String `tfsdk:"image"`
Version types.String `tfsdk:"version"`
}

type InfrastructureStackEnvironment struct {
Name types.String `tfsdk:"name"`
Value types.String `tfsdk:"value"`
Secret types.Bool `tfsdk:"secret"`
}

type InfrastructureStackFile struct {
Path types.String `tfsdk:"path"`
Content types.String `tfsdk:"content"`
}

type InfrastructureStackBindings struct {
Read []*InfrastructureStackPolicyBinding `tfsdk:"read"`
Write []*InfrastructureStackPolicyBinding `tfsdk:"write"`
}

type InfrastructureStackPolicyBinding struct {
GroupID types.String `tfsdk:"group_id"`
ID types.String `tfsdk:"id"`
UserID types.String `tfsdk:"user_id"`
}

func (is *InfrastructureStack) FromCreate(stack *gqlclient.InfrastructureStack, d diag.Diagnostics) {
is.Id = types.StringPointerValue(stack.ID)
is.Name = types.StringValue(stack.Name)
is.Type = types.StringValue(string(stack.Type))
is.ClusterId = types.StringValue(stack.Cluster.ID)
is.Repository.From(stack.Repository, stack.Git)
is.Approval = types.BoolPointerValue(stack.Approval)
// TODO ...
}

0 comments on commit 0b81d26

Please sign in to comment.