diff --git a/docs/resources/dw_vw_hive.md b/docs/resources/dw_vw_hive.md
index 47359d3a..37163c64 100644
--- a/docs/resources/dw_vw_hive.md
+++ b/docs/resources/dw_vw_hive.md
@@ -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
@@ -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
}
```
@@ -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’.
@@ -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.
### Nested Schema for `aws_options`
diff --git a/examples/resources/cdp_dw_vw_hive/resource.tf b/examples/resources/cdp_dw_vw_hive/resource.tf
index f6d434fe..dad5463a 100644
--- a/examples/resources/cdp_dw_vw_hive/resource.tf
+++ b/examples/resources/cdp_dw_vw_hive/resource.tf
@@ -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
@@ -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
}
\ No newline at end of file
diff --git a/resources/dw/virtualwarehouse/hive/model_hive_vw.go b/resources/dw/virtualwarehouse/hive/model_hive_vw.go
index 85b98463..4518da45 100644
--- a/resources/dw/virtualwarehouse/hive/model_hive_vw.go
+++ b/resources/dw/virtualwarehouse/hive/model_hive_vw.go
@@ -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"
@@ -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() == "" {
- return ""
- }
- return strings.TrimPrefix(strings.TrimSuffix(p.ImageVersion.String(), "\""), "\"")
+ }, diags
}
func (p *resourceModel) getServiceConfig() *models.ServiceConfigReq {
@@ -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 {
@@ -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)
diff --git a/resources/dw/virtualwarehouse/hive/resource_hive_vw.go b/resources/dw/virtualwarehouse/hive/resource_hive_vw.go
index e4b9d29a..f960b86d 100644
--- a/resources/dw/virtualwarehouse/hive/resource_hive_vw.go
+++ b/resources/dw/virtualwarehouse/hive/resource_hive_vw.go
@@ -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 {
diff --git a/resources/dw/virtualwarehouse/hive/resource_hive_vw_test.go b/resources/dw/virtualwarehouse/hive/resource_hive_vw_test.go
index 18f7fd10..1bb16415 100644
--- a/resources/dw/virtualwarehouse/hive/resource_hive_vw_test.go
+++ b/resources/dw/virtualwarehouse/hive/resource_hive_vw_test.go
@@ -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,
@@ -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.",
@@ -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"),
@@ -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)
@@ -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)
}
diff --git a/resources/dw/virtualwarehouse/hive/schema_hive_vw.go b/resources/dw/virtualwarehouse/hive/schema_hive_vw.go
index e9fe8d35..a8c679b9 100644
--- a/resources/dw/virtualwarehouse/hive/schema_hive_vw.go
+++ b/resources/dw/virtualwarehouse/hive/schema_hive_vw.go
@@ -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,
@@ -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.",