44 "context"
55 "fmt"
66
7+ "github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault"
8+
79 "terraform-provider-plural/internal/client"
810 "terraform-provider-plural/internal/model"
911
@@ -28,7 +30,8 @@ func NewClusterResource() resource.Resource {
2830
2931// ClusterResource defines the cluster resource implementation.
3032type clusterResource struct {
31- client * client.Client
33+ client * client.Client
34+ consoleUrl string
3235}
3336
3437func (r * clusterResource ) Metadata (_ context.Context , req resource.MetadataRequest , resp * resource.MetadataResponse ) {
@@ -67,6 +70,8 @@ func (r *clusterResource) Schema(_ context.Context, _ resource.SchemaRequest, re
6770 "protect" : schema.BoolAttribute {
6871 MarkdownDescription : "If set to `true` then this cluster cannot be deleted." ,
6972 Optional : true ,
73+ Computed : true ,
74+ Default : booldefault .StaticBool (false ),
7075 },
7176 "tags" : schema.MapAttribute {
7277 MarkdownDescription : "Key-value tags used to filter clusters." ,
@@ -83,7 +88,7 @@ func (r *clusterResource) Configure(_ context.Context, req resource.ConfigureReq
8388 return
8489 }
8590
86- c , ok := req .ProviderData .(* client. Client )
91+ data , ok := req .ProviderData .(* model. ProviderData )
8792 if ! ok {
8893 resp .Diagnostics .AddError (
8994 "Unexpected Cluster Resource Configure Type" ,
@@ -92,7 +97,8 @@ func (r *clusterResource) Configure(_ context.Context, req resource.ConfigureReq
9297 return
9398 }
9499
95- r .client = c
100+ r .client = data .Client
101+ r .consoleUrl = data .ConsoleUrl
96102}
97103
98104func (r * clusterResource ) Create (ctx context.Context , req resource.CreateRequest , resp * resource.CreateResponse ) {
@@ -127,10 +133,11 @@ func (r *clusterResource) Create(ctx context.Context, req resource.CreateRequest
127133 return
128134 }
129135
130- // TODO:
131- // deployToken := *cluster.CreateCluster.DeployToken
132- // url := fmt.Sprintf("%s/ext/gql", p.ConsoleClient.Url())
133- // p.doInstallOperator(url, deployToken)
136+ err = doInstallOperator (ctx , data .Kubeconfig , r .consoleUrl , * cluster .CreateCluster .DeployToken )
137+ if err != nil {
138+ resp .Diagnostics .AddError ("Client Error" , fmt .Sprintf ("Unable to install operator, got error: %s" , err ))
139+ return
140+ }
134141
135142 tflog .Trace (ctx , "installed the cluster operator" )
136143 }
0 commit comments