Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
prateekcldr committed Dec 17, 2024
1 parent 39bb17c commit 15119de
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
14 changes: 14 additions & 0 deletions resources/dw/virtualwarehouse/impala/model_impala_vw.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,16 @@
package impala

import (
"time"

"github.com/hashicorp/terraform-plugin-framework/types"

"github.com/cloudera/terraform-provider-cdp/cdp-sdk-go/gen/dw/models"
"github.com/cloudera/terraform-provider-cdp/utils"
)

const timeZone = time.RFC850

type resourceModel struct {
ID types.String `tfsdk:"id"`
ClusterID types.String `tfsdk:"cluster_id"`
Expand All @@ -27,6 +32,15 @@ type resourceModel struct {
PollingOptions *utils.PollingOptions `tfsdk:"polling_options"`
}

func (p *resourceModel) setFromDescribeVwResponse(resp *models.DescribeVwResponse) {
p.ID = types.StringValue(resp.Vw.DbcID)
p.DatabaseCatalogID = types.StringValue(resp.Vw.DbcID)
p.Name = types.StringValue(resp.Vw.Name)
p.Status = types.StringValue(resp.Vw.Status)
p.ImageVersion = types.StringValue(resp.Vw.CdhVersion)
p.LastUpdated = types.StringValue(time.Now().Format(timeZone))
}

func (p *resourceModel) GetPollingOptions() *utils.PollingOptions {
return p.PollingOptions
}
20 changes: 4 additions & 16 deletions resources/dw/virtualwarehouse/impala/resource_impala_vw.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"time"

"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-log/tflog"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"

Expand Down Expand Up @@ -62,7 +61,7 @@ func (r *impalaResource) Create(ctx context.Context, req resource.CreateRequest,
}

// Create the VW Request using a helper
vwhCreateRequest := createVwRequestFromPlan(&plan)
vwhCreateRequest := r.createVwRequestFromPlan(&plan)
tflog.Debug(ctx, fmt.Sprintf("CreateVw request: %+v", vwhCreateRequest))

// Make API request to create VW
Expand Down Expand Up @@ -141,9 +140,7 @@ func (r *impalaResource) Delete(ctx context.Context, req resource.DeleteRequest,
}

// Handle polling for not async call
pollingOptionsAvailable := state.PollingOptions != nil
isSynchronous := pollingOptionsAvailable && !state.PollingOptions.Async.ValueBool()
if isSynchronous {
if opts := state.PollingOptions; opts == nil || !opts.Async.ValueBool() {
err = r.pollForDeletion(ctx, state, clusterID, vwID)
if err != nil {
resp.Diagnostics.AddError(
Expand Down Expand Up @@ -181,7 +178,7 @@ func (r *impalaResource) stateRefresh(ctx context.Context, clusterID *string, vw
}
}

func createVwRequestFromPlan(plan *resourceModel) *models.CreateVwRequest {
func (r *impalaResource) createVwRequestFromPlan(plan *resourceModel) *models.CreateVwRequest {
req := &models.CreateVwRequest{
Name: plan.Name.ValueStringPointer(),
ClusterID: plan.ClusterID.ValueStringPointer(),
Expand Down Expand Up @@ -222,20 +219,11 @@ func (r *impalaResource) populatePlanFromDescribe(ctx context.Context, plan *res
}

impala := describe.GetPayload()
plan.populateFromImpala(impala)
plan.setFromDescribeVwResponse(impala)

return nil
}

func (plan *resourceModel) populateFromImpala(impala *models.DescribeVwResponse) {
plan.ID = types.StringValue(impala.Vw.DbcID)
plan.DatabaseCatalogID = types.StringValue(impala.Vw.DbcID)
plan.Name = types.StringValue(impala.Vw.Name)
plan.Status = types.StringValue(impala.Vw.Status)
plan.ImageVersion = types.StringValue(impala.Vw.CdhVersion)
plan.LastUpdated = types.StringValue(time.Now().Format(time.RFC850))
}

func (r *impalaResource) deleteVirtualWarehouse(ctx context.Context, clusterID, vwID *string) error {
op := operations.NewDeleteVwParamsWithContext(ctx).
WithInput(&models.DeleteVwRequest{
Expand Down

0 comments on commit 15119de

Please sign in to comment.