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 13, 2024
1 parent 20eef93 commit 701e303
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 36 deletions.
20 changes: 19 additions & 1 deletion docs/resources/dw_vw_impala.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,25 @@ description: |-




## Example Usage

```terraform
// Copyright 2024 Cloudera. All Rights Reserved.
//
// This file is licensed under the Apache License Version 2.0 (the "License").
// You may not use this file except in compliance with the License.
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.
//
// This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
// OF ANY KIND, either express or implied. Refer to the License for the specific
// permissions and limitations governing your use of the file.
resource "cdp_dw_vw_impala" "impala-terraform" {
cluster_id = var.cluster_id
database_catalog_id = var.database_catalog_id
name = var.name
}
```

<!-- schema generated by tfplugindocs -->
## Schema
Expand Down
26 changes: 0 additions & 26 deletions docs/resources/dw_vw_impala.md.tpl

This file was deleted.

15 changes: 15 additions & 0 deletions examples/resources/cdp_dw_vw_impala/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright 2024 Cloudera. All Rights Reserved.
//
// This file is licensed under the Apache License Version 2.0 (the "License").
// You may not use this file except in compliance with the License.
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.
//
// This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
// OF ANY KIND, either express or implied. Refer to the License for the specific
// permissions and limitations governing your use of the file.

resource "cdp_dw_vw_impala" "impala-terraform" {
cluster_id = var.cluster_id
database_catalog_id = var.database_catalog_id
name = var.name
}
19 changes: 10 additions & 9 deletions resources/dw/virtualwarehouse/impala/resource_impala_vw.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (r *impalaResource) Create(ctx context.Context, req resource.CreateRequest,
tflog.Debug(ctx, fmt.Sprintf("CreateVw response: %+v", response.GetPayload()))

// Wait for the VW to reach Running state
if err := r.waitForVwRunning(ctx, &plan, response.GetPayload()); err != nil {
if err := r.waitForVwRunning(ctx, &plan, &response.GetPayload().VwID); err != nil {
resp.Diagnostics.AddError(
"Error waiting for Data Warehouse Impala virtual warehouse",
fmt.Sprintf("Could not create Impala, unexpected error: %v", err),
Expand Down Expand Up @@ -194,13 +194,10 @@ func createVwRequestFromPlan(plan *resourceModel) *models.CreateVwRequest {
return req
}

func (r *impalaResource) waitForVwRunning(ctx context.Context, plan *resourceModel, payload *models.CreateVwResponse) error {
func (r *impalaResource) waitForVwRunning(ctx context.Context, plan *resourceModel, vwID *string) error {
clusterID := plan.ClusterID.ValueStringPointer()
vwID := &payload.VwID

opts := plan.PollingOptions

if opts == nil || !opts.Async.ValueBool() {
if opts := plan.PollingOptions; opts == nil || !opts.Async.ValueBool() {
callFailedCount := 0
stateConf := &retry.StateChangeConf{
Pending: []string{"Accepted", "Creating", "Created", "Starting"},
Expand All @@ -225,14 +222,18 @@ func (r *impalaResource) populatePlanFromDescribe(ctx context.Context, plan *res
}

impala := describe.GetPayload()
plan.ID = types.StringValue(impala.Vw.ID)
plan.populateFromImpala(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))

return nil
}

func (r *impalaResource) deleteVirtualWarehouse(ctx context.Context, clusterID, vwID *string) error {
Expand Down

0 comments on commit 701e303

Please sign in to comment.