Skip to content

Commit

Permalink
DWX-18763: VW Impala create and delete using basic properties (#193)
Browse files Browse the repository at this point in the history
* DWX-18763: VW Impala create and delete using basic properties  and image version
  • Loading branch information
prateek1192 authored Dec 18, 2024
1 parent 2040668 commit be3b4b4
Show file tree
Hide file tree
Showing 11 changed files with 1,039 additions and 1 deletion.
59 changes: 59 additions & 0 deletions docs/resources/dw_vw_impala.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
---
page_title: "cdp_dw_vw_impala Resource - terraform-provider-cdp"
subcategory: "Data Warehouse"
description: |-
A Impala Virtual Warehouse is service which is able to run low-latency SQL queries.
---

# cdp_dw_vw_impala (Resource)

A Impala Virtual Warehouse is service which is able to run low-latency SQL queries.

## 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

### Required

- `cluster_id` (String) The id of the CDW Cluster which the Impala Virtual Warehouse is attached to.
- `database_catalog_id` (String) The id of the Database Catalog which the Impala Virtual Warehouse is attached to.
- `name` (String) The name of the Impala Virtual Warehouse.

### Optional

- `image_version` (String) Image version of the impala.
- `polling_options` (Attributes) Polling related configuration options that could specify various values that will be used during CDP resource creation. (see [below for nested schema](#nestedatt--polling_options))

### Read-Only

- `id` (String) The ID of this resource.
- `last_updated` (String) Timestamp of the last Terraform update of the order.
- `status` (String) The status of the database catalog.

<a id="nestedatt--polling_options"></a>
### Nested Schema for `polling_options`

Optional:

- `async` (Boolean) Boolean value that specifies if Terraform should wait for resource creation/deletion.
- `call_failure_threshold` (Number) Threshold value that specifies how many times should a single call failure happen before giving up the polling.
- `polling_timeout` (Number) Timeout value in minutes that specifies for how long should the polling go for resource creation/deletion.
16 changes: 16 additions & 0 deletions examples/resources/cdp_dw_vw_impala/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// 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
image_version = var.image_version
}
2 changes: 2 additions & 0 deletions provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
dwaws "github.com/cloudera/terraform-provider-cdp/resources/dw/cluster/aws"
dwdatabasecatalog "github.com/cloudera/terraform-provider-cdp/resources/dw/databasecatalog"
"github.com/cloudera/terraform-provider-cdp/resources/dw/virtualwarehouse/hive"
"github.com/cloudera/terraform-provider-cdp/resources/dw/virtualwarehouse/impala"
"github.com/cloudera/terraform-provider-cdp/resources/environments"
"github.com/cloudera/terraform-provider-cdp/resources/iam"
"github.com/cloudera/terraform-provider-cdp/resources/ml"
Expand Down Expand Up @@ -250,6 +251,7 @@ func (p *CdpProvider) Resources(_ context.Context) []func() resource.Resource {
ml.NewWorkspaceResource,
de.NewServiceResource,
hive.NewHiveResource,
impala.NewImpalaResource,
dwaws.NewDwClusterResource,
dwdatabasecatalog.NewDwDatabaseCatalogResource,
}
Expand Down
2 changes: 2 additions & 0 deletions provider/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
dwaws "github.com/cloudera/terraform-provider-cdp/resources/dw/cluster/aws"
dwdatabasecatalog "github.com/cloudera/terraform-provider-cdp/resources/dw/databasecatalog"
"github.com/cloudera/terraform-provider-cdp/resources/dw/virtualwarehouse/hive"
"github.com/cloudera/terraform-provider-cdp/resources/dw/virtualwarehouse/impala"
"github.com/cloudera/terraform-provider-cdp/resources/environments"
"github.com/cloudera/terraform-provider-cdp/resources/iam"
"github.com/cloudera/terraform-provider-cdp/resources/ml"
Expand Down Expand Up @@ -636,6 +637,7 @@ func TestCdpProvider_Resources(t *testing.T) {
ml.NewWorkspaceResource,
de.NewServiceResource,
hive.NewHiveResource,
impala.NewImpalaResource,
dwaws.NewDwClusterResource,
dwdatabasecatalog.NewDwDatabaseCatalogResource,
}
Expand Down
13 changes: 12 additions & 1 deletion resources/dw/resource_dw_acc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@ func TestAccDwCluster_Basic(t *testing.T) {
testAccAwsDataLakeConfig(&dlParams),
testAccAwsClusterBasicConfig(&envParams),
testAccDwCatalog(),
testAccHiveVirtualWarehouse(cdpacctest.RandomShortWithPrefix("tf-hive"))),
testAccHiveVirtualWarehouse(cdpacctest.RandomShortWithPrefix("tf-hive")),
testAccImpalaVirtualWarehouse(cdpacctest.RandomShortWithPrefix("tf-impala"))),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("cdp_dw_aws_cluster.test_data_warehouse_aws", "name", envParams.Name),
resource.TestCheckResourceAttr("cdp_dw_aws_cluster.test_data_warehouse_aws", "status", "Accepted"),
Expand Down Expand Up @@ -330,3 +331,13 @@ func testCheckClusterDestroy(s *terraform.State) error {
}
return nil
}

func testAccImpalaVirtualWarehouse(name string) string {
return fmt.Sprintf(`
resource "cdp_dw_vw_impala" "test_impala" {
cluster_id = cdp_dw_aws_cluster.test_data_warehouse_aws.cluster_id
database_catalog_id = cdp_dw_database_catalog.test_catalog.id
name = %[1]q
}
`, name)
}
46 changes: 46 additions & 0 deletions resources/dw/virtualwarehouse/impala/model_impala_vw.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// 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.

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"`
DatabaseCatalogID types.String `tfsdk:"database_catalog_id"`
Name types.String `tfsdk:"name"`
LastUpdated types.String `tfsdk:"last_updated"`
Status types.String `tfsdk:"status"`
ImageVersion types.String `tfsdk:"image_version"`
PollingOptions *utils.PollingOptions `tfsdk:"polling_options"`
}

func (p *resourceModel) setFromDescribeVwResponse(resp *models.DescribeVwResponse) {
p.ID = types.StringValue(resp.Vw.ID)
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
}
Loading

0 comments on commit be3b4b4

Please sign in to comment.