Skip to content

Commit

Permalink
Adding unit tests and example resource with all properties
Browse files Browse the repository at this point in the history
  • Loading branch information
tevesz committed Dec 11, 2024
1 parent 57c792d commit 7d5133a
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 10 deletions.
29 changes: 26 additions & 3 deletions docs/resources/dw_vw_hive.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
```

Expand Down
29 changes: 26 additions & 3 deletions examples/resources/cdp_dw_vw_hive/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
4 changes: 2 additions & 2 deletions resources/dw/resource_dw_acc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion resources/dw/virtualwarehouse/hive/model_hive_vw.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (p *resourceModel) convertToCreateVwRequest() *models.CreateVwRequest {
}

func (p *resourceModel) getImageVersion() string {
if p.ImageVersion.IsNull() || p.ImageVersion.String() == "<unknown>" {
if p.ImageVersion.IsNull() || p.ImageVersion.IsUnknown() || p.ImageVersion.String() == "<unknown>" {
return ""
}
return strings.TrimPrefix(strings.TrimSuffix(p.ImageVersion.String(), "\""), "\"")
Expand Down
11 changes: 10 additions & 1 deletion resources/dw/virtualwarehouse/hive/resource_hive_vw_acc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -98,6 +103,10 @@ func testAccHiveBasicConfig(params hiveTestParameters) string {
owner = "[email protected]"
}
}
query_isolation_options = {
max_queries = 100
max_nodes_per_query = 10
}
}
`, params.ClusterID, params.DatabaseCatalogID, params.Name)
}
Expand Down
64 changes: 64 additions & 0 deletions resources/dw/virtualwarehouse/hive/resource_hive_vw_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}

0 comments on commit 7d5133a

Please sign in to comment.