From b03217169703874d831b4e60114724498b94172d Mon Sep 17 00:00:00 2001 From: Marcin Maciaszczyk Date: Wed, 24 Jul 2024 14:01:19 +0200 Subject: [PATCH 01/19] register group member resource --- internal/provider/provider.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/provider/provider.go b/internal/provider/provider.go index 4c6beb3..a60c923 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -187,6 +187,7 @@ func (p *PluralProvider) Resources(_ context.Context) []func() resource.Resource r.NewServiceContextResource, r.NewInfrastructureStackResource, r.NewCustomStackRunResource, + r.NewGroupMemberResource, } } From f79b65e37a1f39f6245bcfa7d50f9c38776060cf Mon Sep 17 00:00:00 2001 From: Marcin Maciaszczyk Date: Wed, 24 Jul 2024 14:25:05 +0200 Subject: [PATCH 02/19] register other resources and data sources --- internal/provider/provider.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/internal/provider/provider.go b/internal/provider/provider.go index a60c923..01c4cab 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -187,6 +187,8 @@ func (p *PluralProvider) Resources(_ context.Context) []func() resource.Resource r.NewServiceContextResource, r.NewInfrastructureStackResource, r.NewCustomStackRunResource, + r.NewRbacResource, + r.NewGlobalServiceResource, r.NewGroupMemberResource, } } @@ -197,6 +199,9 @@ func (p *PluralProvider) DataSources(_ context.Context) []func() datasource.Data ds.NewClusterDataSource, ds.NewGitRepositoryDataSource, ds.NewProviderDataSource, + ds.NewGroupDataSource, + ds.NewUserDataSource, + ds.NewConfigDataSource, } } From 34851f534dd1f0c5cfd549f9bfb44962ccbe7330 Mon Sep 17 00:00:00 2001 From: Marcin Maciaszczyk Date: Wed, 24 Jul 2024 14:44:14 +0200 Subject: [PATCH 03/19] add group model --- internal/resource/group_model.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 internal/resource/group_model.go diff --git a/internal/resource/group_model.go b/internal/resource/group_model.go new file mode 100644 index 0000000..3bd834d --- /dev/null +++ b/internal/resource/group_model.go @@ -0,0 +1,25 @@ +package resource + +import ( + "github.com/hashicorp/terraform-plugin-framework/types" + gqlclient "github.com/pluralsh/console-client-go" +) + +type group struct { + Id types.String `tfsdk:"id"` + Name types.String `tfsdk:"name"` + Description types.String `tfsdk:"description"` +} + +func (g *group) From(response *gqlclient.GroupFragment) { + g.Id = types.StringValue(response.ID) + g.Name = types.StringValue(response.Name) + g.Name = types.StringPointerValue(response.Description) +} + +func (g *group) Attributes() gqlclient.GroupAttributes { + return gqlclient.GroupAttributes{ + Name: g.Name.ValueString(), + Description: g.Description.ValueStringPointer(), + } +} From 5aa982d7747a2142ce92f320184f4ed3fde3c620 Mon Sep 17 00:00:00 2001 From: Marcin Maciaszczyk Date: Wed, 24 Jul 2024 14:45:28 +0200 Subject: [PATCH 04/19] minor improvements --- internal/resource/group_member.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/resource/group_member.go b/internal/resource/group_member.go index 226fa1f..7b7997f 100644 --- a/internal/resource/group_member.go +++ b/internal/resource/group_member.go @@ -99,11 +99,11 @@ func (r *GroupMemberResource) Create(ctx context.Context, req resource.CreateReq resp.Diagnostics.Append(resp.State.Set(ctx, data)...) } -func (r *GroupMemberResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { +func (r *GroupMemberResource) Read(_ context.Context, _ resource.ReadRequest, _ *resource.ReadResponse) { // ignore } -func (r *GroupMemberResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { +func (r *GroupMemberResource) Update(_ context.Context, _ resource.UpdateRequest, resp *resource.UpdateResponse) { resp.Diagnostics.AddError("Client Error", "cannot update a group member") } From 81751ec9bb78a98434596060d75a6864a5db5c82 Mon Sep 17 00:00:00 2001 From: Marcin Maciaszczyk Date: Wed, 24 Jul 2024 14:50:05 +0200 Subject: [PATCH 05/19] add group resource --- internal/provider/provider.go | 1 + internal/resource/group.go | 158 ++++++++++++++++++++++++++++++++++ 2 files changed, 159 insertions(+) create mode 100644 internal/resource/group.go diff --git a/internal/provider/provider.go b/internal/provider/provider.go index 01c4cab..52d9ec4 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -190,6 +190,7 @@ func (p *PluralProvider) Resources(_ context.Context) []func() resource.Resource r.NewRbacResource, r.NewGlobalServiceResource, r.NewGroupMemberResource, + r.NewGroupResource, } } diff --git a/internal/resource/group.go b/internal/resource/group.go new file mode 100644 index 0000000..69482cb --- /dev/null +++ b/internal/resource/group.go @@ -0,0 +1,158 @@ +package resource + +import ( + "context" + "fmt" + + "terraform-provider-plural/internal/common" + + "terraform-provider-plural/internal/client" + + "github.com/hashicorp/terraform-plugin-framework/path" + "github.com/hashicorp/terraform-plugin-framework/resource" + "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/stringplanmodifier" +) + +var _ resource.Resource = &GroupResource{} +var _ resource.ResourceWithImportState = &GroupResource{} + +func NewGroupResource() resource.Resource { + return &GroupResource{} +} + +// GroupResource defines the Group resource implementation. +type GroupResource struct { + client *client.Client +} + +func (r *GroupResource) Metadata( + _ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse, +) { + resp.TypeName = req.ProviderTypeName + "_group" +} + +func (r *GroupResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) { + resp.Schema = schema.Schema{ + MarkdownDescription: "group resource", + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + Computed: true, + Description: "Internal identifier of this group.", + MarkdownDescription: "Internal identifier of this group.", + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + }, + "name": schema.StringAttribute{ + Required: true, + Description: "Name of this group.", + MarkdownDescription: "Name of this group.", + }, + "description": schema.StringAttribute{ + Required: true, + Description: "Description of this group.", + MarkdownDescription: "Description of this group.", + }, + }, + } +} + +func (r *GroupResource) Configure( + _ context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse, +) { + if req.ProviderData == nil { + return + } + + data, ok := req.ProviderData.(*common.ProviderData) + if !ok { + resp.Diagnostics.AddError( + "Unexpected Group Resource Configure Type", + fmt.Sprintf( + "Expected *common.ProviderData, got: %T. Please report this issue to the provider developers.", + req.ProviderData, + ), + ) + + return + } + + r.client = data.Client +} + +func (r *GroupResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { + data := new(group) + resp.Diagnostics.Append(req.Plan.Get(ctx, data)...) + if resp.Diagnostics.HasError() { + return + } + + response, err := r.client.CreateGroup(ctx, data.Attributes()) + if err != nil { + resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to create group, got error: %s", err)) + return + } + + data.From(response.CreateGroup) + resp.Diagnostics.Append(resp.State.Set(ctx, data)...) +} + +func (r *GroupResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { + data := new(group) + resp.Diagnostics.Append(req.State.Get(ctx, data)...) + if resp.Diagnostics.HasError() { + return + } + + response, err := r.client.GetGroup(ctx, data.Name.ValueString()) // TODO: Immutable name? + if err != nil { + resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to get group, got error: %s", err)) + return + } + + if response == nil || response.Group == nil { + resp.Diagnostics.AddError("Client Error", "Unable to find group") + return + } + + data.From(response.Group) + resp.Diagnostics.Append(resp.State.Set(ctx, data)...) +} + +func (r *GroupResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { + data := new(group) + resp.Diagnostics.Append(req.Plan.Get(ctx, data)...) + if resp.Diagnostics.HasError() { + return + } + + _, err := r.client.UpdateGroup(ctx, data.Id.ValueString(), data.Attributes()) + if err != nil { + resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to update group, got error: %s", err)) + return + } + + resp.Diagnostics.Append(resp.State.Set(ctx, data)...) +} + +func (r *GroupResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { + data := new(group) + resp.Diagnostics.Append(req.State.Get(ctx, data)...) + if resp.Diagnostics.HasError() { + return + } + + _, err := r.client.DeleteGroup(ctx, data.Id.ValueString()) + if err != nil { + resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to delete group, got error: %s", err)) + return + } +} + +func (r *GroupResource) ImportState( + ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse, +) { + resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) +} From 6372f15d07a7466830dbbc26e6dc69191e52adc7 Mon Sep 17 00:00:00 2001 From: Marcin Maciaszczyk Date: Wed, 24 Jul 2024 15:10:11 +0200 Subject: [PATCH 06/19] switch to the new client --- go.mod | 42 ++++++------ go.sum | 66 ++++++++++--------- internal/client/client.go | 2 +- internal/common/bindings.go | 2 +- internal/common/cluster_node_pool.go | 2 +- internal/common/cluster_provider.go | 2 +- internal/common/project.go | 2 +- internal/common/tags.go | 2 +- internal/datasource/cluster.go | 2 +- internal/datasource/cluster_model.go | 2 +- internal/datasource/git_repository_model.go | 2 +- internal/datasource/group.go | 2 +- internal/datasource/group_model.go | 2 +- internal/datasource/provider_model.go | 2 +- internal/datasource/user.go | 2 +- internal/datasource/user_model.go | 2 +- internal/provider/provider.go | 2 +- internal/resource/cluster_model.go | 2 +- internal/resource/cluster_operator_handler.go | 2 +- internal/resource/custom_stack_run_model.go | 2 +- internal/resource/custom_stack_run_schema.go | 2 +- internal/resource/git_repository_model.go | 2 +- internal/resource/global_service_model.go | 2 +- internal/resource/group.go | 34 +++++----- internal/resource/group_member_model.go | 2 +- internal/resource/group_model.go | 2 +- .../resource/infrastructure_stack_model.go | 2 +- .../resource/infrastructure_stack_schema.go | 2 +- internal/resource/project_model.go | 2 +- internal/resource/provider_model.go | 2 +- internal/resource/rbac_model.go | 2 +- internal/resource/service_context_model.go | 2 +- internal/resource/service_deployment_model.go | 2 +- 33 files changed, 105 insertions(+), 97 deletions(-) diff --git a/go.mod b/go.mod index f24a3fe..b0d515c 100644 --- a/go.mod +++ b/go.mod @@ -1,18 +1,18 @@ module terraform-provider-plural -go 1.22 +go 1.22.4 -toolchain go1.22.0 +toolchain go1.22.5 require ( - github.com/Yamashou/gqlgenc v0.18.1 + github.com/Yamashou/gqlgenc v0.23.2 github.com/golangci/golangci-lint v1.55.1 github.com/hashicorp/terraform-plugin-docs v0.16.0 github.com/hashicorp/terraform-plugin-framework v1.4.2 github.com/hashicorp/terraform-plugin-framework-validators v0.12.0 github.com/hashicorp/terraform-plugin-log v0.9.0 github.com/mitchellh/go-homedir v1.1.0 - github.com/pluralsh/console-client-go v0.8.0 + github.com/pluralsh/console/go/client v1.0.0 github.com/pluralsh/plural-cli v0.8.5-0.20240216094552-efc34ee6de37 github.com/pluralsh/polly v0.1.7 github.com/samber/lo v1.38.1 @@ -29,7 +29,7 @@ require ( 4d63.com/gocheckcompilerdirectives v1.2.1 // indirect 4d63.com/gochecknoglobals v0.2.1 // indirect github.com/4meepo/tagalign v1.3.3 // indirect - github.com/99designs/gqlgen v0.17.43 // indirect + github.com/99designs/gqlgen v0.17.49 // indirect github.com/Abirdcfly/dupword v0.0.13 // indirect github.com/AlecAivazis/survey/v2 v2.3.5 // indirect github.com/Antonboom/errname v0.1.12 // indirect @@ -80,7 +80,7 @@ require ( github.com/curioswitch/go-reassign v0.2.0 // indirect github.com/cyphar/filepath-securejoin v0.2.3 // indirect github.com/daixiang0/gci v0.11.2 // indirect - github.com/davecgh/go-spew v1.1.1 // indirect + github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect github.com/denis-tingaikin/go-header v0.4.3 // indirect github.com/docker/cli v20.10.21+incompatible // indirect github.com/docker/distribution v2.8.2+incompatible // indirect @@ -239,8 +239,9 @@ require ( github.com/peterbourgon/diskv v2.0.1+incompatible // indirect github.com/pjbgf/sha1cd v0.3.0 // indirect github.com/pkg/errors v0.9.1 // indirect + github.com/pluralsh/console-client-go v0.0.92 // indirect github.com/pluralsh/gqlclient v1.11.0 // indirect - github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect github.com/polyfloyd/go-errorlint v1.4.5 // indirect github.com/posener/complete v1.2.3 // indirect github.com/prometheus/client_golang v1.15.1 // indirect @@ -270,7 +271,7 @@ require ( github.com/sivchari/tenv v1.7.1 // indirect github.com/skeema/knownhosts v1.1.0 // indirect github.com/sonatard/noctx v0.0.2 // indirect - github.com/sosodev/duration v1.2.0 // indirect + github.com/sosodev/duration v1.3.1 // indirect github.com/sourcegraph/go-diff v0.7.0 // indirect github.com/spf13/afero v1.9.5 // indirect github.com/spf13/cast v1.5.0 // indirect @@ -280,8 +281,8 @@ require ( github.com/spf13/viper v1.15.0 // indirect github.com/ssgreg/nlreturn/v2 v2.2.1 // indirect github.com/stbenjam/no-sprintf-host-port v0.1.1 // indirect - github.com/stretchr/objx v0.5.0 // indirect - github.com/stretchr/testify v1.8.4 // indirect + github.com/stretchr/objx v0.5.2 // indirect + github.com/stretchr/testify v1.9.0 // indirect github.com/subosito/gotenv v1.4.2 // indirect github.com/t-yuki/gocover-cobertura v0.0.0-20180217150009-aaee18c8195c // indirect github.com/tdakkota/asciicheck v0.2.0 // indirect @@ -293,7 +294,7 @@ require ( github.com/ultraware/funlen v0.1.0 // indirect github.com/ultraware/whitespace v0.0.5 // indirect github.com/uudashr/gocognit v1.1.2 // indirect - github.com/vektah/gqlparser/v2 v2.5.11 // indirect + github.com/vektah/gqlparser/v2 v2.5.16 // indirect github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect github.com/xanzy/ssh-agent v0.3.3 // indirect @@ -315,22 +316,22 @@ require ( go.uber.org/goleak v1.2.1 // indirect go.uber.org/multierr v1.8.0 // indirect go.uber.org/zap v1.24.0 // indirect - golang.org/x/crypto v0.16.0 // indirect + golang.org/x/crypto v0.24.0 // indirect golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df // indirect golang.org/x/exp/typeparams v0.0.0-20230307190834-24139beb5833 // indirect - golang.org/x/mod v0.13.0 // indirect - golang.org/x/net v0.19.0 // indirect + golang.org/x/mod v0.18.0 // indirect + golang.org/x/net v0.26.0 // indirect golang.org/x/oauth2 v0.8.0 // indirect - golang.org/x/sync v0.4.0 // indirect - golang.org/x/sys v0.17.0 // indirect - golang.org/x/term v0.17.0 // indirect - golang.org/x/text v0.14.0 // indirect + golang.org/x/sync v0.7.0 // indirect + golang.org/x/sys v0.21.0 // indirect + golang.org/x/term v0.21.0 // indirect + golang.org/x/text v0.16.0 // indirect golang.org/x/time v0.3.0 // indirect - golang.org/x/tools v0.14.0 // indirect + golang.org/x/tools v0.22.0 // indirect google.golang.org/appengine v1.6.7 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20230525234030-28d5490b6b19 // indirect google.golang.org/grpc v1.57.0 // indirect - google.golang.org/protobuf v1.31.0 // indirect + google.golang.org/protobuf v1.34.1 // indirect gopkg.in/inf.v0 v0.9.1 // indirect gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/warnings.v0 v0.1.2 // indirect @@ -357,6 +358,7 @@ require ( ) replace ( + github.com/Yamashou/gqlgenc => github.com/Yamashou/gqlgenc v0.18.1 go.etcd.io/etcd/pkg/v3 => go.etcd.io/etcd/pkg/v3 v3.5.0-alpha.0 k8s.io/cli-runtime => k8s.io/cli-runtime v0.26.4 k8s.io/kube-openapi => k8s.io/kube-openapi v0.0.0-20230109183929-3758b55a6596 diff --git a/go.sum b/go.sum index 4c9c5c2..eb61398 100644 --- a/go.sum +++ b/go.sum @@ -48,8 +48,8 @@ filippo.io/age v1.1.1 h1:pIpO7l151hCnQ4BdyBujnGP2YlUo0uj6sAVNHGBvXHg= filippo.io/age v1.1.1/go.mod h1:l03SrzDUrBkdBx8+IILdnn2KZysqQdbEBUQ4p3sqEQE= github.com/4meepo/tagalign v1.3.3 h1:ZsOxcwGD/jP4U/aw7qeWu58i7dwYemfy5Y+IF1ACoNw= github.com/4meepo/tagalign v1.3.3/go.mod h1:Q9c1rYMZJc9dPRkbQPpcBNCLEmY2njbAsXhQOZFE2dE= -github.com/99designs/gqlgen v0.17.43 h1:I4SYg6ahjowErAQcHFVKy5EcWuwJ3+Xw9z2fLpuFCPo= -github.com/99designs/gqlgen v0.17.43/go.mod h1:lO0Zjy8MkZgBdv4T1U91x09r0e0WFOdhVUutlQs1Rsc= +github.com/99designs/gqlgen v0.17.49 h1:b3hNGexHd33fBSAd4NDT/c3NCcQzcAVkknhN9ym36YQ= +github.com/99designs/gqlgen v0.17.49/go.mod h1:tC8YFVZMed81x7UJ7ORUwXF4Kn6SXuucFqQBhN8+BU0= github.com/Abirdcfly/dupword v0.0.13 h1:SMS17YXypwP000fA7Lr+kfyBQyW14tTT+nRv9ASwUUo= github.com/Abirdcfly/dupword v0.0.13/go.mod h1:Ut6Ue2KgF/kCOawpW4LnExT+xZLQviJPE4klBPMK/5Y= github.com/AlecAivazis/survey/v2 v2.3.5 h1:A8cYupsAZkjaUmhtTYv3sSqc7LO5mp1XDfqe5E/9wRQ= @@ -233,8 +233,9 @@ github.com/cyphar/filepath-securejoin v0.2.3/go.mod h1:aPGpWjXOXUn2NCNjFvBE6aRxG github.com/daixiang0/gci v0.11.2 h1:Oji+oPsp3bQ6bNNgX30NBAVT18P4uBH4sRZnlOlTj7Y= github.com/daixiang0/gci v0.11.2/go.mod h1:xtHP9N7AHdNvtRNfcx9gwTDfw7FRJx4bZUsiEfiNNAI= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= +github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/denis-tingaikin/go-header v0.4.3 h1:tEaZKAlqql6SKCY++utLmkPLd6K8IBM20Ha7UVm+mtU= github.com/denis-tingaikin/go-header v0.4.3/go.mod h1:0wOCWuN71D5qIgE2nz9KrKmuYBAC2Mra5RassOIQ2/c= github.com/denisenkom/go-mssqldb v0.9.0/go.mod h1:xbL0rPBG9cCiLr28tMa8zpbdarY27NDyej4t/EjAShU= @@ -856,16 +857,19 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/sftp v1.10.1/go.mod h1:lYOWFsE0bwd1+KfKJaKeuokY15vzFx25BLbzYYoAxZI= github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qRg= -github.com/pluralsh/console-client-go v0.8.0 h1:wCX92bN5EPW8g58neebJPFOm0YQKPCdLBJItSku4dec= -github.com/pluralsh/console-client-go v0.8.0/go.mod h1:eyCiLA44YbXiYyJh8303jk5JdPkt9McgCo5kBjk4lKo= +github.com/pluralsh/console-client-go v0.0.92 h1:PMSF05Zp5gLejeEWXbwe17CfXNLJ55dGlFPAAVucfCM= +github.com/pluralsh/console-client-go v0.0.92/go.mod h1:eyCiLA44YbXiYyJh8303jk5JdPkt9McgCo5kBjk4lKo= +github.com/pluralsh/console/go/client v1.0.0 h1:jsKmDjZFNEYMg6xgOeIjRyP/2oJXYOQqjUGeA6i0v84= +github.com/pluralsh/console/go/client v1.0.0/go.mod h1:lpoWASYsM9keNePS3dpFiEisUHEfObIVlSL3tzpKn8k= github.com/pluralsh/gqlclient v1.11.0 h1:FfXW7FiEJLHOfTAa7NxDb8jb3aMZNIpCAcG+bg8uHYA= github.com/pluralsh/gqlclient v1.11.0/go.mod h1:qSXKUlio1F2DRPy8el4oFYsmpKbkUYspgPB87T4it5I= github.com/pluralsh/plural-cli v0.8.5-0.20240216094552-efc34ee6de37 h1:DBnaKvKmbTbKwbkrh/2gJBwyHYfaXdxeT3UGh+94K4g= github.com/pluralsh/plural-cli v0.8.5-0.20240216094552-efc34ee6de37/go.mod h1:ZjvgOn9wE5vQXkImmoQknKKP0/68Ph6Hj19fUE1WdDU= github.com/pluralsh/polly v0.1.7 h1:MUuTb6rCUV1doisaFGC+iz+33ZPU4FZHOb/kFwSDkjw= github.com/pluralsh/polly v0.1.7/go.mod h1:Yo1/jcW+4xwhWG+ZJikZy4J4HJkMNPZ7sq5auL2c/tY= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= +github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/polyfloyd/go-errorlint v1.4.5 h1:70YWmMy4FgRHehGNOUask3HtSFSOLKgmDn7ryNe7LqI= github.com/polyfloyd/go-errorlint v1.4.5/go.mod h1:sIZEbFoDOCnTYYZoVkjc4hTnM459tuWA9H/EkdXwsKk= github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI= @@ -984,8 +988,8 @@ github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9 github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= github.com/sonatard/noctx v0.0.2 h1:L7Dz4De2zDQhW8S0t+KUjY0MAQJd6SgVwhzNIc4ok00= github.com/sonatard/noctx v0.0.2/go.mod h1:kzFz+CzWSjQ2OzIm46uJZoXuBpa2+0y3T36U18dWqIo= -github.com/sosodev/duration v1.2.0 h1:pqK/FLSjsAADWY74SyWDCjOcd5l7H8GSnnOGEB9A1Us= -github.com/sosodev/duration v1.2.0/go.mod h1:RQIBBX0+fMLc/D9+Jb/fwvVmo0eZvDDEERAikUR6SDg= +github.com/sosodev/duration v1.3.1 h1:qtHBDMQ6lvMQsL15g4aopM4HEfOaYuhWBw3NPTtlqq4= +github.com/sosodev/duration v1.3.1/go.mod h1:RQIBBX0+fMLc/D9+Jb/fwvVmo0eZvDDEERAikUR6SDg= github.com/sourcegraph/go-diff v0.7.0 h1:9uLlrd5T46OXs5qpp8L/MTltk0zikUGi0sNNyCpA8G0= github.com/sourcegraph/go-diff v0.7.0/go.mod h1:iBszgVvyxdc8SFZ7gm69go2KDdt3ag071iBaWPF6cjs= github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= @@ -1019,8 +1023,9 @@ github.com/stoewer/go-strcase v1.2.0/go.mod h1:IBiWB2sKIp3wVVQ3Y035++gc+knqhUQag github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= -github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY= +github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= @@ -1032,8 +1037,9 @@ github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1F github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= github.com/subosito/gotenv v1.4.2 h1:X1TuBLAMDFbaTAChgCBLu3DU3UPyELpnF2jjJ2cz/S8= github.com/subosito/gotenv v1.4.2/go.mod h1:ayKnFf/c6rvx/2iiLrJUk1e6plDbT3edrFNGqEflhK0= @@ -1063,8 +1069,8 @@ github.com/ultraware/whitespace v0.0.5 h1:hh+/cpIcopyMYbZNVov9iSxvJU3OYQg78Sfaqz github.com/ultraware/whitespace v0.0.5/go.mod h1:aVMh/gQve5Maj9hQ/hg+F75lr/X5A89uZnzAmWSineA= github.com/uudashr/gocognit v1.1.2 h1:l6BAEKJqQH2UpKAPKdMfZf5kE4W/2xk8pfU1OVLvniI= github.com/uudashr/gocognit v1.1.2/go.mod h1:aAVdLURqcanke8h3vg35BC++eseDm66Z7KmchI5et4k= -github.com/vektah/gqlparser/v2 v2.5.11 h1:JJxLtXIoN7+3x6MBdtIP59TP1RANnY7pXOaDnADQSf8= -github.com/vektah/gqlparser/v2 v2.5.11/go.mod h1:1rCcfwB2ekJofmluGWXMSEnPMZgbxzwj6FaZ/4OT8Cc= +github.com/vektah/gqlparser/v2 v2.5.16 h1:1gcmLTvs3JLKXckwCwlUagVn/IlV2bwqle0vJ0vy5p8= +github.com/vektah/gqlparser/v2 v2.5.16/go.mod h1:1lz1OeCqgQbQepsGxPVywrjdBHW2T08PUS3pJqepRww= github.com/vmihailenco/msgpack/v5 v5.3.5 h1:5gO0H1iULLWGhs2H5tbAHIZTV8/cYafcFOr9znI5mJU= github.com/vmihailenco/msgpack/v5 v5.3.5/go.mod h1:7xyJ9e+0+9SaZT0Wt1RGleJXzli6Q/V5KbhBonMG9jc= github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAhO7/IwNM9g= @@ -1168,8 +1174,8 @@ golang.org/x/crypto v0.1.0/go.mod h1:RecgLatLF4+eUMCP1PoPZQb+cVrJcOPbHkTkbkB9sbw golang.org/x/crypto v0.3.0/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4= golang.org/x/crypto v0.5.0/go.mod h1:NK/OQwhpMQP3MwtdjgLlYHnH9ebylxKWv3e0fK+mkQU= golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58= -golang.org/x/crypto v0.16.0 h1:mMMrFzRSCF0GvB7Ne27XVtVAaXLrPmgPC7/v0tkwHaY= -golang.org/x/crypto v0.16.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4= +golang.org/x/crypto v0.24.0 h1:mnl8DM0o513X8fdIkmyFE/5hTYxbwYOjDS/+rK6qpRI= +golang.org/x/crypto v0.24.0/go.mod h1:Z1PMYSOR5nyMcyAVAIQSKCDwalqy85Aqn1x3Ws4L5DM= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= @@ -1217,8 +1223,8 @@ golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91 golang.org/x/mod v0.6.0/go.mod h1:4mET923SAdbXp2ki8ey+zGs1SLqsuM2Y0uvdZR/fUNI= golang.org/x/mod v0.7.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= -golang.org/x/mod v0.13.0 h1:I/DsJXRlw/8l/0c24sM9yb0T4z9liZTduXvdAWYiysY= -golang.org/x/mod v0.13.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= +golang.org/x/mod v0.18.0 h1:5+9lSbEzPSdWkH32vYPBwEpX8KwDbM52Ud9xBUvNlb0= +golang.org/x/mod v0.18.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20181023162649-9b4f9f5ad519/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -1271,8 +1277,8 @@ golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY= golang.org/x/net v0.5.0/go.mod h1:DivGGAXEgPSlEBzxGzZI+ZLohi+xUj054jfeKui00ws= golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= -golang.org/x/net v0.19.0 h1:zTwKpTd2XuCqf8huc7Fo2iSy+4RHPd10s4KzeTnVr1c= -golang.org/x/net v0.19.0/go.mod h1:CfAk/cbD4CthTvqiEl8NpboMuiuOYsAr/7NOjZJtv1U= +golang.org/x/net v0.26.0 h1:soB7SVo0PWrY4vPW/+ay0jKDNScG2X9wFeYlXIvJsOQ= +golang.org/x/net v0.26.0/go.mod h1:5YKkiSynbBIh3p6iOc/vibscux0x38BZDkn8sCUPxHE= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -1301,8 +1307,8 @@ golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.4.0 h1:zxkM55ReGkDlKSM+Fu41A+zmbZuaPVbGMzvvdUPznYQ= -golang.org/x/sync v0.4.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= +golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= +golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -1388,8 +1394,8 @@ golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y= -golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws= +golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210503060354-a79de5458b56/go.mod h1:tfny5GFUkzUvx4ps4ajbZsCe5lw1metzhBm9T3x7oIY= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= @@ -1399,8 +1405,8 @@ golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc= golang.org/x/term v0.4.0/go.mod h1:9P2UbLfCdcvo3p/nzKvsmas4TnlujnuoV9hGgYzW1lQ= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= golang.org/x/term v0.14.0/go.mod h1:TySc+nGkYR6qt8km8wUhuFRTVSMIX3XPR58y2lC8vww= -golang.org/x/term v0.17.0 h1:mkTF7LCd6WGJNL3K1Ad7kwxNfYAW6a8a8QqtMblp/4U= -golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk= +golang.org/x/term v0.21.0 h1:WVXCp+/EBEHOj53Rvu+7KiT/iElMrO8ACK16SMZ3jaA= +golang.org/x/term v0.21.0/go.mod h1:ooXLefLobQVslOqselCNF4SxFAaoS6KujMbsGzSDmX0= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -1413,8 +1419,8 @@ golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.6.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= -golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= -golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4= +golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= @@ -1496,8 +1502,8 @@ golang.org/x/tools v0.2.0/go.mod h1:y4OqIKeOV/fWJetJ8bXPU1sEVniLMIyDAZWeHdV+NTA= golang.org/x/tools v0.3.0/go.mod h1:/rWhSS2+zyEVwoJf8YAX6L2f0ntZ7Kn/mGgAWcipA5k= golang.org/x/tools v0.5.0/go.mod h1:N+Kgy78s5I24c24dU8OfWNEotWjutIs8SnJvn5IDq+k= golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= -golang.org/x/tools v0.14.0 h1:jvNa2pY0M4r62jkRQ6RwEZZyPcymeL9XZMLBbV7U2nc= -golang.org/x/tools v0.14.0/go.mod h1:uYBEerGOWcJyEORxN+Ek8+TT266gXkNlHdJBwexUsBg= +golang.org/x/tools v0.22.0 h1:gqSGLZqv+AI9lIQzniJ0nZDRG5GBPsSi+DRNHWNz6yA= +golang.org/x/tools v0.22.0/go.mod h1:aCwcsjqvq7Yqt6TNyX7QMU2enbQ/Gt0bo6krSeEri+c= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -1615,8 +1621,8 @@ google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlba google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8= -google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg= +google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/internal/client/client.go b/internal/client/client.go index b26d15b..41b926c 100644 --- a/internal/client/client.go +++ b/internal/client/client.go @@ -4,7 +4,7 @@ import ( "context" "fmt" - gqlclient "github.com/pluralsh/console-client-go" + gqlclient "github.com/pluralsh/console/go/client" "github.com/samber/lo" ) diff --git a/internal/common/bindings.go b/internal/common/bindings.go index 7d5dee7..7decd48 100644 --- a/internal/common/bindings.go +++ b/internal/common/bindings.go @@ -7,7 +7,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-plugin-framework/types/basetypes" - console "github.com/pluralsh/console-client-go" + console "github.com/pluralsh/console/go/client" ) type Bindings struct { diff --git a/internal/common/cluster_node_pool.go b/internal/common/cluster_node_pool.go index 08c59ce..b272840 100644 --- a/internal/common/cluster_node_pool.go +++ b/internal/common/cluster_node_pool.go @@ -7,7 +7,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-plugin-framework/types/basetypes" - console "github.com/pluralsh/console-client-go" + console "github.com/pluralsh/console/go/client" ) type ClusterNodePool struct { diff --git a/internal/common/cluster_provider.go b/internal/common/cluster_provider.go index 899afd5..3ce412b 100644 --- a/internal/common/cluster_provider.go +++ b/internal/common/cluster_provider.go @@ -3,7 +3,7 @@ package common import ( "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-plugin-framework/types/basetypes" - console "github.com/pluralsh/console-client-go" + console "github.com/pluralsh/console/go/client" ) func ClusterProviderIdFrom(provider *console.ClusterProviderFragment) basetypes.StringValue { diff --git a/internal/common/project.go b/internal/common/project.go index 425b6e6..12db7f2 100644 --- a/internal/common/project.go +++ b/internal/common/project.go @@ -2,7 +2,7 @@ package common import ( "github.com/hashicorp/terraform-plugin-framework/types" - gqlclient "github.com/pluralsh/console-client-go" + gqlclient "github.com/pluralsh/console/go/client" ) func ProjectFrom(project *gqlclient.TinyProjectFragment) types.String { diff --git a/internal/common/tags.go b/internal/common/tags.go index a9bca15..d5a0499 100644 --- a/internal/common/tags.go +++ b/internal/common/tags.go @@ -5,7 +5,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-plugin-framework/types/basetypes" - console "github.com/pluralsh/console-client-go" + console "github.com/pluralsh/console/go/client" ) func TagsFrom(tags []*console.ClusterTags, config types.Map, d diag.Diagnostics) basetypes.MapValue { diff --git a/internal/datasource/cluster.go b/internal/datasource/cluster.go index 6df6e59..cbda0ad 100644 --- a/internal/datasource/cluster.go +++ b/internal/datasource/cluster.go @@ -13,7 +13,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/schema/validator" "github.com/hashicorp/terraform-plugin-framework/types" - console "github.com/pluralsh/console-client-go" + console "github.com/pluralsh/console/go/client" ) func NewClusterDataSource() datasource.DataSource { diff --git a/internal/datasource/cluster_model.go b/internal/datasource/cluster_model.go index 5af3567..c558e56 100644 --- a/internal/datasource/cluster_model.go +++ b/internal/datasource/cluster_model.go @@ -9,7 +9,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/types" - console "github.com/pluralsh/console-client-go" + console "github.com/pluralsh/console/go/client" ) type cluster struct { diff --git a/internal/datasource/git_repository_model.go b/internal/datasource/git_repository_model.go index b82d893..6a4cbe2 100644 --- a/internal/datasource/git_repository_model.go +++ b/internal/datasource/git_repository_model.go @@ -2,7 +2,7 @@ package datasource import ( "github.com/hashicorp/terraform-plugin-framework/types" - gqlclient "github.com/pluralsh/console-client-go" + gqlclient "github.com/pluralsh/console/go/client" ) type gitRepository struct { diff --git a/internal/datasource/group.go b/internal/datasource/group.go index 041a601..2107bc3 100644 --- a/internal/datasource/group.go +++ b/internal/datasource/group.go @@ -12,7 +12,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/datasource/schema" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/schema/validator" - console "github.com/pluralsh/console-client-go" + console "github.com/pluralsh/console/go/client" ) func NewGroupDataSource() datasource.DataSource { diff --git a/internal/datasource/group_model.go b/internal/datasource/group_model.go index f3a266a..4812f64 100644 --- a/internal/datasource/group_model.go +++ b/internal/datasource/group_model.go @@ -5,7 +5,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/types" - console "github.com/pluralsh/console-client-go" + console "github.com/pluralsh/console/go/client" ) type group struct { diff --git a/internal/datasource/provider_model.go b/internal/datasource/provider_model.go index be3de66..18f367a 100644 --- a/internal/datasource/provider_model.go +++ b/internal/datasource/provider_model.go @@ -2,7 +2,7 @@ package datasource import ( "github.com/hashicorp/terraform-plugin-framework/types" - console "github.com/pluralsh/console-client-go" + console "github.com/pluralsh/console/go/client" ) type provider struct { diff --git a/internal/datasource/user.go b/internal/datasource/user.go index dcf7b27..5858091 100644 --- a/internal/datasource/user.go +++ b/internal/datasource/user.go @@ -12,7 +12,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/datasource/schema" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/schema/validator" - console "github.com/pluralsh/console-client-go" + console "github.com/pluralsh/console/go/client" ) func NewUserDataSource() datasource.DataSource { diff --git a/internal/datasource/user_model.go b/internal/datasource/user_model.go index 34f38d2..41c122e 100644 --- a/internal/datasource/user_model.go +++ b/internal/datasource/user_model.go @@ -5,7 +5,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/types" - console "github.com/pluralsh/console-client-go" + console "github.com/pluralsh/console/go/client" ) type user struct { diff --git a/internal/provider/provider.go b/internal/provider/provider.go index 52d9ec4..f776284 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -21,7 +21,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/schema/validator" "github.com/hashicorp/terraform-plugin-framework/types" - client "github.com/pluralsh/console-client-go" + client "github.com/pluralsh/console/go/client" "github.com/pluralsh/plural-cli/pkg/console" ) diff --git a/internal/resource/cluster_model.go b/internal/resource/cluster_model.go index 54c6680..7246728 100644 --- a/internal/resource/cluster_model.go +++ b/internal/resource/cluster_model.go @@ -9,7 +9,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/types" - console "github.com/pluralsh/console-client-go" + console "github.com/pluralsh/console/go/client" ) type cluster struct { diff --git a/internal/resource/cluster_operator_handler.go b/internal/resource/cluster_operator_handler.go index 35cbbb1..53dfcaf 100644 --- a/internal/resource/cluster_operator_handler.go +++ b/internal/resource/cluster_operator_handler.go @@ -8,7 +8,7 @@ import ( "terraform-provider-plural/internal/client" - gqlclient "github.com/pluralsh/console-client-go" + gqlclient "github.com/pluralsh/console/go/client" "github.com/pluralsh/plural-cli/pkg/console" "github.com/pluralsh/plural-cli/pkg/helm" "github.com/pluralsh/polly/algorithms" diff --git a/internal/resource/custom_stack_run_model.go b/internal/resource/custom_stack_run_model.go index db8350c..1fd4bad 100644 --- a/internal/resource/custom_stack_run_model.go +++ b/internal/resource/custom_stack_run_model.go @@ -9,7 +9,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-plugin-framework/types/basetypes" - gqlclient "github.com/pluralsh/console-client-go" + gqlclient "github.com/pluralsh/console/go/client" "github.com/pluralsh/polly/algorithms" ) diff --git a/internal/resource/custom_stack_run_schema.go b/internal/resource/custom_stack_run_schema.go index 4aca013..90263cf 100644 --- a/internal/resource/custom_stack_run_schema.go +++ b/internal/resource/custom_stack_run_schema.go @@ -7,7 +7,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" "github.com/hashicorp/terraform-plugin-framework/schema/validator" "github.com/hashicorp/terraform-plugin-framework/types" - gqlclient "github.com/pluralsh/console-client-go" + gqlclient "github.com/pluralsh/console/go/client" ) func (r *CustomStackRunResource) schema() schema.Schema { diff --git a/internal/resource/git_repository_model.go b/internal/resource/git_repository_model.go index 8cb1715..faca525 100644 --- a/internal/resource/git_repository_model.go +++ b/internal/resource/git_repository_model.go @@ -2,7 +2,7 @@ package resource import ( "github.com/hashicorp/terraform-plugin-framework/types" - gqlclient "github.com/pluralsh/console-client-go" + gqlclient "github.com/pluralsh/console/go/client" ) type gitRepository struct { diff --git a/internal/resource/global_service_model.go b/internal/resource/global_service_model.go index 7e817b1..fb610e8 100644 --- a/internal/resource/global_service_model.go +++ b/internal/resource/global_service_model.go @@ -8,7 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/types" - gqlclient "github.com/pluralsh/console-client-go" + gqlclient "github.com/pluralsh/console/go/client" "github.com/samber/lo" ) diff --git a/internal/resource/group.go b/internal/resource/group.go index 69482cb..966f47d 100644 --- a/internal/resource/group.go +++ b/internal/resource/group.go @@ -89,13 +89,13 @@ func (r *GroupResource) Create(ctx context.Context, req resource.CreateRequest, return } - response, err := r.client.CreateGroup(ctx, data.Attributes()) - if err != nil { - resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to create group, got error: %s", err)) - return - } - - data.From(response.CreateGroup) + //response, err := r.client.CreateGroup(ctx, data.Attributes()) + //if err != nil { + // resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to create group, got error: %s", err)) + // return + //} + // + //data.From(response.CreateGroup) resp.Diagnostics.Append(resp.State.Set(ctx, data)...) } @@ -128,11 +128,11 @@ func (r *GroupResource) Update(ctx context.Context, req resource.UpdateRequest, return } - _, err := r.client.UpdateGroup(ctx, data.Id.ValueString(), data.Attributes()) - if err != nil { - resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to update group, got error: %s", err)) - return - } + // _, err := r.client.UpdateGroup(ctx, data.Id.ValueString(), data.Attributes()) + //if err != nil { + // resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to update group, got error: %s", err)) + // return + //} resp.Diagnostics.Append(resp.State.Set(ctx, data)...) } @@ -144,11 +144,11 @@ func (r *GroupResource) Delete(ctx context.Context, req resource.DeleteRequest, return } - _, err := r.client.DeleteGroup(ctx, data.Id.ValueString()) - if err != nil { - resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to delete group, got error: %s", err)) - return - } + //_, err := r.client.DeleteGroup(ctx, data.Id.ValueString()) + //if err != nil { + // resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to delete group, got error: %s", err)) + // return + //} } func (r *GroupResource) ImportState( diff --git a/internal/resource/group_member_model.go b/internal/resource/group_member_model.go index 0b63b13..ad594be 100644 --- a/internal/resource/group_member_model.go +++ b/internal/resource/group_member_model.go @@ -2,7 +2,7 @@ package resource import ( "github.com/hashicorp/terraform-plugin-framework/types" - gqlclient "github.com/pluralsh/console-client-go" + gqlclient "github.com/pluralsh/console/go/client" ) type groupMember struct { diff --git a/internal/resource/group_model.go b/internal/resource/group_model.go index 3bd834d..ed5b752 100644 --- a/internal/resource/group_model.go +++ b/internal/resource/group_model.go @@ -2,7 +2,7 @@ package resource import ( "github.com/hashicorp/terraform-plugin-framework/types" - gqlclient "github.com/pluralsh/console-client-go" + gqlclient "github.com/pluralsh/console/go/client" ) type group struct { diff --git a/internal/resource/infrastructure_stack_model.go b/internal/resource/infrastructure_stack_model.go index be83abc..ba79a80 100644 --- a/internal/resource/infrastructure_stack_model.go +++ b/internal/resource/infrastructure_stack_model.go @@ -10,7 +10,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-plugin-framework/types/basetypes" - gqlclient "github.com/pluralsh/console-client-go" + gqlclient "github.com/pluralsh/console/go/client" "github.com/pluralsh/polly/algorithms" ) diff --git a/internal/resource/infrastructure_stack_schema.go b/internal/resource/infrastructure_stack_schema.go index 0833824..9f0cbe5 100644 --- a/internal/resource/infrastructure_stack_schema.go +++ b/internal/resource/infrastructure_stack_schema.go @@ -14,7 +14,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" "github.com/hashicorp/terraform-plugin-framework/schema/validator" "github.com/hashicorp/terraform-plugin-framework/types" - gqlclient "github.com/pluralsh/console-client-go" + gqlclient "github.com/pluralsh/console/go/client" ) func (r *InfrastructureStackResource) schema() schema.Schema { diff --git a/internal/resource/project_model.go b/internal/resource/project_model.go index c30bdd7..36ce84b 100644 --- a/internal/resource/project_model.go +++ b/internal/resource/project_model.go @@ -7,7 +7,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/types" - gqlclient "github.com/pluralsh/console-client-go" + gqlclient "github.com/pluralsh/console/go/client" ) type Project struct { diff --git a/internal/resource/provider_model.go b/internal/resource/provider_model.go index ae590a7..2098d5b 100644 --- a/internal/resource/provider_model.go +++ b/internal/resource/provider_model.go @@ -2,7 +2,7 @@ package resource import ( "github.com/hashicorp/terraform-plugin-framework/types" - console "github.com/pluralsh/console-client-go" + console "github.com/pluralsh/console/go/client" ) type provider struct { diff --git a/internal/resource/rbac_model.go b/internal/resource/rbac_model.go index 572611e..acb8e14 100644 --- a/internal/resource/rbac_model.go +++ b/internal/resource/rbac_model.go @@ -7,7 +7,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/types" - gqlclient "github.com/pluralsh/console-client-go" + gqlclient "github.com/pluralsh/console/go/client" ) type rbac struct { diff --git a/internal/resource/service_context_model.go b/internal/resource/service_context_model.go index 7a55c92..b6001e6 100644 --- a/internal/resource/service_context_model.go +++ b/internal/resource/service_context_model.go @@ -7,7 +7,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/types" - console "github.com/pluralsh/console-client-go" + console "github.com/pluralsh/console/go/client" ) type serviceContext struct { diff --git a/internal/resource/service_deployment_model.go b/internal/resource/service_deployment_model.go index ccebead..2f999f0 100644 --- a/internal/resource/service_deployment_model.go +++ b/internal/resource/service_deployment_model.go @@ -10,7 +10,7 @@ import ( "terraform-provider-plural/internal/common" "github.com/hashicorp/terraform-plugin-framework/types" - gqlclient "github.com/pluralsh/console-client-go" + gqlclient "github.com/pluralsh/console/go/client" "github.com/pluralsh/polly/algorithms" "github.com/samber/lo" ) From 392b0e85f1126d973f7408dd5dd78eb2e39fd137 Mon Sep 17 00:00:00 2001 From: Marcin Maciaszczyk Date: Wed, 24 Jul 2024 15:14:43 +0200 Subject: [PATCH 07/19] adjust code to the new schema --- internal/resource/infrastructure_stack_model.go | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/internal/resource/infrastructure_stack_model.go b/internal/resource/infrastructure_stack_model.go index ba79a80..e19c286 100644 --- a/internal/resource/infrastructure_stack_model.go +++ b/internal/resource/infrastructure_stack_model.go @@ -167,19 +167,15 @@ func (isr *InfrastructureStackRepository) Attributes() gqlclient.GitRefAttribute } } -func (isr *InfrastructureStackRepository) From(repository *gqlclient.GitRepositoryFragment, ref *gqlclient.GitRefFragment) { +func (isr *InfrastructureStackRepository) From(repository *gqlclient.GitRepositoryFragment, ref gqlclient.GitRefFragment) { + isr.Ref = types.StringValue(ref.Ref) + isr.Folder = types.StringValue(ref.Folder) + if isr == nil { return } isr.Id = types.StringValue(repository.ID) - - if ref == nil { - return - } - - isr.Ref = types.StringValue(ref.Ref) - isr.Folder = types.StringValue(ref.Folder) } type InfrastructureStackHookSpec struct { @@ -270,8 +266,8 @@ func (isc *InfrastructureStackConfiguration) Attributes(ctx context.Context, d d } } -func (isc *InfrastructureStackConfiguration) From(ctx context.Context, configuration *gqlclient.StackConfigurationFragment, d diag.Diagnostics) { - if isc == nil || configuration == nil { +func (isc *InfrastructureStackConfiguration) From(ctx context.Context, configuration gqlclient.StackConfigurationFragment, d diag.Diagnostics) { + if isc == nil { return } From cafa3d40964373203839ab54e5139d51ea4741ce Mon Sep 17 00:00:00 2001 From: Marcin Maciaszczyk Date: Wed, 24 Jul 2024 15:17:20 +0200 Subject: [PATCH 08/19] minor fix --- internal/resource/infrastructure_stack_model.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/internal/resource/infrastructure_stack_model.go b/internal/resource/infrastructure_stack_model.go index e19c286..f053a62 100644 --- a/internal/resource/infrastructure_stack_model.go +++ b/internal/resource/infrastructure_stack_model.go @@ -168,14 +168,13 @@ func (isr *InfrastructureStackRepository) Attributes() gqlclient.GitRefAttribute } func (isr *InfrastructureStackRepository) From(repository *gqlclient.GitRepositoryFragment, ref gqlclient.GitRefFragment) { - isr.Ref = types.StringValue(ref.Ref) - isr.Folder = types.StringValue(ref.Folder) - if isr == nil { return } isr.Id = types.StringValue(repository.ID) + isr.Ref = types.StringValue(ref.Ref) + isr.Folder = types.StringValue(ref.Folder) } type InfrastructureStackHookSpec struct { From 3efaf68b21e4ac78e044385fe43fcf8ebdc6dcc8 Mon Sep 17 00:00:00 2001 From: Marcin Maciaszczyk Date: Wed, 24 Jul 2024 16:17:24 +0200 Subject: [PATCH 09/19] use new client methods --- go.mod | 2 +- go.sum | 4 ++-- internal/resource/group.go | 36 ++++++++++++++++++------------------ 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/go.mod b/go.mod index b0d515c..982f163 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,7 @@ require ( github.com/hashicorp/terraform-plugin-framework-validators v0.12.0 github.com/hashicorp/terraform-plugin-log v0.9.0 github.com/mitchellh/go-homedir v1.1.0 - github.com/pluralsh/console/go/client v1.0.0 + github.com/pluralsh/console/go/client v1.2.0 github.com/pluralsh/plural-cli v0.8.5-0.20240216094552-efc34ee6de37 github.com/pluralsh/polly v0.1.7 github.com/samber/lo v1.38.1 diff --git a/go.sum b/go.sum index eb61398..9482001 100644 --- a/go.sum +++ b/go.sum @@ -859,8 +859,8 @@ github.com/pkg/sftp v1.10.1/go.mod h1:lYOWFsE0bwd1+KfKJaKeuokY15vzFx25BLbzYYoAxZ github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qRg= github.com/pluralsh/console-client-go v0.0.92 h1:PMSF05Zp5gLejeEWXbwe17CfXNLJ55dGlFPAAVucfCM= github.com/pluralsh/console-client-go v0.0.92/go.mod h1:eyCiLA44YbXiYyJh8303jk5JdPkt9McgCo5kBjk4lKo= -github.com/pluralsh/console/go/client v1.0.0 h1:jsKmDjZFNEYMg6xgOeIjRyP/2oJXYOQqjUGeA6i0v84= -github.com/pluralsh/console/go/client v1.0.0/go.mod h1:lpoWASYsM9keNePS3dpFiEisUHEfObIVlSL3tzpKn8k= +github.com/pluralsh/console/go/client v1.2.0 h1:LXrmLaVtKjQa1ZbV4JQFkA2ZTepq8xAsvLI46DOEpEY= +github.com/pluralsh/console/go/client v1.2.0/go.mod h1:lpoWASYsM9keNePS3dpFiEisUHEfObIVlSL3tzpKn8k= github.com/pluralsh/gqlclient v1.11.0 h1:FfXW7FiEJLHOfTAa7NxDb8jb3aMZNIpCAcG+bg8uHYA= github.com/pluralsh/gqlclient v1.11.0/go.mod h1:qSXKUlio1F2DRPy8el4oFYsmpKbkUYspgPB87T4it5I= github.com/pluralsh/plural-cli v0.8.5-0.20240216094552-efc34ee6de37 h1:DBnaKvKmbTbKwbkrh/2gJBwyHYfaXdxeT3UGh+94K4g= diff --git a/internal/resource/group.go b/internal/resource/group.go index 966f47d..54e0740 100644 --- a/internal/resource/group.go +++ b/internal/resource/group.go @@ -89,13 +89,13 @@ func (r *GroupResource) Create(ctx context.Context, req resource.CreateRequest, return } - //response, err := r.client.CreateGroup(ctx, data.Attributes()) - //if err != nil { - // resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to create group, got error: %s", err)) - // return - //} - // - //data.From(response.CreateGroup) + response, err := r.client.CreateGroup(ctx, data.Attributes()) + if err != nil { + resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to create group, got error: %s", err)) + return + } + + data.From(response.CreateGroup) resp.Diagnostics.Append(resp.State.Set(ctx, data)...) } @@ -106,7 +106,7 @@ func (r *GroupResource) Read(ctx context.Context, req resource.ReadRequest, resp return } - response, err := r.client.GetGroup(ctx, data.Name.ValueString()) // TODO: Immutable name? + response, err := r.client.GetGroup(ctx, data.Name.ValueString()) if err != nil { resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to get group, got error: %s", err)) return @@ -128,11 +128,11 @@ func (r *GroupResource) Update(ctx context.Context, req resource.UpdateRequest, return } - // _, err := r.client.UpdateGroup(ctx, data.Id.ValueString(), data.Attributes()) - //if err != nil { - // resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to update group, got error: %s", err)) - // return - //} + _, err := r.client.UpdateGroup(ctx, data.Id.ValueString(), data.Attributes()) + if err != nil { + resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to update group, got error: %s", err)) + return + } resp.Diagnostics.Append(resp.State.Set(ctx, data)...) } @@ -144,11 +144,11 @@ func (r *GroupResource) Delete(ctx context.Context, req resource.DeleteRequest, return } - //_, err := r.client.DeleteGroup(ctx, data.Id.ValueString()) - //if err != nil { - // resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to delete group, got error: %s", err)) - // return - //} + _, err := r.client.DeleteGroup(ctx, data.Id.ValueString()) + if err != nil { + resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to delete group, got error: %s", err)) + return + } } func (r *GroupResource) ImportState( From 8678c9a279a3bdb61f4fd59cebd7df76d0c3974d Mon Sep 17 00:00:00 2001 From: Marcin Maciaszczyk Date: Thu, 25 Jul 2024 10:52:14 +0200 Subject: [PATCH 10/19] fix group data source --- internal/datasource/group.go | 40 +++++++++++------------------- internal/datasource/group_model.go | 15 ++++++----- 2 files changed, 22 insertions(+), 33 deletions(-) diff --git a/internal/datasource/group.go b/internal/datasource/group.go index 2107bc3..5e40aea 100644 --- a/internal/datasource/group.go +++ b/internal/datasource/group.go @@ -7,12 +7,8 @@ import ( "terraform-provider-plural/internal/client" "terraform-provider-plural/internal/common" - "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" "github.com/hashicorp/terraform-plugin-framework/datasource" "github.com/hashicorp/terraform-plugin-framework/datasource/schema" - "github.com/hashicorp/terraform-plugin-framework/path" - "github.com/hashicorp/terraform-plugin-framework/schema/validator" - console "github.com/pluralsh/console/go/client" ) func NewGroupDataSource() datasource.DataSource { @@ -32,13 +28,18 @@ func (d *groupDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, MarkdownDescription: "A representation of a group to organize authorization in your plural console.", Attributes: map[string]schema.Attribute{ "id": schema.StringAttribute{ - Optional: true, - Computed: true, + Description: "Internal identifier of this group.", MarkdownDescription: "Internal identifier of this group.", - Validators: []validator.String{stringvalidator.ExactlyOneOf(path.MatchRoot("id"))}, + Computed: true, }, "name": schema.StringAttribute{ - MarkdownDescription: "Name of the group.", + Description: "Name of this group.", + MarkdownDescription: "Name of this group.", + Required: true, + }, + "description": schema.StringAttribute{ + Description: "Description of this group.", + MarkdownDescription: "Description of this group.", Computed: true, }, }, @@ -69,27 +70,16 @@ func (d *groupDataSource) Read(ctx context.Context, req datasource.ReadRequest, return } - if data.Name.IsNull() { - resp.Diagnostics.AddError( - "Missing group name", - "The provider could not read group data. Name must be specified.", - ) - } - - var group *console.GroupFragment - if !data.Name.IsNull() { - if c, err := d.client.GetGroup(ctx, data.Name.ValueString()); err != nil { - resp.Diagnostics.AddWarning("Client Error", fmt.Sprintf("Unable to read group by name, got error: %s", err)) - } else { - group = c.Group - } + response, err := d.client.GetGroup(ctx, data.Name.ValueString()) + if err != nil { + resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to read group by name, got error: %s", err)) } - if group == nil { - resp.Diagnostics.AddError("Client Error", "Unable to read group, see warnings for more information") + if response == nil || response.Group == nil { + resp.Diagnostics.AddError("Client Error", "Unable to find group, got no error") return } - data.From(group, ctx, resp.Diagnostics) + data.From(response.Group) resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) } diff --git a/internal/datasource/group_model.go b/internal/datasource/group_model.go index 4812f64..1412425 100644 --- a/internal/datasource/group_model.go +++ b/internal/datasource/group_model.go @@ -1,19 +1,18 @@ package datasource import ( - "context" - - "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/types" console "github.com/pluralsh/console/go/client" ) type group struct { - Id types.String `tfsdk:"id"` - Name types.String `tfsdk:"name"` + Id types.String `tfsdk:"id"` + Name types.String `tfsdk:"name"` + Description types.String `tfsdk:"description"` } -func (c *group) From(cl *console.GroupFragment, ctx context.Context, d diag.Diagnostics) { - c.Id = types.StringValue(cl.ID) - c.Name = types.StringValue(cl.Name) +func (g *group) From(gf *console.GroupFragment) { + g.Id = types.StringValue(gf.ID) + g.Name = types.StringValue(gf.Name) + g.Description = types.StringPointerValue(gf.Description) } From 81b04d79dc1a65a450ea982cfc3c3e008c2855b5 Mon Sep 17 00:00:00 2001 From: Marcin Maciaszczyk Date: Thu, 25 Jul 2024 11:14:46 +0200 Subject: [PATCH 11/19] fix user data source --- internal/datasource/user.go | 27 +++++++-------------------- internal/datasource/user_model.go | 5 +---- 2 files changed, 8 insertions(+), 24 deletions(-) diff --git a/internal/datasource/user.go b/internal/datasource/user.go index 5858091..04159ca 100644 --- a/internal/datasource/user.go +++ b/internal/datasource/user.go @@ -12,7 +12,6 @@ import ( "github.com/hashicorp/terraform-plugin-framework/datasource/schema" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/schema/validator" - console "github.com/pluralsh/console/go/client" ) func NewUserDataSource() datasource.DataSource { @@ -43,7 +42,7 @@ func (d *userDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, r }, "email": schema.StringAttribute{ MarkdownDescription: "Email address of this user.", - Computed: true, + Required: true, Validators: []validator.String{stringvalidator.ExactlyOneOf(path.MatchRoot("id"))}, }, }, @@ -74,28 +73,16 @@ func (d *userDataSource) Read(ctx context.Context, req datasource.ReadRequest, r return } - if data.Email.IsNull() { - resp.Diagnostics.AddError( - "Missing user email", - "The provider could not read user data. Email must be specified.", - ) - } - - // First try to fetch cluster by ID if it was provided. - var user *console.UserFragment - if !data.Email.IsNull() { - if c, err := d.client.GetUser(ctx, data.Email.ValueString()); err != nil { - resp.Diagnostics.AddWarning("Client Error", fmt.Sprintf("Unable to read user by email, got error: %s", err)) - } else { - user = c.User - } + response, err := d.client.GetUser(ctx, data.Email.ValueString()) + if err != nil { + resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to read user by email, got error: %s", err)) } - if user == nil { - resp.Diagnostics.AddError("Client Error", "Unable to read user, see warnings for more information") + if response == nil || response.User == nil { + resp.Diagnostics.AddError("Client Error", "Unable to find user, got no error") return } - data.From(user, ctx, resp.Diagnostics) + data.From(response.User) resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) } diff --git a/internal/datasource/user_model.go b/internal/datasource/user_model.go index 41c122e..e9513f1 100644 --- a/internal/datasource/user_model.go +++ b/internal/datasource/user_model.go @@ -1,9 +1,6 @@ package datasource import ( - "context" - - "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/types" console "github.com/pluralsh/console/go/client" ) @@ -14,7 +11,7 @@ type user struct { Email types.String `tfsdk:"email"` } -func (c *user) From(cl *console.UserFragment, ctx context.Context, d diag.Diagnostics) { +func (c *user) From(cl *console.UserFragment) { c.Id = types.StringValue(cl.ID) c.Name = types.StringValue(cl.Name) c.Email = types.StringValue(cl.Email) From ecc817d9a0357b9802c2784810618ef9b74a7656 Mon Sep 17 00:00:00 2001 From: Marcin Maciaszczyk Date: Thu, 25 Jul 2024 11:31:01 +0200 Subject: [PATCH 12/19] start using common model package --- internal/datasource/group.go | 3 +- internal/datasource/group_model.go | 18 ----- internal/datasource/project.go | 4 +- internal/datasource/user.go | 3 +- internal/model/global_service.go | 65 +++++++++++++++++++ .../group_model.go => model/group.go} | 8 +-- internal/model/group_member.go | 18 +++++ .../project_model.go => model/project.go} | 14 ++-- .../{resource/rbac_model.go => model/rbac.go} | 10 +-- .../service_context.go} | 12 ++-- .../user_model.go => model/user.go} | 12 ++-- internal/resource/global_service.go | 9 +-- internal/resource/global_service_model.go | 65 ------------------- internal/resource/group.go | 9 +-- internal/resource/group_member.go | 5 +- internal/resource/group_member_model.go | 18 ----- internal/resource/project.go | 7 +- internal/resource/rbac.go | 6 +- 18 files changed, 138 insertions(+), 148 deletions(-) delete mode 100644 internal/datasource/group_model.go create mode 100644 internal/model/global_service.go rename internal/{resource/group_model.go => model/group.go} (77%) create mode 100644 internal/model/group_member.go rename internal/{resource/project_model.go => model/project.go} (72%) rename internal/{resource/rbac_model.go => model/rbac.go} (63%) rename internal/{resource/service_context_model.go => model/service_context.go} (76%) rename internal/{datasource/user_model.go => model/user.go} (51%) delete mode 100644 internal/resource/global_service_model.go delete mode 100644 internal/resource/group_member_model.go diff --git a/internal/datasource/group.go b/internal/datasource/group.go index 5e40aea..309c642 100644 --- a/internal/datasource/group.go +++ b/internal/datasource/group.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/datasource" "github.com/hashicorp/terraform-plugin-framework/datasource/schema" @@ -64,7 +65,7 @@ func (d *groupDataSource) Configure(_ context.Context, req datasource.ConfigureR } func (d *groupDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { - var data group + var data model.Group resp.Diagnostics.Append(req.Config.Get(ctx, &data)...) if resp.Diagnostics.HasError() { return diff --git a/internal/datasource/group_model.go b/internal/datasource/group_model.go deleted file mode 100644 index 1412425..0000000 --- a/internal/datasource/group_model.go +++ /dev/null @@ -1,18 +0,0 @@ -package datasource - -import ( - "github.com/hashicorp/terraform-plugin-framework/types" - console "github.com/pluralsh/console/go/client" -) - -type group struct { - Id types.String `tfsdk:"id"` - Name types.String `tfsdk:"name"` - Description types.String `tfsdk:"description"` -} - -func (g *group) From(gf *console.GroupFragment) { - g.Id = types.StringValue(gf.ID) - g.Name = types.StringValue(gf.Name) - g.Description = types.StringPointerValue(gf.Description) -} diff --git a/internal/datasource/project.go b/internal/datasource/project.go index b3afeba..2149862 100644 --- a/internal/datasource/project.go +++ b/internal/datasource/project.go @@ -6,7 +6,7 @@ import ( "terraform-provider-plural/internal/client" "terraform-provider-plural/internal/common" - "terraform-provider-plural/internal/resource" + "terraform-provider-plural/internal/model" "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" "github.com/hashicorp/terraform-plugin-framework/datasource" @@ -117,7 +117,7 @@ func (d *projectDataSource) Configure(_ context.Context, req datasource.Configur } func (d *projectDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { - data := new(resource.Project) + data := new(model.Project) resp.Diagnostics.Append(req.Config.Get(ctx, data)...) if resp.Diagnostics.HasError() { return diff --git a/internal/datasource/user.go b/internal/datasource/user.go index 04159ca..5cb9816 100644 --- a/internal/datasource/user.go +++ b/internal/datasource/user.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-validators/stringvalidator" "github.com/hashicorp/terraform-plugin-framework/datasource" @@ -67,7 +68,7 @@ func (d *userDataSource) Configure(_ context.Context, req datasource.ConfigureRe } func (d *userDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { - var data user + var data model.User resp.Diagnostics.Append(req.Config.Get(ctx, &data)...) if resp.Diagnostics.HasError() { return diff --git a/internal/model/global_service.go b/internal/model/global_service.go new file mode 100644 index 0000000..4190785 --- /dev/null +++ b/internal/model/global_service.go @@ -0,0 +1,65 @@ +package model + +import ( + "context" + "strings" + + "terraform-provider-plural/internal/common" + + "github.com/hashicorp/terraform-plugin-framework/diag" + "github.com/hashicorp/terraform-plugin-framework/types" + gqlclient "github.com/pluralsh/console/go/client" + "github.com/samber/lo" +) + +type GlobalService struct { + Id types.String `tfsdk:"id"` + Name types.String `tfsdk:"name"` + ServiceId types.String `tfsdk:"service_id"` + Distro types.String `tfsdk:"distro"` + ProviderId types.String `tfsdk:"provider_id"` + Tags types.Map `tfsdk:"tags"` +} + +func (gs *GlobalService) From(response *gqlclient.GlobalServiceFragment, d diag.Diagnostics) { + gs.Id = types.StringValue(response.ID) + gs.Name = types.StringValue(response.Name) + gs.ServiceId = types.StringValue(response.Service.ID) + if response.Distro != nil { + gs.Distro = types.StringValue(string(*response.Distro)) + } + if response.Provider != nil { + gs.ProviderId = types.StringValue(response.Provider.ID) + } + gs.Tags = common.TagsFrom(response.Tags, gs.Tags, d) + +} + +func (gs *GlobalService) Attributes(ctx context.Context, d diag.Diagnostics) gqlclient.GlobalServiceAttributes { + var distro *gqlclient.ClusterDistro + if !gs.Distro.IsNull() { + distro = lo.ToPtr(gqlclient.ClusterDistro(strings.ToUpper(gs.Distro.ValueString()))) + } + return gqlclient.GlobalServiceAttributes{ + Name: gs.Name.ValueString(), + Distro: distro, + ProviderID: gs.ProviderId.ValueStringPointer(), + Tags: gs.TagsAttribute(ctx, d), + } +} + +func (gs *GlobalService) TagsAttribute(ctx context.Context, d diag.Diagnostics) []*gqlclient.TagAttributes { + if gs.Tags.IsNull() { + return nil + } + + result := make([]*gqlclient.TagAttributes, 0) + elements := make(map[string]types.String, len(gs.Tags.Elements())) + d.Append(gs.Tags.ElementsAs(ctx, &elements, false)...) + + for k, v := range elements { + result = append(result, &gqlclient.TagAttributes{Name: k, Value: v.ValueString()}) + } + + return result +} diff --git a/internal/resource/group_model.go b/internal/model/group.go similarity index 77% rename from internal/resource/group_model.go rename to internal/model/group.go index ed5b752..23c069a 100644 --- a/internal/resource/group_model.go +++ b/internal/model/group.go @@ -1,23 +1,23 @@ -package resource +package model import ( "github.com/hashicorp/terraform-plugin-framework/types" gqlclient "github.com/pluralsh/console/go/client" ) -type group struct { +type Group struct { Id types.String `tfsdk:"id"` Name types.String `tfsdk:"name"` Description types.String `tfsdk:"description"` } -func (g *group) From(response *gqlclient.GroupFragment) { +func (g *Group) From(response *gqlclient.GroupFragment) { g.Id = types.StringValue(response.ID) g.Name = types.StringValue(response.Name) g.Name = types.StringPointerValue(response.Description) } -func (g *group) Attributes() gqlclient.GroupAttributes { +func (g *Group) Attributes() gqlclient.GroupAttributes { return gqlclient.GroupAttributes{ Name: g.Name.ValueString(), Description: g.Description.ValueStringPointer(), diff --git a/internal/model/group_member.go b/internal/model/group_member.go new file mode 100644 index 0000000..910c4f0 --- /dev/null +++ b/internal/model/group_member.go @@ -0,0 +1,18 @@ +package model + +import ( + "github.com/hashicorp/terraform-plugin-framework/types" + gqlclient "github.com/pluralsh/console/go/client" +) + +type GroupMember struct { + Id types.String `tfsdk:"id"` + UserId types.String `tfsdk:"user_id"` + GroupId types.String `tfsdk:"group_id"` +} + +func (gm *GroupMember) From(response *gqlclient.GroupMemberFragment) { + gm.Id = types.StringValue(response.ID) + gm.UserId = types.StringValue(response.User.ID) + gm.GroupId = types.StringValue(response.Group.ID) +} diff --git a/internal/resource/project_model.go b/internal/model/project.go similarity index 72% rename from internal/resource/project_model.go rename to internal/model/project.go index 36ce84b..2d981ab 100644 --- a/internal/resource/project_model.go +++ b/internal/model/project.go @@ -1,4 +1,4 @@ -package resource +package model import ( "context" @@ -27,12 +27,12 @@ func (p *Project) Attributes(ctx context.Context, d diag.Diagnostics) (*gqlclien }, nil } -func (p *Project) From(project *gqlclient.ProjectFragment, ctx context.Context, d diag.Diagnostics) { - p.Id = types.StringValue(project.ID) - p.Name = types.StringValue(project.Name) - p.Description = types.StringPointerValue(project.Description) - p.Default = defaultFrom(project.Default) - p.Bindings.From(project.ReadBindings, project.WriteBindings, ctx, d) +func (p *Project) From(response *gqlclient.ProjectFragment, ctx context.Context, d diag.Diagnostics) { + p.Id = types.StringValue(response.ID) + p.Name = types.StringValue(response.Name) + p.Description = types.StringPointerValue(response.Description) + p.Default = defaultFrom(response.Default) + p.Bindings.From(response.ReadBindings, response.WriteBindings, ctx, d) } func defaultFrom(def *bool) types.Bool { diff --git a/internal/resource/rbac_model.go b/internal/model/rbac.go similarity index 63% rename from internal/resource/rbac_model.go rename to internal/model/rbac.go index acb8e14..66f3690 100644 --- a/internal/resource/rbac_model.go +++ b/internal/model/rbac.go @@ -1,4 +1,4 @@ -package resource +package model import ( "context" @@ -10,15 +10,15 @@ import ( gqlclient "github.com/pluralsh/console/go/client" ) -type rbac struct { +type RBAC struct { ClusterId types.String `tfsdk:"cluster_id"` ServiceId types.String `tfsdk:"service_id"` Bindings *common.Bindings `tfsdk:"rbac"` } -func (g *rbac) Attributes(ctx context.Context, d diag.Diagnostics) gqlclient.RbacAttributes { +func (rbac *RBAC) Attributes(ctx context.Context, d diag.Diagnostics) gqlclient.RbacAttributes { return gqlclient.RbacAttributes{ - ReadBindings: g.Bindings.ReadAttributes(ctx, d), - WriteBindings: g.Bindings.WriteAttributes(ctx, d), + ReadBindings: rbac.Bindings.ReadAttributes(ctx, d), + WriteBindings: rbac.Bindings.WriteAttributes(ctx, d), } } diff --git a/internal/resource/service_context_model.go b/internal/model/service_context.go similarity index 76% rename from internal/resource/service_context_model.go rename to internal/model/service_context.go index b6001e6..00a42bd 100644 --- a/internal/resource/service_context_model.go +++ b/internal/model/service_context.go @@ -1,4 +1,4 @@ -package resource +package model import ( "context" @@ -10,19 +10,19 @@ import ( console "github.com/pluralsh/console/go/client" ) -type serviceContext struct { +type ServiceContext struct { Id types.String `tfsdk:"id"` Name types.String `tfsdk:"name"` Configuration types.Map `tfsdk:"configuration"` Secrets types.Map `tfsdk:"secrets"` } -func (sc *serviceContext) From(scf *console.ServiceContextFragment, ctx context.Context, d diag.Diagnostics) { - sc.Id = types.StringValue(scf.ID) - sc.Configuration = common.MapFrom(scf.Configuration, ctx, d) +func (sc *ServiceContext) From(response *console.ServiceContextFragment, ctx context.Context, d diag.Diagnostics) { + sc.Id = types.StringValue(response.ID) + sc.Configuration = common.MapFrom(response.Configuration, ctx, d) } -func (sc *serviceContext) Attributes(ctx context.Context, d diag.Diagnostics) console.ServiceContextAttributes { +func (sc *ServiceContext) Attributes(ctx context.Context, d diag.Diagnostics) console.ServiceContextAttributes { configuration := make(map[string]types.String, len(sc.Configuration.Elements())) sc.Configuration.ElementsAs(ctx, &configuration, false) diff --git a/internal/datasource/user_model.go b/internal/model/user.go similarity index 51% rename from internal/datasource/user_model.go rename to internal/model/user.go index e9513f1..0a051d1 100644 --- a/internal/datasource/user_model.go +++ b/internal/model/user.go @@ -1,18 +1,18 @@ -package datasource +package model import ( "github.com/hashicorp/terraform-plugin-framework/types" console "github.com/pluralsh/console/go/client" ) -type user struct { +type User struct { Id types.String `tfsdk:"id"` Name types.String `tfsdk:"name"` Email types.String `tfsdk:"email"` } -func (c *user) From(cl *console.UserFragment) { - c.Id = types.StringValue(cl.ID) - c.Name = types.StringValue(cl.Name) - c.Email = types.StringValue(cl.Email) +func (u *User) From(response *console.UserFragment) { + u.Id = types.StringValue(response.ID) + u.Name = types.StringValue(response.Name) + u.Email = types.StringValue(response.Email) } diff --git a/internal/resource/global_service.go b/internal/resource/global_service.go index cee5e46..a1e97b9 100644 --- a/internal/resource/global_service.go +++ b/internal/resource/global_service.go @@ -5,6 +5,7 @@ import ( "fmt" "terraform-provider-plural/internal/common" + "terraform-provider-plural/internal/model" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" @@ -102,7 +103,7 @@ func (r *GlobalServiceResource) Configure( } func (r *GlobalServiceResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { - data := new(globalService) + data := new(model.GlobalService) resp.Diagnostics.Append(req.Plan.Get(ctx, data)...) if resp.Diagnostics.HasError() { return @@ -119,7 +120,7 @@ func (r *GlobalServiceResource) Create(ctx context.Context, req resource.CreateR } func (r *GlobalServiceResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { - data := new(globalService) + data := new(model.GlobalService) resp.Diagnostics.Append(req.State.Get(ctx, data)...) if resp.Diagnostics.HasError() { return @@ -129,7 +130,7 @@ func (r *GlobalServiceResource) Read(ctx context.Context, req resource.ReadReque } func (r *GlobalServiceResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { - data := new(globalService) + data := new(model.GlobalService) resp.Diagnostics.Append(req.Plan.Get(ctx, data)...) if resp.Diagnostics.HasError() { return @@ -145,7 +146,7 @@ func (r *GlobalServiceResource) Update(ctx context.Context, req resource.UpdateR } func (r *GlobalServiceResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { - data := new(globalService) + data := new(model.GlobalService) resp.Diagnostics.Append(req.State.Get(ctx, data)...) if resp.Diagnostics.HasError() { return diff --git a/internal/resource/global_service_model.go b/internal/resource/global_service_model.go deleted file mode 100644 index fb610e8..0000000 --- a/internal/resource/global_service_model.go +++ /dev/null @@ -1,65 +0,0 @@ -package resource - -import ( - "context" - "strings" - - "terraform-provider-plural/internal/common" - - "github.com/hashicorp/terraform-plugin-framework/diag" - "github.com/hashicorp/terraform-plugin-framework/types" - gqlclient "github.com/pluralsh/console/go/client" - "github.com/samber/lo" -) - -type globalService struct { - Id types.String `tfsdk:"id"` - Name types.String `tfsdk:"name"` - ServiceId types.String `tfsdk:"service_id"` - Distro types.String `tfsdk:"distro"` - ProviderId types.String `tfsdk:"provider_id"` - Tags types.Map `tfsdk:"tags"` -} - -func (g *globalService) From(response *gqlclient.GlobalServiceFragment, d diag.Diagnostics) { - g.Id = types.StringValue(response.ID) - g.Name = types.StringValue(response.Name) - g.ServiceId = types.StringValue(response.Service.ID) - if response.Distro != nil { - g.Distro = types.StringValue(string(*response.Distro)) - } - if response.Provider != nil { - g.ProviderId = types.StringValue(response.Provider.ID) - } - g.Tags = common.TagsFrom(response.Tags, g.Tags, d) - -} - -func (g *globalService) Attributes(ctx context.Context, d diag.Diagnostics) gqlclient.GlobalServiceAttributes { - var distro *gqlclient.ClusterDistro - if !g.Distro.IsNull() { - distro = lo.ToPtr(gqlclient.ClusterDistro(strings.ToUpper(g.Distro.ValueString()))) - } - return gqlclient.GlobalServiceAttributes{ - Name: g.Name.ValueString(), - Distro: distro, - ProviderID: g.ProviderId.ValueStringPointer(), - Tags: g.TagsAttribute(ctx, d), - } -} - -func (g *globalService) TagsAttribute(ctx context.Context, d diag.Diagnostics) []*gqlclient.TagAttributes { - if g.Tags.IsNull() { - return nil - } - - result := make([]*gqlclient.TagAttributes, 0) - elements := make(map[string]types.String, len(g.Tags.Elements())) - d.Append(g.Tags.ElementsAs(ctx, &elements, false)...) - - for k, v := range elements { - result = append(result, &gqlclient.TagAttributes{Name: k, Value: v.ValueString()}) - } - - return result -} diff --git a/internal/resource/group.go b/internal/resource/group.go index 54e0740..980d90c 100644 --- a/internal/resource/group.go +++ b/internal/resource/group.go @@ -5,6 +5,7 @@ import ( "fmt" "terraform-provider-plural/internal/common" + "terraform-provider-plural/internal/model" "terraform-provider-plural/internal/client" @@ -83,7 +84,7 @@ func (r *GroupResource) Configure( } func (r *GroupResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { - data := new(group) + data := new(model.Group) resp.Diagnostics.Append(req.Plan.Get(ctx, data)...) if resp.Diagnostics.HasError() { return @@ -100,7 +101,7 @@ func (r *GroupResource) Create(ctx context.Context, req resource.CreateRequest, } func (r *GroupResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { - data := new(group) + data := new(model.Group) resp.Diagnostics.Append(req.State.Get(ctx, data)...) if resp.Diagnostics.HasError() { return @@ -122,7 +123,7 @@ func (r *GroupResource) Read(ctx context.Context, req resource.ReadRequest, resp } func (r *GroupResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { - data := new(group) + data := new(model.Group) resp.Diagnostics.Append(req.Plan.Get(ctx, data)...) if resp.Diagnostics.HasError() { return @@ -138,7 +139,7 @@ func (r *GroupResource) Update(ctx context.Context, req resource.UpdateRequest, } func (r *GroupResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { - data := new(group) + data := new(model.Group) resp.Diagnostics.Append(req.State.Get(ctx, data)...) if resp.Diagnostics.HasError() { return diff --git a/internal/resource/group_member.go b/internal/resource/group_member.go index 7b7997f..b471c9f 100644 --- a/internal/resource/group_member.go +++ b/internal/resource/group_member.go @@ -5,6 +5,7 @@ import ( "fmt" "terraform-provider-plural/internal/common" + "terraform-provider-plural/internal/model" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" @@ -83,7 +84,7 @@ func (r *GroupMemberResource) Configure( } func (r *GroupMemberResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { - data := new(groupMember) + data := new(model.GroupMember) resp.Diagnostics.Append(req.Plan.Get(ctx, data)...) if resp.Diagnostics.HasError() { return @@ -108,7 +109,7 @@ func (r *GroupMemberResource) Update(_ context.Context, _ resource.UpdateRequest } func (r *GroupMemberResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { - data := new(groupMember) + data := new(model.GroupMember) resp.Diagnostics.Append(req.State.Get(ctx, data)...) if resp.Diagnostics.HasError() { return diff --git a/internal/resource/group_member_model.go b/internal/resource/group_member_model.go deleted file mode 100644 index ad594be..0000000 --- a/internal/resource/group_member_model.go +++ /dev/null @@ -1,18 +0,0 @@ -package resource - -import ( - "github.com/hashicorp/terraform-plugin-framework/types" - gqlclient "github.com/pluralsh/console/go/client" -) - -type groupMember struct { - Id types.String `tfsdk:"id"` - UserId types.String `tfsdk:"user_id"` - GroupId types.String `tfsdk:"group_id"` -} - -func (g *groupMember) From(response *gqlclient.GroupMemberFragment) { - g.Id = types.StringValue(response.ID) - g.UserId = types.StringValue(response.User.ID) - g.GroupId = types.StringValue(response.Group.ID) -} diff --git a/internal/resource/project.go b/internal/resource/project.go index fab24b4..18e3cac 100644 --- a/internal/resource/project.go +++ b/internal/resource/project.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" @@ -124,7 +125,7 @@ func (r *ProjectResource) Configure(_ context.Context, req resource.ConfigureReq } func (r *ProjectResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { - data := new(Project) + data := new(model.Project) resp.Diagnostics.Append(req.Plan.Get(ctx, data)...) if resp.Diagnostics.HasError() { return @@ -146,7 +147,7 @@ func (r *ProjectResource) Create(ctx context.Context, req resource.CreateRequest } func (r *ProjectResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { - data := new(Project) + data := new(model.Project) resp.Diagnostics.Append(req.State.Get(ctx, data)...) if resp.Diagnostics.HasError() { return @@ -163,7 +164,7 @@ func (r *ProjectResource) Read(ctx context.Context, req resource.ReadRequest, re } func (r *ProjectResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { - data := new(Project) + data := new(model.Project) resp.Diagnostics.Append(req.Plan.Get(ctx, data)...) if resp.Diagnostics.HasError() { return diff --git a/internal/resource/rbac.go b/internal/resource/rbac.go index 4d8a0a6..b76c4a3 100644 --- a/internal/resource/rbac.go +++ b/internal/resource/rbac.go @@ -4,6 +4,8 @@ import ( "context" "fmt" + "terraform-provider-plural/internal/model" + "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" @@ -120,7 +122,7 @@ func (r *rbacResource) Configure(_ context.Context, req resource.ConfigureReques } func (r *rbacResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { - var data rbac + var data model.RBAC resp.Diagnostics.Append(req.Plan.Get(ctx, data)...) if resp.Diagnostics.HasError() { return @@ -140,7 +142,7 @@ func (r *rbacResource) Read(ctx context.Context, req resource.ReadRequest, resp } func (r *rbacResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { - var data rbac + var data model.RBAC resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...) if resp.Diagnostics.HasError() { return From f46a276ab79eb030331f3a6882a09b8ceefd70b8 Mon Sep 17 00:00:00 2001 From: Marcin Maciaszczyk Date: Thu, 25 Jul 2024 12:11:06 +0200 Subject: [PATCH 13/19] further refactoring --- example/gitrepository/main.tf | 24 +++++++++++ internal/datasource/git_repository.go | 3 +- internal/datasource/git_repository_model.go | 16 ------- internal/model/git_repository.go | 48 +++++++++++++++++++++ internal/resource/git_repository.go | 9 ++-- internal/resource/git_repository_model.go | 36 ---------------- internal/resource/global_service.go | 1 - internal/resource/service_context.go | 9 ++-- 8 files changed, 84 insertions(+), 62 deletions(-) create mode 100644 example/gitrepository/main.tf delete mode 100644 internal/datasource/git_repository_model.go create mode 100644 internal/model/git_repository.go delete mode 100644 internal/resource/git_repository_model.go diff --git a/example/gitrepository/main.tf b/example/gitrepository/main.tf new file mode 100644 index 0000000..9882d0f --- /dev/null +++ b/example/gitrepository/main.tf @@ -0,0 +1,24 @@ +terraform { + required_providers { + plural = { + source = "pluralsh/plural" + version = "0.2.1" + } + } +} + +provider "plural" { + use_cli = true +} + +data "plural_cluster" "cluster" { + handle = "mgmt" +} + +data "plural_git_repository" "repository" { + url = "https://github.com/zreigz/tf-hello.git" +} + +resource "plural_git_repository" "repository" { + url = "https://github.com/zreigz/tf-hello.git" +} diff --git a/internal/datasource/git_repository.go b/internal/datasource/git_repository.go index 029c4d6..94fc692 100644 --- a/internal/datasource/git_repository.go +++ b/internal/datasource/git_repository.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-validators/stringvalidator" "github.com/hashicorp/terraform-plugin-framework/datasource" @@ -70,7 +71,7 @@ func (r *GitRepositoryDataSource) Configure(_ context.Context, req datasource.Co } func (r *GitRepositoryDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { - data := new(gitRepository) + data := new(model.GitRepository) resp.Diagnostics.Append(req.Config.Get(ctx, data)...) if resp.Diagnostics.HasError() { return diff --git a/internal/datasource/git_repository_model.go b/internal/datasource/git_repository_model.go deleted file mode 100644 index 6a4cbe2..0000000 --- a/internal/datasource/git_repository_model.go +++ /dev/null @@ -1,16 +0,0 @@ -package datasource - -import ( - "github.com/hashicorp/terraform-plugin-framework/types" - gqlclient "github.com/pluralsh/console/go/client" -) - -type gitRepository struct { - Id types.String `tfsdk:"id"` - Url types.String `tfsdk:"url"` -} - -func (g *gitRepository) From(response *gqlclient.GitRepositoryFragment) { - g.Id = types.StringValue(response.ID) - g.Url = types.StringValue(response.URL) -} diff --git a/internal/model/git_repository.go b/internal/model/git_repository.go new file mode 100644 index 0000000..c8816aa --- /dev/null +++ b/internal/model/git_repository.go @@ -0,0 +1,48 @@ +package model + +import ( + "github.com/hashicorp/terraform-plugin-framework/types" + gqlclient "github.com/pluralsh/console/go/client" +) + +// TODO: Embed structs like these once it will be supported: https://github.com/hashicorp/terraform-plugin-framework/pull/1021 + +type GitRepository struct { + Id types.String `tfsdk:"id"` + Url types.String `tfsdk:"url"` +} + +func (gr *GitRepository) From(response *gqlclient.GitRepositoryFragment) { + gr.Id = types.StringValue(response.ID) + gr.Url = types.StringValue(response.URL) +} + +type GitRepositoryExtended struct { + Id types.String `tfsdk:"id"` + Url types.String `tfsdk:"url"` + PrivateKey types.String `tfsdk:"private_key"` + Passphrase types.String `tfsdk:"passphrase"` + Username types.String `tfsdk:"username"` + Password types.String `tfsdk:"password"` + UrlFormat types.String `tfsdk:"url_format"` + HttpsPath types.String `tfsdk:"https_path"` + Decrypt types.Bool `tfsdk:"decrypt"` +} + +func (gre *GitRepositoryExtended) From(response *gqlclient.GitRepositoryFragment) { + gre.Id = types.StringValue(response.ID) + gre.Url = types.StringValue(response.URL) +} + +func (gre *GitRepositoryExtended) Attributes() gqlclient.GitAttributes { + return gqlclient.GitAttributes{ + URL: gre.Url.ValueString(), + PrivateKey: gre.PrivateKey.ValueStringPointer(), + Passphrase: gre.Passphrase.ValueStringPointer(), + Username: gre.Username.ValueStringPointer(), + Password: gre.Password.ValueStringPointer(), + HTTPSPath: gre.HttpsPath.ValueStringPointer(), + URLFormat: gre.UrlFormat.ValueStringPointer(), + Decrypt: gre.Decrypt.ValueBoolPointer(), + } +} diff --git a/internal/resource/git_repository.go b/internal/resource/git_repository.go index c4886cb..5d28b28 100644 --- a/internal/resource/git_repository.go +++ b/internal/resource/git_repository.go @@ -5,6 +5,7 @@ import ( "fmt" "terraform-provider-plural/internal/common" + "terraform-provider-plural/internal/model" "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" "github.com/hashicorp/terraform-plugin-framework/path" @@ -144,7 +145,7 @@ func (r *GitRepositoryResource) Configure( } func (r *GitRepositoryResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { - data := new(gitRepository) + data := new(model.GitRepositoryExtended) resp.Diagnostics.Append(req.Plan.Get(ctx, data)...) if resp.Diagnostics.HasError() { return @@ -161,7 +162,7 @@ func (r *GitRepositoryResource) Create(ctx context.Context, req resource.CreateR } func (r *GitRepositoryResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { - data := new(gitRepository) + data := new(model.GitRepositoryExtended) resp.Diagnostics.Append(req.State.Get(ctx, data)...) if resp.Diagnostics.HasError() { return @@ -183,7 +184,7 @@ func (r *GitRepositoryResource) Read(ctx context.Context, req resource.ReadReque } func (r *GitRepositoryResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { - data := new(gitRepository) + data := new(model.GitRepositoryExtended) resp.Diagnostics.Append(req.Plan.Get(ctx, data)...) if resp.Diagnostics.HasError() { return @@ -199,7 +200,7 @@ func (r *GitRepositoryResource) Update(ctx context.Context, req resource.UpdateR } func (r *GitRepositoryResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { - data := new(gitRepository) + data := new(model.GitRepositoryExtended) resp.Diagnostics.Append(req.State.Get(ctx, data)...) if resp.Diagnostics.HasError() { return diff --git a/internal/resource/git_repository_model.go b/internal/resource/git_repository_model.go deleted file mode 100644 index faca525..0000000 --- a/internal/resource/git_repository_model.go +++ /dev/null @@ -1,36 +0,0 @@ -package resource - -import ( - "github.com/hashicorp/terraform-plugin-framework/types" - gqlclient "github.com/pluralsh/console/go/client" -) - -type gitRepository struct { - Id types.String `tfsdk:"id"` - Url types.String `tfsdk:"url"` - PrivateKey types.String `tfsdk:"private_key"` - Passphrase types.String `tfsdk:"passphrase"` - Username types.String `tfsdk:"username"` - Password types.String `tfsdk:"password"` - UrlFormat types.String `tfsdk:"url_format"` - HttpsPath types.String `tfsdk:"https_path"` - Decrypt types.Bool `tfsdk:"decrypt"` -} - -func (g *gitRepository) From(response *gqlclient.GitRepositoryFragment) { - g.Id = types.StringValue(response.ID) - g.Url = types.StringValue(response.URL) -} - -func (g *gitRepository) Attributes() gqlclient.GitAttributes { - return gqlclient.GitAttributes{ - URL: g.Url.ValueString(), - PrivateKey: g.PrivateKey.ValueStringPointer(), - Passphrase: g.Passphrase.ValueStringPointer(), - Username: g.Username.ValueStringPointer(), - Password: g.Password.ValueStringPointer(), - HTTPSPath: g.HttpsPath.ValueStringPointer(), - URLFormat: g.UrlFormat.ValueStringPointer(), - Decrypt: g.Decrypt.ValueBoolPointer(), - } -} diff --git a/internal/resource/global_service.go b/internal/resource/global_service.go index a1e97b9..7f1c9e9 100644 --- a/internal/resource/global_service.go +++ b/internal/resource/global_service.go @@ -63,7 +63,6 @@ func (r *GlobalServiceResource) Schema(_ context.Context, _ resource.SchemaReque MarkdownDescription: "Id of a CAPI provider that this global service targets.", }, "service_id": schema.StringAttribute{ - Optional: true, Required: true, Description: "The id of the service that will be replicated by this global service.", MarkdownDescription: "The id of the service that will be replicated by this global service.", diff --git a/internal/resource/service_context.go b/internal/resource/service_context.go index a43e892..4a0444f 100644 --- a/internal/resource/service_context.go +++ b/internal/resource/service_context.go @@ -5,6 +5,7 @@ import ( "fmt" "terraform-provider-plural/internal/common" + "terraform-provider-plural/internal/model" "terraform-provider-plural/internal/client" @@ -84,7 +85,7 @@ func (r *ServiceContextResource) Configure(_ context.Context, req resource.Confi } func (r *ServiceContextResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { - data := new(serviceContext) + data := new(model.ServiceContext) resp.Diagnostics.Append(req.Plan.Get(ctx, data)...) if resp.Diagnostics.HasError() { return @@ -101,7 +102,7 @@ func (r *ServiceContextResource) Create(ctx context.Context, req resource.Create } func (r *ServiceContextResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { - data := new(serviceContext) + data := new(model.ServiceContext) resp.Diagnostics.Append(req.State.Get(ctx, data)...) if resp.Diagnostics.HasError() { return @@ -118,7 +119,7 @@ func (r *ServiceContextResource) Read(ctx context.Context, req resource.ReadRequ } func (r *ServiceContextResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { - data := new(serviceContext) + data := new(model.ServiceContext) resp.Diagnostics.Append(req.Plan.Get(ctx, data)...) if resp.Diagnostics.HasError() { return @@ -134,7 +135,7 @@ func (r *ServiceContextResource) Update(ctx context.Context, req resource.Update } func (r *ServiceContextResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { - data := new(serviceContext) + data := new(model.ServiceContext) resp.Diagnostics.Append(req.State.Get(ctx, data)...) if resp.Diagnostics.HasError() { return From 584fce6aeab028fadad79e57a83bc7da1e0f2b0f Mon Sep 17 00:00:00 2001 From: Marcin Maciaszczyk Date: Thu, 25 Jul 2024 12:30:05 +0200 Subject: [PATCH 14/19] fix group data source --- example/user/main.tf | 20 ++++++++++++++++++++ internal/model/group.go | 2 +- 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 example/user/main.tf diff --git a/example/user/main.tf b/example/user/main.tf new file mode 100644 index 0000000..4a1aaa1 --- /dev/null +++ b/example/user/main.tf @@ -0,0 +1,20 @@ +terraform { + required_providers { + plural = { + source = "pluralsh/plural" + version = "0.2.1" + } + } +} + +provider "plural" { + use_cli = true +} + +data "plural_user" "user" { + email = "marcin@plural.sh" +} + +data "plural_group" "group" { + name = "team" +} \ No newline at end of file diff --git a/internal/model/group.go b/internal/model/group.go index 23c069a..bbf03fd 100644 --- a/internal/model/group.go +++ b/internal/model/group.go @@ -14,7 +14,7 @@ type Group struct { func (g *Group) From(response *gqlclient.GroupFragment) { g.Id = types.StringValue(response.ID) g.Name = types.StringValue(response.Name) - g.Name = types.StringPointerValue(response.Description) + g.Description = types.StringPointerValue(response.Description) } func (g *Group) Attributes() gqlclient.GroupAttributes { From a951e263d7e0e1778affbdfd00bf10a84c04b7fd Mon Sep 17 00:00:00 2001 From: Marcin Maciaszczyk Date: Thu, 25 Jul 2024 12:50:57 +0200 Subject: [PATCH 15/19] fix config data source --- example/user/main.tf | 4 ++- internal/datasource/config.go | 42 +++++------------------------- internal/model/config.go | 48 +++++++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+), 37 deletions(-) create mode 100644 internal/model/config.go diff --git a/example/user/main.tf b/example/user/main.tf index 4a1aaa1..5d09f80 100644 --- a/example/user/main.tf +++ b/example/user/main.tf @@ -11,10 +11,12 @@ provider "plural" { use_cli = true } +data "plural_config" "config" {} + data "plural_user" "user" { email = "marcin@plural.sh" } data "plural_group" "group" { name = "team" -} \ No newline at end of file +} diff --git a/internal/datasource/config.go b/internal/datasource/config.go index e6eafe3..6eaacf7 100644 --- a/internal/datasource/config.go +++ b/internal/datasource/config.go @@ -3,25 +3,15 @@ package datasource import ( "context" "fmt" - "os" "terraform-provider-plural/internal/client" "terraform-provider-plural/internal/common" - - "github.com/mitchellh/go-homedir" + "terraform-provider-plural/internal/model" "github.com/hashicorp/terraform-plugin-framework/datasource" "github.com/hashicorp/terraform-plugin-framework/datasource/schema" - "github.com/hashicorp/terraform-plugin-framework/types" - - "gopkg.in/yaml.v2" ) -type config struct { - Email types.String `tfsdk:"email" yaml:"email"` - Token types.String `tfsdk:"token" yaml:"email"` -} - func NewConfigDataSource() datasource.DataSource { return &configDataSource{} } @@ -39,11 +29,12 @@ func (d *configDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, MarkdownDescription: "A representation of a config to authenticate to app.plural.sh", Attributes: map[string]schema.Attribute{ "email": schema.StringAttribute{ - Optional: true, - Computed: true, + Description: "The email used to authenticate to plural.", MarkdownDescription: "The email used to authenticate to plural.", + Computed: true, }, "token": schema.StringAttribute{ + Description: "Access token used to authenticate to plural.", MarkdownDescription: "Access token used to authenticate to plural.", Computed: true, }, @@ -69,33 +60,12 @@ func (d *configDataSource) Configure(_ context.Context, req datasource.Configure } func (d *configDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { - var data config + var data model.Config resp.Diagnostics.Append(req.Config.Get(ctx, &data)...) if resp.Diagnostics.HasError() { return } - p, err := homedir.Expand("~/.plural/config.yml") - if err != nil { - resp.Diagnostics.AddWarning("Client Error", fmt.Sprintf("Could not read local plural config: %s", err)) - return - } - - res, err := os.ReadFile(p) - if err != nil { - resp.Diagnostics.AddWarning("Client Error", fmt.Sprintf("Could not read local plural config: %s", err)) - return - } - - var conf struct { - Spec config - } - - if err := yaml.Unmarshal(res, &conf); err != nil { - resp.Diagnostics.AddWarning("Client Error", fmt.Sprintf("Could not parse local plural config: %s", err)) - return - } - - data = conf.Spec + data.From(resp.Diagnostics) resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) } diff --git a/internal/model/config.go b/internal/model/config.go new file mode 100644 index 0000000..3c2a483 --- /dev/null +++ b/internal/model/config.go @@ -0,0 +1,48 @@ +package model + +import ( + "fmt" + "os" + + "github.com/hashicorp/terraform-plugin-framework/diag" + "github.com/hashicorp/terraform-plugin-framework/types" + "github.com/mitchellh/go-homedir" + "gopkg.in/yaml.v2" +) + +type Config struct { + Email types.String `tfsdk:"email" yaml:"email"` + Token types.String `tfsdk:"token" yaml:"token"` +} + +type LocalConfig struct { + Spec LocalConfigSpec `yaml:"spec"` +} + +type LocalConfigSpec struct { + Email string `yaml:"email"` + Token string `yaml:"token"` +} + +func (c *Config) From(d diag.Diagnostics) { + p, err := homedir.Expand("~/.plural/config.yml") + if err != nil { + d.AddError("Client Error", fmt.Sprintf("Could not find local plural config: %s", err)) + return + } + + res, err := os.ReadFile(p) + if err != nil { + d.AddError("Client Error", fmt.Sprintf("Could not read local plural config: %s", err)) + return + } + + var config LocalConfig + if err := yaml.Unmarshal(res, &config); err != nil { + d.AddError("Client Error", fmt.Sprintf("Could not parse local plural config: %s", err)) + return + } + + c.Email = types.StringValue(config.Spec.Email) + c.Token = types.StringValue(config.Spec.Token) +} From aed3d535d6309ff8d19462f108025b3accf0bd87 Mon Sep 17 00:00:00 2001 From: Marcin Maciaszczyk Date: Thu, 25 Jul 2024 12:57:27 +0200 Subject: [PATCH 16/19] fix group resource --- example/user/main.tf | 9 +++++++++ internal/resource/group.go | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/example/user/main.tf b/example/user/main.tf index 5d09f80..5a343eb 100644 --- a/example/user/main.tf +++ b/example/user/main.tf @@ -20,3 +20,12 @@ data "plural_user" "user" { data "plural_group" "group" { name = "team" } + +# resource "plural_group" "test" { +# name = "test" +# description = "test group" +# } +# +# resource "plural_group" "empty" { +# name = "empty" +# } diff --git a/internal/resource/group.go b/internal/resource/group.go index 980d90c..34907d1 100644 --- a/internal/resource/group.go +++ b/internal/resource/group.go @@ -52,7 +52,7 @@ func (r *GroupResource) Schema(_ context.Context, _ resource.SchemaRequest, resp MarkdownDescription: "Name of this group.", }, "description": schema.StringAttribute{ - Required: true, + Optional: true, Description: "Description of this group.", MarkdownDescription: "Description of this group.", }, From 5f28e0bb8c926e803c8ec61c771fe4c00f1f29cd Mon Sep 17 00:00:00 2001 From: Marcin Maciaszczyk Date: Thu, 25 Jul 2024 13:01:43 +0200 Subject: [PATCH 17/19] test group member --- example/user/main.tf | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/example/user/main.tf b/example/user/main.tf index 5a343eb..c9810a0 100644 --- a/example/user/main.tf +++ b/example/user/main.tf @@ -21,11 +21,16 @@ data "plural_group" "group" { name = "team" } -# resource "plural_group" "test" { -# name = "test" -# description = "test group" -# } -# -# resource "plural_group" "empty" { -# name = "empty" -# } +resource "plural_group" "test" { + name = "test" + description = "test group" +} + +resource "plural_group" "empty" { + name = "empty" +} + +resource "plural_group_member" "test" { + user_id = data.plural_user.user.id + group_id = plural_group.test.id +} \ No newline at end of file From bfd5e8493e4d0f4646c16d616bd4bd69181fa690 Mon Sep 17 00:00:00 2001 From: Marcin Maciaszczyk Date: Thu, 25 Jul 2024 13:51:15 +0200 Subject: [PATCH 18/19] fix global service resource --- example/globalservice/main.tf | 18 ++++++++++++++++++ internal/resource/global_service.go | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 example/globalservice/main.tf diff --git a/example/globalservice/main.tf b/example/globalservice/main.tf new file mode 100644 index 0000000..95ce63e --- /dev/null +++ b/example/globalservice/main.tf @@ -0,0 +1,18 @@ +terraform { + required_providers { + plural = { + source = "pluralsh/plural" + version = "0.2.1" + } + } +} + +provider "plural" { + use_cli = true +} + +resource "plural_global_service" "guestbook" { + name = "guestbook" + service_id = "624bff88-05e3-45f6-bc3b-44708594e28e" + distro = "AKS" +} diff --git a/internal/resource/global_service.go b/internal/resource/global_service.go index 7f1c9e9..b96b897 100644 --- a/internal/resource/global_service.go +++ b/internal/resource/global_service.go @@ -108,7 +108,7 @@ func (r *GlobalServiceResource) Create(ctx context.Context, req resource.CreateR return } - response, err := r.client.CreateGlobalService(ctx, data.Attributes(ctx, resp.Diagnostics)) + response, err := r.client.CreateGlobalServiceDeployment(ctx, data.ServiceId.ValueString(), data.Attributes(ctx, resp.Diagnostics)) if err != nil { resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to create GlobalService, got error: %s", err)) return From d20e1afd1f26e4136306c85a688e6dbecb4fcd41 Mon Sep 17 00:00:00 2001 From: Marcin Maciaszczyk Date: Thu, 25 Jul 2024 14:03:30 +0200 Subject: [PATCH 19/19] fix rbac resource --- example/user/main.tf | 17 +++++++++------- internal/model/rbac.go | 2 +- internal/resource/rbac.go | 42 +++++++++++++++------------------------ 3 files changed, 27 insertions(+), 34 deletions(-) diff --git a/example/user/main.tf b/example/user/main.tf index c9810a0..d7fae45 100644 --- a/example/user/main.tf +++ b/example/user/main.tf @@ -26,11 +26,14 @@ resource "plural_group" "test" { description = "test group" } -resource "plural_group" "empty" { - name = "empty" -} - -resource "plural_group_member" "test" { - user_id = data.plural_user.user.id - group_id = plural_group.test.id +resource "plural_rbac" "rbac" { + service_id = "624bff88-05e3-45f6-bc3b-44708594e28e" + bindings = { + read = [{ + user_id = data.plural_user.user.id + }] + write = [{ + user_id = data.plural_user.user.id + }] + } } \ No newline at end of file diff --git a/internal/model/rbac.go b/internal/model/rbac.go index 66f3690..c9d17fc 100644 --- a/internal/model/rbac.go +++ b/internal/model/rbac.go @@ -13,7 +13,7 @@ import ( type RBAC struct { ClusterId types.String `tfsdk:"cluster_id"` ServiceId types.String `tfsdk:"service_id"` - Bindings *common.Bindings `tfsdk:"rbac"` + Bindings *common.Bindings `tfsdk:"bindings"` } func (rbac *RBAC) Attributes(ctx context.Context, d diag.Diagnostics) gqlclient.RbacAttributes { diff --git a/internal/resource/rbac.go b/internal/resource/rbac.go index b76c4a3..9d08445 100644 --- a/internal/resource/rbac.go +++ b/internal/resource/rbac.go @@ -8,6 +8,8 @@ import ( "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/objectplanmodifier" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" "terraform-provider-plural/internal/client" "terraform-provider-plural/internal/common" @@ -56,19 +58,13 @@ func (r *rbacResource) Schema(_ context.Context, _ resource.SchemaRequest, resp NestedObject: schema.NestedAttributeObject{ Attributes: map[string]schema.Attribute{ "group_id": schema.StringAttribute{ - Description: "", - MarkdownDescription: "", - Optional: true, + Optional: true, }, "id": schema.StringAttribute{ - Description: "", - MarkdownDescription: "", - Optional: true, + Optional: true, }, "user_id": schema.StringAttribute{ - Description: "", - MarkdownDescription: "", - Optional: true, + Optional: true, }, }, }, @@ -80,24 +76,19 @@ func (r *rbacResource) Schema(_ context.Context, _ resource.SchemaRequest, resp NestedObject: schema.NestedAttributeObject{ Attributes: map[string]schema.Attribute{ "group_id": schema.StringAttribute{ - Description: "", - MarkdownDescription: "", - Optional: true, + Optional: true, }, "id": schema.StringAttribute{ - Description: "", - MarkdownDescription: "", - Optional: true, + Optional: true, }, "user_id": schema.StringAttribute{ - Description: "", - MarkdownDescription: "", - Optional: true, + Optional: true, }, }, }, }, }, + PlanModifiers: []planmodifier.Object{objectplanmodifier.UseStateForUnknown()}, }, }, } @@ -122,7 +113,7 @@ func (r *rbacResource) Configure(_ context.Context, req resource.ConfigureReques } func (r *rbacResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { - var data model.RBAC + data := new(model.RBAC) resp.Diagnostics.Append(req.Plan.Get(ctx, data)...) if resp.Diagnostics.HasError() { return @@ -130,19 +121,19 @@ func (r *rbacResource) Create(ctx context.Context, req resource.CreateRequest, r _, err := r.client.UpdateRbac(ctx, data.Attributes(ctx, resp.Diagnostics), data.ServiceId.ValueStringPointer(), data.ClusterId.ValueStringPointer(), nil) if err != nil { - resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to update rbac, got error: %s", err)) + resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to update RBAC, got error: %s", err)) return } resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) } -func (r *rbacResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { +func (r *rbacResource) Read(_ context.Context, _ resource.ReadRequest, _ *resource.ReadResponse) { // ignore } func (r *rbacResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { - var data model.RBAC + data := new(model.RBAC) resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...) if resp.Diagnostics.HasError() { return @@ -150,17 +141,16 @@ func (r *rbacResource) Update(ctx context.Context, req resource.UpdateRequest, r _, err := r.client.UpdateRbac(ctx, data.Attributes(ctx, resp.Diagnostics), data.ServiceId.ValueStringPointer(), data.ClusterId.ValueStringPointer(), nil) if err != nil { - resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to update rbac, got error: %s", err)) + resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to update RBAC, got error: %s", err)) return } resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) } -func (r *rbacResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { +func (r *rbacResource) Delete(_ context.Context, _ resource.DeleteRequest, _ *resource.DeleteResponse) { // ignore } -func (r *rbacResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { - // ignore +func (r *rbacResource) ImportState(_ context.Context, _ resource.ImportStateRequest, _ *resource.ImportStateResponse) { }