Skip to content

Commit 2859ccd

Browse files
committed
feat: Add logging function to ClusterResource
1 parent 95e6146 commit 2859ccd

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

terraform-provider-constellation/internal/provider/cluster_resource.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,21 +589,36 @@ func (r *ClusterResource) ModifyPlan(ctx context.Context, req resource.ModifyPla
589589
// Create is called when the resource is created.
590590
func (r *ClusterResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {
591591
// Read data supplied by Terraform runtime into the model
592+
r.logWithContext(ctx, "INFO", "Starting cluster creation")
593+
592594
var data ClusterResourceModel
593595
resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...)
594596
if resp.Diagnostics.HasError() {
597+
r.logWithContext(ctx, "ERROR", "Failed to read plan data", map[string]interface{}{"error": resp.Diagnostics.Errors()})
595598
return
596599
}
597600

598601
// Apply changes to the cluster, including the init RPC and skipping the node upgrade.
602+
r.logWithContext(ctx, "DEBUG", "Applying cluster changes", map[string]interface{}{
603+
"csp": data.CSP.ValueString(),
604+
"name": data.Name.ValueString(),
605+
})
599606
diags := r.apply(ctx, &data, false, true)
600607
resp.Diagnostics.Append(diags...)
601608
if resp.Diagnostics.HasError() {
609+
r.logWithContext(ctx, "ERROR", "Failed to apply cluster changes", map[string]interface{}{"error": resp.Diagnostics.Errors()})
602610
return
603611
}
604612

605613
// Save data into Terraform state
614+
r.logWithContext(ctx, "DEBUG", "Saving cluster data to state")
606615
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
616+
if resp.Diagnostics.HasError() {
617+
r.logWithContext(ctx, "ERROR", "Failed to save cluster data to state", map[string]interface{}{"error": resp.Diagnostics.Errors()})
618+
return
619+
}
620+
621+
r.logWithContext(ctx, "INFO", "Cluster creation completed successfully")
607622
}
608623

609624
// Read is called when the resource is read or refreshed.

0 commit comments

Comments
 (0)