Skip to content

Commit

Permalink
support more cluster properties
Browse files Browse the repository at this point in the history
  • Loading branch information
maciaszczykm committed Nov 15, 2023
1 parent 6e2ef25 commit 4711211
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 15 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
1 change: 1 addition & 0 deletions internal/datasource/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
}
28 changes: 16 additions & 12 deletions internal/resource/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand All @@ -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.
Expand Down Expand Up @@ -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
}

Expand All @@ -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(),
Expand All @@ -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 {
Expand Down Expand Up @@ -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)...)
}
Expand All @@ -172,16 +174,18 @@ 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 {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to update cluster, got error: %s", err))
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)...)
}
Expand Down

0 comments on commit 4711211

Please sign in to comment.