Skip to content

Commit

Permalink
Addressing review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
tevesz committed Dec 18, 2024
1 parent bacb1f3 commit 7e3eae4
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 57 deletions.
40 changes: 24 additions & 16 deletions docs/resources/dw_vw_hive.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,30 @@ A Hive Virtual Warehouse is service which is able to run big SQL queries.
# OF ANY KIND, either express or implied. Refer to the License for the specific
# permissions and limitations governing your use of the file.
terraform {
required_providers {
cdp = {
source = "cloudera/cdp"
}
}
}
resource "cdp_dw_vw_hive" "example" {
cluster_id = "env-id"
database_catalog_id = "warehouse-id"
name = "default-catalog"
group_size = 2
platform_jwt_auth = true
enable_sso = true
image_version = "2024.0.18.4-5"
min_group_count = 1
max_group_count = 3
disable_auto_suspend = false
auto_suspend_timeout_seconds = 100
cluster_id = "env-id"
database_catalog_id = "warehouse-id"
name = "default-catalog"
group_size = 2
platform_jwt_auth = true
enable_sso = true
image_version = "2024.0.18.4-5"
min_group_count = 1
max_group_count = 3
disable_auto_suspend = false
auto_suspend_timeout_seconds = 100
scale_wait_time_seconds = 230 // either headroom or scale_wait_time_seconds can be configured
headroom = 1
headroom = 1
max_concurrent_isolated_queries = 5
max_nodes_per_isolated_query = 2
max_nodes_per_isolated_query = 2
aws_options = {
availability_zone = "us-west-2a"
ebs_llap_spill_gb = 300
Expand All @@ -64,7 +72,7 @@ output "jwt_connection_string" {
}
output "jwt_token_gen_url" {
value = cdp_dw_vw_hive.example.jwt_token_gen_url
value = cdp_dw_vw_hive.example.jwt_token_gen_url
}
```

Expand All @@ -88,7 +96,7 @@ output "jwt_token_gen_url" {
- `enable_sso` (Boolean) Enable SSO for the Virtual Warehouse. If this field is not specified, it defaults to ‘false’.
- `headroom` (Number) Set headroom node count. Nodes will be started in case there are no free nodes left to pick up new jobs.
- `image_version` (String) The version of the Hive Virtual Warehouse image.
- `ldap_groups` (List of String) LDAP group names to be enabled for auth.
- `ldap_groups` (List of String) LDAP group names to be enabled to authenticate with.
- `max_concurrent_isolated_queries` (Number) Maximum number of concurrent isolated queries. If not provided, 0 will be applied. The 0 value means the query isolation functionality will be disabled.
- `max_nodes_per_isolated_query` (Number) Maximum number of nodes per isolated query. If not provided, 0 will be applied. The 0 value means the query isolation functionality will be disabled.
- `platform_jwt_auth` (Boolean) Value of ‘true’ automatically configures the Virtual Warehouse to support JWTs issued by the CDP JWT token provider. Value of ‘false’ does not enable JWT auth on the Virtual Warehouse. If this field is not specified, it defaults to ‘false’.
Expand All @@ -105,7 +113,7 @@ output "jwt_token_gen_url" {
- `jwt_token_gen_url` (String) URL to generate JWT tokens for the Virtual Warehouse by the CDP JWT token provider. Available if platform JWT authentication is enabled.
- `kerberos_jdbc_url` (String) Kerberos JDBC URL for the Hive Virtual Warehouse.
- `last_updated` (String) Timestamp of the last Terraform update of the order.
- `status` (String) The status of the database catalog.
- `status` (String) The status of the Hive Virtual Warehouse.

<a id="nestedatt--aws_options"></a>
### Nested Schema for `aws_options`
Expand Down
36 changes: 22 additions & 14 deletions examples/resources/cdp_dw_vw_hive/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,30 @@
# OF ANY KIND, either express or implied. Refer to the License for the specific
# permissions and limitations governing your use of the file.

terraform {
required_providers {
cdp = {
source = "cloudera/cdp"
}
}
}

resource "cdp_dw_vw_hive" "example" {
cluster_id = "env-id"
database_catalog_id = "warehouse-id"
name = "default-catalog"
group_size = 2
platform_jwt_auth = true
enable_sso = true
image_version = "2024.0.18.4-5"
min_group_count = 1
max_group_count = 3
disable_auto_suspend = false
auto_suspend_timeout_seconds = 100
cluster_id = "env-id"
database_catalog_id = "warehouse-id"
name = "default-catalog"
group_size = 2
platform_jwt_auth = true
enable_sso = true
image_version = "2024.0.18.4-5"
min_group_count = 1
max_group_count = 3
disable_auto_suspend = false
auto_suspend_timeout_seconds = 100
scale_wait_time_seconds = 230 // either headroom or scale_wait_time_seconds can be configured
headroom = 1
headroom = 1
max_concurrent_isolated_queries = 5
max_nodes_per_isolated_query = 2
max_nodes_per_isolated_query = 2
aws_options = {
availability_zone = "us-west-2a"
ebs_llap_spill_gb = 300
Expand All @@ -50,5 +58,5 @@ output "jwt_connection_string" {
}

output "jwt_token_gen_url" {
value = cdp_dw_vw_hive.example.jwt_token_gen_url
value = cdp_dw_vw_hive.example.jwt_token_gen_url
}
39 changes: 19 additions & 20 deletions resources/dw/virtualwarehouse/hive/model_hive_vw.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
package hive

import (
"strings"
"context"
"time"

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

"github.com/cloudera/terraform-provider-cdp/cdp-sdk-go/gen/dw/models"
Expand Down Expand Up @@ -60,30 +61,24 @@ func (p *resourceModel) GetPollingOptions() *utils.PollingOptions {
return p.PollingOptions
}

func (p *resourceModel) convertToCreateVwRequest() *models.CreateVwRequest {
func (p *resourceModel) convertToCreateVwRequest(ctx context.Context) (*models.CreateVwRequest, diag.Diagnostics) {
vwType := models.VwType("hive")
tags, diags := p.getTags(ctx)
return &models.CreateVwRequest{
ClusterID: p.ClusterID.ValueStringPointer(),
DbcID: p.DatabaseCatalogID.ValueStringPointer(),
EbsLLAPSpillGB: p.getEbsLLAPSpillGB(),
ImageVersion: p.getImageVersion(),
ImageVersion: p.ImageVersion.ValueString(),
Name: p.Name.ValueStringPointer(),
NodeCount: utils.Int64To32(p.GroupSize),
PlatformJwtAuth: p.PlatformJwtAuth.ValueBoolPointer(),
QueryIsolationOptions: p.getQueryIsolationOptions(),
Autoscaling: p.getAutoscaling(),
AvailabilityZone: p.getAvailabilityZone(),
Tags: p.getTags(),
Tags: tags,
Config: p.getServiceConfig(),
VwType: &vwType,
}
}

func (p *resourceModel) getImageVersion() string {
if p.ImageVersion.IsNull() || p.ImageVersion.IsUnknown() || p.ImageVersion.String() == "<unknown>" {
return ""
}
return strings.TrimPrefix(strings.TrimSuffix(p.ImageVersion.String(), "\""), "\"")
}, diags
}

func (p *resourceModel) getServiceConfig() *models.ServiceConfigReq {
Expand All @@ -95,22 +90,23 @@ func (p *resourceModel) getServiceConfig() *models.ServiceConfigReq {
}
}

func (p *resourceModel) getTags() []*models.TagRequest {
func (p *resourceModel) getTags(ctx context.Context) ([]*models.TagRequest, diag.Diagnostics) {
if p.AwsOptions.Tags.IsNull() {
return nil
return nil, diag.Diagnostics{}
}
var tags []*models.TagRequest
for k, v := range p.AwsOptions.Tags.Elements() {
if v.IsNull() {
tags := make([]*models.TagRequest, 0, len(p.AwsOptions.Tags.Elements()))
elements := make(map[string]string, len(p.AwsOptions.Tags.Elements()))
diags := p.AwsOptions.Tags.ElementsAs(ctx, &elements, false)
for k, v := range elements {
if v == "" {
continue
}
value := strings.TrimPrefix(strings.TrimSuffix(v.String(), "\""), "\"")
tags = append(tags, &models.TagRequest{
Key: &k,
Value: &value,
Value: &v,
})
}
return tags
return tags, diags
}

func (p *resourceModel) getQueryIsolationOptions() *models.QueryIsolationOptionsRequest {
Expand Down Expand Up @@ -146,6 +142,9 @@ func (p *resourceModel) getAutoscaling() *models.AutoscalingOptionsCreateRequest
}

func (p *resourceModel) setFromDescribeVwResponse(resp *models.DescribeVwResponse) {
if resp.Vw == nil {
return
}
p.ID = types.StringValue(resp.Vw.ID)
p.DatabaseCatalogID = types.StringValue(resp.Vw.DbcID)
p.Name = types.StringValue(resp.Vw.Name)
Expand Down
7 changes: 6 additions & 1 deletion resources/dw/virtualwarehouse/hive/resource_hive_vw.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,13 @@ func (r *hiveResource) Create(ctx context.Context, req resource.CreateRequest, r
return
}

createReq, diags := plan.convertToCreateVwRequest(ctx)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
}
vw := operations.NewCreateVwParamsWithContext(ctx).
WithInput(plan.convertToCreateVwRequest())
WithInput(createReq)

response, err := r.client.Dw.Operations.CreateVw(vw)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ func testAccHiveBasicConfig(params hiveTestParameters) string {
cluster_id = %[1]q
database_catalog_id = %[2]q
name = %[3]q
image_version = "2024.0.18.4-3"
group_size = 2
platform_jwt_auth = true
enable_sso = true
Expand Down
12 changes: 8 additions & 4 deletions resources/dw/virtualwarehouse/hive/resource_hive_vw_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ var testHiveSchema = schema.Schema{
"ldap_groups": schema.ListAttribute{
Optional: true,
ElementType: types.StringType,
MarkdownDescription: "LDAP group names to be enabled for auth.",
MarkdownDescription: "LDAP group names to be enabled to authenticate with.",
},
"enable_sso": schema.BoolAttribute{
Optional: true,
Expand Down Expand Up @@ -175,7 +175,7 @@ var testHiveSchema = schema.Schema{
},
"status": schema.StringAttribute{
Computed: true,
MarkdownDescription: "The status of the database catalog.",
MarkdownDescription: "The status of the Hive Virtual Warehouse.",
},
"polling_options": schema.SingleNestedAttribute{
MarkdownDescription: "Polling related configuration options that could specify various values that will be used during CDP resource creation.",
Expand Down Expand Up @@ -582,6 +582,7 @@ func (suite *HiveTestSuite) TestStateRefresh_FailureThresholdReached() {
}

func (suite *HiveTestSuite) TestConvertToCreateVwRequest_All() {
ctx := context.TODO()
plan := resourceModel{
ClusterID: types.StringValue("cluster-id"),
DatabaseCatalogID: types.StringValue("database-catalog-id"),
Expand All @@ -606,7 +607,8 @@ func (suite *HiveTestSuite) TestConvertToCreateVwRequest_All() {
},
}

req := plan.convertToCreateVwRequest()
req, diags := plan.convertToCreateVwRequest(ctx)
suite.False(diags.HasError())
suite.Equal("cluster-id", *req.ClusterID)
suite.Equal("database-catalog-id", *req.DbcID)
suite.Equal("test-name", *req.Name)
Expand All @@ -630,12 +632,14 @@ func (suite *HiveTestSuite) TestConvertToCreateVwRequest_All() {
}

func (suite *HiveTestSuite) TestConvertToCreateVwRequest_MissingImageVersion() {
ctx := context.TODO()
plan := resourceModel{
ImageVersion: types.StringUnknown(),
AwsOptions: &awsOptions{},
}

req := plan.convertToCreateVwRequest()
req, diags := plan.convertToCreateVwRequest(ctx)
suite.False(diags.HasError())
suite.Equal("", req.ImageVersion)
}

Expand Down
4 changes: 2 additions & 2 deletions resources/dw/virtualwarehouse/hive/schema_hive_vw.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ var hiveSchema = schema.Schema{
"ldap_groups": schema.ListAttribute{
Optional: true,
ElementType: types.StringType,
MarkdownDescription: "LDAP group names to be enabled for auth.",
MarkdownDescription: "LDAP group names to be enabled to authenticate with.",
},
"enable_sso": schema.BoolAttribute{
Optional: true,
Expand Down Expand Up @@ -157,7 +157,7 @@ var hiveSchema = schema.Schema{
},
"status": schema.StringAttribute{
Computed: true,
MarkdownDescription: "The status of the database catalog.",
MarkdownDescription: "The status of the Hive Virtual Warehouse.",
},
"polling_options": schema.SingleNestedAttribute{
MarkdownDescription: "Polling related configuration options that could specify various values that will be used during CDP resource creation.",
Expand Down

0 comments on commit 7e3eae4

Please sign in to comment.