From 471121178be51388e97e54879ea2de2d81ad89e7 Mon Sep 17 00:00:00 2001 From: Marcin Maciaszczyk Date: Wed, 15 Nov 2023 15:04:05 +0100 Subject: [PATCH] support more cluster properties --- go.mod | 2 +- go.sum | 4 ++-- internal/datasource/cluster.go | 1 + internal/resource/cluster.go | 28 ++++++++++++++++------------ 4 files changed, 20 insertions(+), 15 deletions(-) diff --git a/go.mod b/go.mod index 0655e85..3d23962 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( 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/pluralsh/console-client-go v0.0.34 + github.com/pluralsh/console-client-go v0.0.36 github.com/pluralsh/plural-cli v0.8.1-0.20231114145714-860fa85f7e63 ) diff --git a/go.sum b/go.sum index 77cdc78..ef2d5a6 100644 --- a/go.sum +++ b/go.sum @@ -851,8 +851,8 @@ 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.0.34 h1:YEvLvwE9s7xGClNiIPPVpISZ9/8RUpwvTWeF0w0u2q0= -github.com/pluralsh/console-client-go v0.0.34/go.mod h1:kZjk0pXAWnvyj+miXveCho4kKQaX1Tm3CGAM+iwurWU= +github.com/pluralsh/console-client-go v0.0.36 h1:yjABMAgkRu0nI5QtmM/rO+rvXvLUAoV/fIiaHmuGhgo= +github.com/pluralsh/console-client-go v0.0.36/go.mod h1:kZjk0pXAWnvyj+miXveCho4kKQaX1Tm3CGAM+iwurWU= 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.1-0.20231114145714-860fa85f7e63 h1:1IWFJ6th8IMzSTND6RkmK/iYiOodtU3hXVs9X6nFWOQ= diff --git a/internal/datasource/cluster.go b/internal/datasource/cluster.go index 57e08b5..7919d76 100644 --- a/internal/datasource/cluster.go +++ b/internal/datasource/cluster.go @@ -28,5 +28,6 @@ func (d *clusterDataSource) Schema(_ context.Context, _ datasource.SchemaRequest resp.Schema = schema.Schema{} } +// TODO: Support read by handle and ID. func (d *clusterDataSource) Read(_ context.Context, _ datasource.ReadRequest, _ *datasource.ReadResponse) { } diff --git a/internal/resource/cluster.go b/internal/resource/cluster.go index 5f3b345..d829948 100644 --- a/internal/resource/cluster.go +++ b/internal/resource/cluster.go @@ -13,7 +13,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/schema/validator" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-plugin-log/tflog" - consoleClient "github.com/pluralsh/console-client-go" + console "github.com/pluralsh/console-client-go" ) var _ resource.Resource = &ClusterResource{} @@ -25,7 +25,7 @@ func NewClusterResource() resource.Resource { // ClusterResource defines the cluster resource implementation. type ClusterResource struct { - client *consoleClient.Client + client *console.Client } // ClusterResourceModel describes the cluster resource data model. @@ -90,14 +90,12 @@ func (r *ClusterResource) Configure(_ context.Context, req resource.ConfigureReq return } - client, ok := req.ProviderData.(*consoleClient.Client) - + client, ok := req.ProviderData.(*console.Client) if !ok { resp.Diagnostics.AddError( "Unexpected Cluster Resource Configure Type", fmt.Sprintf("Expected *console.Client, got: %T. Please report this issue to the provider developers.", req.ProviderData), ) - return } @@ -111,7 +109,7 @@ func (r *ClusterResource) Create(ctx context.Context, req resource.CreateRequest return } - attrs := consoleClient.ClusterAttributes{ + attrs := console.ClusterAttributes{ Name: data.Name.ValueString(), Handle: data.Handle.ValueStringPointer(), Protect: data.Protect.ValueBoolPointer(), @@ -124,7 +122,11 @@ func (r *ClusterResource) Create(ctx context.Context, req resource.CreateRequest tflog.Trace(ctx, "created a cluster") + data.Name = types.StringValue(cluster.CreateCluster.Name) + data.Handle = types.StringPointerValue(cluster.CreateCluster.Handle) data.Id = types.StringValue(cluster.CreateCluster.ID) + data.Protect = types.BoolPointerValue(cluster.CreateCluster.Protect) + data.InseredAt = types.StringPointerValue(cluster.CreateCluster.InsertedAt) if data.Cloud.ValueString() == "byok" { if cluster.CreateCluster.DeployToken == nil { @@ -157,10 +159,10 @@ func (r *ClusterResource) Read(ctx context.Context, req resource.ReadRequest, re } data.Id = types.StringValue(cluster.Cluster.ID) - data.InseredAt = types.StringNull() // TODO: Update client to return this field. + data.InseredAt = types.StringPointerValue(cluster.Cluster.InsertedAt) data.Name = types.StringValue(cluster.Cluster.Name) - data.Handle = types.StringValue(*cluster.Cluster.Handle) - data.Protect = types.BoolNull() // TODO: Update client to return this field. + data.Handle = types.StringPointerValue(cluster.Cluster.Handle) + data.Protect = types.BoolPointerValue(cluster.Cluster.Protect) resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) } @@ -172,8 +174,9 @@ func (r *ClusterResource) Update(ctx context.Context, req resource.UpdateRequest return } - attrs := consoleClient.ClusterUpdateAttributes{ - Handle: data.Handle.ValueStringPointer(), + attrs := console.ClusterUpdateAttributes{ + Handle: data.Handle.ValueStringPointer(), + Protect: data.Protect.ValueBoolPointer(), } cluster, err := r.client.UpdateCluster(ctx, data.Id.ValueString(), attrs) if err != nil { @@ -181,7 +184,8 @@ func (r *ClusterResource) Update(ctx context.Context, req resource.UpdateRequest return } - data.Handle = types.StringValue(*cluster.UpdateCluster.Handle) + data.Handle = types.StringPointerValue(cluster.UpdateCluster.Handle) + data.Protect = types.BoolPointerValue(cluster.UpdateCluster.Protect) resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) }