From 7d5133a3c95f399ba71e3371d966a3309042566c Mon Sep 17 00:00:00 2001 From: Agnes Tevesz Date: Tue, 10 Dec 2024 22:28:57 -0600 Subject: [PATCH] Adding unit tests and example resource with all properties --- docs/resources/dw_vw_hive.md | 29 ++++++++- examples/resources/cdp_dw_vw_hive/resource.tf | 29 ++++++++- resources/dw/resource_dw_acc_test.go | 4 +- .../dw/virtualwarehouse/hive/model_hive_vw.go | 2 +- .../hive/resource_hive_vw_acc_test.go | 11 +++- .../hive/resource_hive_vw_test.go | 64 +++++++++++++++++++ 6 files changed, 129 insertions(+), 10 deletions(-) diff --git a/docs/resources/dw_vw_hive.md b/docs/resources/dw_vw_hive.md index 9858b935..9c2978a1 100644 --- a/docs/resources/dw_vw_hive.md +++ b/docs/resources/dw_vw_hive.md @@ -23,9 +23,32 @@ A Hive Virtual Warehouse is service which is able to run big SQL queries. # permissions and limitations governing your use of the file. resource "cdp_dw_vw_hive" "example" { - cluster_id = var.cluster_id - database_catalog_id = var.database_catalog_id - name = var.name + cluster_id = "env-id" + database_catalog_id = "warehouse-id" + name = "default-catalog" + node_count = 2 + platform_jwt_auth = true + enable_sso = true + image_version = "2024.0.19.0-301" + autoscaling = { + min_clusters = 1 + max_clusters = 3 + disable_auto_suspend = false + auto_suspend_timeout_seconds = 100 + hive_scale_wait_time_seconds = 230 + hive_desired_free_capacity = 1 + } + aws_options = { + availability_zone = "us-west-2a" + ebs_llap_spill_gb = 300 + tags = { + "key1" = "value1" + } + } + query_isolation_options = { + max_queries = 100 + max_nodes_per_query = 10 + } } ``` diff --git a/examples/resources/cdp_dw_vw_hive/resource.tf b/examples/resources/cdp_dw_vw_hive/resource.tf index c4094659..04b75c76 100644 --- a/examples/resources/cdp_dw_vw_hive/resource.tf +++ b/examples/resources/cdp_dw_vw_hive/resource.tf @@ -9,7 +9,30 @@ # permissions and limitations governing your use of the file. resource "cdp_dw_vw_hive" "example" { - cluster_id = var.cluster_id - database_catalog_id = var.database_catalog_id - name = var.name + cluster_id = "env-id" + database_catalog_id = "warehouse-id" + name = "default-catalog" + node_count = 2 + platform_jwt_auth = true + enable_sso = true + image_version = "2024.0.19.0-301" + autoscaling = { + min_clusters = 1 + max_clusters = 3 + disable_auto_suspend = false + auto_suspend_timeout_seconds = 100 + hive_scale_wait_time_seconds = 230 + hive_desired_free_capacity = 1 + } + aws_options = { + availability_zone = "us-west-2a" + ebs_llap_spill_gb = 300 + tags = { + "key1" = "value1" + } + } + query_isolation_options = { + max_queries = 100 + max_nodes_per_query = 10 + } } diff --git a/resources/dw/resource_dw_acc_test.go b/resources/dw/resource_dw_acc_test.go index 4300051a..f56d924a 100644 --- a/resources/dw/resource_dw_acc_test.go +++ b/resources/dw/resource_dw_acc_test.go @@ -287,7 +287,7 @@ func testAccHiveVirtualWarehouse(name string) string { enable_sso = true image_version = "2024.0.19.0-301" node_count = 2 - autoscaling = { + autoscaling = { min_clusters = 1 max_clusters = 3 disable_auto_suspend = false @@ -298,7 +298,7 @@ func testAccHiveVirtualWarehouse(name string) string { availability_zone = "us-west-2a" ebs_llap_spill_gb = 300 tags = { - owner = "cdw-terraform@cloudera.com" + owner = "cdw-terraform" } } } diff --git a/resources/dw/virtualwarehouse/hive/model_hive_vw.go b/resources/dw/virtualwarehouse/hive/model_hive_vw.go index 318580b9..0bfc2137 100644 --- a/resources/dw/virtualwarehouse/hive/model_hive_vw.go +++ b/resources/dw/virtualwarehouse/hive/model_hive_vw.go @@ -88,7 +88,7 @@ func (p *resourceModel) convertToCreateVwRequest() *models.CreateVwRequest { } func (p *resourceModel) getImageVersion() string { - if p.ImageVersion.IsNull() || p.ImageVersion.String() == "" { + if p.ImageVersion.IsNull() || p.ImageVersion.IsUnknown() || p.ImageVersion.String() == "" { return "" } return strings.TrimPrefix(strings.TrimSuffix(p.ImageVersion.String(), "\""), "\"") diff --git a/resources/dw/virtualwarehouse/hive/resource_hive_vw_acc_test.go b/resources/dw/virtualwarehouse/hive/resource_hive_vw_acc_test.go index 68a05cbe..0a4fc976 100644 --- a/resources/dw/virtualwarehouse/hive/resource_hive_vw_acc_test.go +++ b/resources/dw/virtualwarehouse/hive/resource_hive_vw_acc_test.go @@ -67,6 +67,12 @@ func TestAccHive_basic(t *testing.T) { resource.TestCheckResourceAttr("cdp_dw_vw_hive.test_hive", "name", params.Name), resource.TestCheckResourceAttr("cdp_dw_vw_hive.test_hive", "cluster_id", params.ClusterID), resource.TestCheckResourceAttr("cdp_dw_vw_hive.test_hive", "database_catalog_id", params.DatabaseCatalogID), + resource.TestCheckResourceAttrSet("cdp_dw_vw_hive.test_hive", "compactor"), + resource.TestCheckResourceAttrSet("cdp_dw_vw_hive.test_hive", "jdbc_url"), + resource.TestCheckResourceAttrSet("cdp_dw_vw_hive.test_hive", "kerberos_jdbc_url"), + resource.TestCheckResourceAttrSet("cdp_dw_vw_hive.test_hive", "hue_url"), + resource.TestCheckResourceAttrSet("cdp_dw_vw_hive.test_hive", "jwt_connection_string"), + resource.TestCheckResourceAttrSet("cdp_dw_vw_hive.test_hive", "jwt_token_gen_url"), ), }, // Delete testing automatically occurs in TestCase @@ -83,7 +89,6 @@ func testAccHiveBasicConfig(params hiveTestParameters) string { node_count = 2 platform_jwt_auth = true enable_sso = true - image_version = "2024.0.19.0-301" autoscaling = { min_clusters = 2 max_clusters = 5 @@ -98,6 +103,10 @@ func testAccHiveBasicConfig(params hiveTestParameters) string { owner = "cdw-terraform@cloudera.com" } } + query_isolation_options = { + max_queries = 100 + max_nodes_per_query = 10 + } } `, params.ClusterID, params.DatabaseCatalogID, params.Name) } diff --git a/resources/dw/virtualwarehouse/hive/resource_hive_vw_test.go b/resources/dw/virtualwarehouse/hive/resource_hive_vw_test.go index d2bcd38f..c591a741 100644 --- a/resources/dw/virtualwarehouse/hive/resource_hive_vw_test.go +++ b/resources/dw/virtualwarehouse/hive/resource_hive_vw_test.go @@ -16,6 +16,7 @@ import ( "testing" "github.com/go-openapi/runtime" + "github.com/hashicorp/terraform-plugin-framework/attr" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault" @@ -591,3 +592,66 @@ func (suite *HiveTestSuite) TestStateRefresh_FailureThresholdReached() { } suite.Error(err, "unknown error") } + +func (suite *HiveTestSuite) TestConvertToCreateVwRequest_All() { + plan := resourceModel{ + ClusterID: types.StringValue("cluster-id"), + DatabaseCatalogID: types.StringValue("database-catalog-id"), + Name: types.StringValue("test-name"), + ImageVersion: types.StringValue("2024.0.19.0-301"), + NodeCount: types.Int64Value(10), + PlatformJwtAuth: types.BoolValue(true), + LdapGroups: types.ListValueMust(types.StringType, []attr.Value{types.StringValue("ldap-group")}), + EnableSSO: types.BoolValue(true), + Autoscaling: &autoscaling{ + MinClusters: types.Int64Value(1), + MaxClusters: types.Int64Value(10), + DisableAutoSuspend: types.BoolValue(false), + AutoSuspendTimeoutSeconds: types.Int64Value(60), + HiveScaleWaitTimeSeconds: types.Int64Value(60), + HiveDesiredFreeCapacity: types.Int64Value(2), + }, + AwsOptions: &awsOptions{ + AvailabilityZone: types.StringValue("us-west-2a"), + EbsLLAPSpillGb: types.Int64Value(300), + Tags: types.MapValueMust(types.StringType, map[string]attr.Value{"key1": types.StringValue("value1")}), + }, + QueryIsolationOptions: &queryIsolationOptions{ + MaxQueries: types.Int64Value(5), + MaxNodesPerQuery: types.Int64Value(2), + }, + } + + req := plan.convertToCreateVwRequest() + suite.Equal("cluster-id", *req.ClusterID) + suite.Equal("database-catalog-id", *req.DbcID) + suite.Equal("test-name", *req.Name) + suite.Equal("2024.0.19.0-301", req.ImageVersion) + suite.Equal(int32(10), req.NodeCount) + suite.Equal(true, *req.PlatformJwtAuth) + suite.Equal([]string{"ldap-group"}, req.Config.LdapGroups) + suite.Equal(true, req.Config.EnableSSO) + suite.Equal(int32(1), *req.Autoscaling.MinClusters) + suite.Equal(int32(10), *req.Autoscaling.MaxClusters) + suite.Equal(false, req.Autoscaling.DisableAutoSuspend) + suite.Equal(int32(60), req.Autoscaling.AutoSuspendTimeoutSeconds) + suite.Equal(int32(60), req.Autoscaling.HiveScaleWaitTimeSeconds) + suite.Equal(int32(2), req.Autoscaling.HiveDesiredFreeCapacity) + suite.Equal("us-west-2a", req.AvailabilityZone) + suite.Equal(int32(300), req.EbsLLAPSpillGB) + suite.Equal("key1", *req.Tags[0].Key) + suite.Equal("value1", *req.Tags[0].Value) + suite.Equal(int32(5), req.QueryIsolationOptions.MaxQueries) + suite.Equal(int32(2), req.QueryIsolationOptions.MaxNodesPerQuery) +} + +func (suite *HiveTestSuite) TestConvertToCreateVwRequest_MissingImageVersion() { + plan := resourceModel{ + ImageVersion: types.StringUnknown(), + AwsOptions: &awsOptions{}, + Autoscaling: &autoscaling{}, + } + + req := plan.convertToCreateVwRequest() + suite.Equal("", req.ImageVersion) +}