diff --git a/docs/resources/datalake_azure_datalake.md b/docs/resources/datalake_azure_datalake.md index 8ae2eec9..c6fde6d3 100644 --- a/docs/resources/datalake_azure_datalake.md +++ b/docs/resources/datalake_azure_datalake.md @@ -25,8 +25,11 @@ A Data Lake is a service which provides a protective ring around the data stored - `database_type` (String) The type of the azure database. FLEXIBLE_SERVER is the next generation managed PostgreSQL service in Azure that provides maximum flexibility over your database, built-in cost-optimizations. SINGLE_SERVER is a fully managed database service with minimal requirements for customizations of the database. - `enable_ranger_raz` (Boolean) +- `flexible_server_delegated_subnet_id` (String) This argument allows you to specify the subnet ID for the subnet within which you want to configure your Azure Flexible Server. - `image` (Attributes) (see [below for nested schema](#nestedatt--image)) - `java_version` (Number) +- `load_balancer_sku` (String) Represents the Azure load balancer SKU type. The current default is BASIC. To disable the load balancer, use type NONE. Possible values: BASIC, STANDARD, NONE +- `multi_az` (Boolean) Creates CDP datalake distributed across multiple availability zones in an Azure region. - `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)) - `recipes` (Attributes Set) (see [below for nested schema](#nestedatt--recipes)) - `runtime` (String) diff --git a/provider/provider_test.go b/provider/provider_test.go index cd314aa4..4b350f64 100644 --- a/provider/provider_test.go +++ b/provider/provider_test.go @@ -674,7 +674,7 @@ func TestCdpProvider_Schema(t *testing.T) { sresps = append(sresps, attribute) } - unexpectedFields, missingFields := testUtil.CompareStrings(sresps, expectedSchemaFields) + unexpectedFields, missingFields := testUtil.CompareStringSlices(sresps, expectedSchemaFields) if len(unexpectedFields) > 0 { t.Errorf("The following unexpected field(s) got introduced: %s", strings.Join(unexpectedFields, ",")) @@ -720,13 +720,13 @@ func TestCdpProvider_DataSources(t *testing.T) { func compareResources(actual, expected []func() resource.Resource) (unexpected, missing []string) { actualNames := testUtil.ToStringSliceFunc(actual, getPackageAndNameOfResource) expectedNames := testUtil.ToStringSliceFunc(expected, getPackageAndNameOfResource) - return testUtil.CompareStrings(actualNames, expectedNames) + return testUtil.CompareStringSlices(actualNames, expectedNames) } func compareDataSources(actual, expected []func() datasource.DataSource) (unexpected, missing []string) { actualNames := testUtil.ToStringSliceFunc(actual, getPackageAndNameOfDataSource) expectedNames := testUtil.ToStringSliceFunc(expected, getPackageAndNameOfDataSource) - return testUtil.CompareStrings(actualNames, expectedNames) + return testUtil.CompareStringSlices(actualNames, expectedNames) } func getPackageAndNameOfResource(f func() resource.Resource) string { diff --git a/resources/datahub/converter.go b/resources/datahub/converter.go index 15f49846..b1b378c8 100644 --- a/resources/datahub/converter.go +++ b/resources/datahub/converter.go @@ -19,6 +19,7 @@ import ( "github.com/hashicorp/terraform-plugin-log/tflog" datahubmodels "github.com/cloudera/terraform-provider-cdp/cdp-sdk-go/gen/datahub/models" + "github.com/cloudera/terraform-provider-cdp/utils" ) func fromModelToAwsRequest(model awsDatahubResourceModel, ctx context.Context) *datahubmodels.CreateAWSClusterRequest { @@ -49,7 +50,7 @@ func fromModelToAwsRequest(model awsDatahubResourceModel, ctx context.Context) * InstanceGroupName: group.InstanceGroupName.ValueStringPointer(), InstanceGroupType: group.InstanceGroupType.ValueStringPointer(), InstanceType: group.InstanceType.ValueStringPointer(), - NodeCount: int64To32Pointer(group.NodeCount), + NodeCount: utils.Int64To32Pointer(group.NodeCount), RecipeNames: igRecipes, RecoveryMode: group.RecoveryMode.ValueString(), RootVolumeSize: int64To32(group.RootVolumeSize), @@ -131,7 +132,7 @@ func fromModelToGcpRequest(model gcpDatahubResourceModel, ctx context.Context) * InstanceGroupName: group.InstanceGroupName.ValueStringPointer(), InstanceGroupType: group.InstanceGroupType.ValueStringPointer(), InstanceType: group.InstanceType.ValueStringPointer(), - NodeCount: int64To32Pointer(group.NodeCount), + NodeCount: utils.Int64To32Pointer(group.NodeCount), RecipeNames: igRecipes, RecoveryMode: group.RecoveryMode.ValueString(), RootVolumeSize: &volumeSize, @@ -210,7 +211,7 @@ func fromModelToAzureRequest(model azureDatahubResourceModel, ctx context.Contex InstanceGroupName: group.InstanceGroupName.ValueStringPointer(), InstanceGroupType: group.InstanceGroupType.ValueStringPointer(), InstanceType: group.InstanceType.ValueStringPointer(), - NodeCount: int64To32Pointer(group.NodeCount), + NodeCount: utils.Int64To32Pointer(group.NodeCount), RecipeNames: igRecipes, RecoveryMode: group.RecoveryMode.ValueString(), RootVolumeSize: &rootVolumeSize, @@ -259,8 +260,8 @@ func fromModelToAzureRequest(model azureDatahubResourceModel, ctx context.Contex func createAttachedVolumeRequest(attachedVolumeConfig AttachedVolumeConfiguration) *datahubmodels.AttachedVolumeRequest { return &datahubmodels.AttachedVolumeRequest{ - VolumeCount: int64To32Pointer(attachedVolumeConfig.VolumeCount), - VolumeSize: int64To32Pointer(attachedVolumeConfig.VolumeSize), + VolumeCount: utils.Int64To32Pointer(attachedVolumeConfig.VolumeCount), + VolumeSize: utils.Int64To32Pointer(attachedVolumeConfig.VolumeSize), VolumeType: attachedVolumeConfig.VolumeType.ValueStringPointer(), } } @@ -269,9 +270,3 @@ func int64To32(in types.Int64) int32 { n64 := in.ValueInt64() return int32(n64) } - -func int64To32Pointer(in types.Int64) *int32 { - n64 := in.ValueInt64() - var n2 = int32(n64) - return &n2 -} diff --git a/resources/datahub/converter_test.go b/resources/datahub/converter_test.go index 26827f3a..0ce63b60 100644 --- a/resources/datahub/converter_test.go +++ b/resources/datahub/converter_test.go @@ -14,6 +14,7 @@ import ( "context" "testing" + "github.com/cloudera/terraform-provider-cdp/utils/test" "github.com/hashicorp/terraform-plugin-framework/attr" "github.com/hashicorp/terraform-plugin-framework/types" ) @@ -53,22 +54,22 @@ func TestFromModelToRequestBasicFields(t *testing.T) { } got := fromModelToAwsRequest(input, context.TODO()) - compareStrings(got.ClusterName, input.Name.ValueString(), t) - compareStrings(got.Environment, input.Environment.ValueString(), t) - compareStrings(got.ClusterTemplate, input.ClusterTemplate.ValueString(), t) - compareStrings(got.SubnetID, input.SubnetId.ValueString(), t) - compareStringSlices(got.SubnetIds, input.SubnetIds.Elements(), t) - compareBools(got.MultiAz, input.MultiAz.ValueBool(), t) - compareStrings(*got.Tags[0].Value, input.Tags.Elements()["key"].(types.String).ValueString(), t) - compareStrings(got.CustomConfigurationsName, input.CustomConfigurationsName.ValueString(), t) - compareStrings(got.Image.CatalogName, input.Image.Attributes()["catalog"].(types.String).ValueString(), t) - compareStrings(got.Image.ID, input.Image.Attributes()["id"].(types.String).ValueString(), t) - compareStrings(got.Image.Os, input.Image.Attributes()["os"].(types.String).ValueString(), t) - compareStrings(got.RequestTemplate, input.RequestTemplate.ValueString(), t) - compareStrings(string(got.DatahubDatabase), input.DatahubDatabase.ValueString(), t) - compareStrings(got.ClusterExtension.CustomProperties, input.ClusterExtension.Attributes()["custom_properties"].(types.String).ValueString(), t) - compareBools(got.EnableLoadBalancer, input.EnableLoadBalancer.ValueBool(), t) - compareInt32PointerToTypesInt64(&got.JavaVersion, input.JavaVersion, t) + test.CompareStrings(got.ClusterName, input.Name.ValueString(), t) + test.CompareStrings(got.Environment, input.Environment.ValueString(), t) + test.CompareStrings(got.ClusterTemplate, input.ClusterTemplate.ValueString(), t) + test.CompareStrings(got.SubnetID, input.SubnetId.ValueString(), t) + test.CompareStringValueSlices(got.SubnetIds, input.SubnetIds.Elements(), t) + test.CompareBools(got.MultiAz, input.MultiAz.ValueBool(), t) + test.CompareStrings(*got.Tags[0].Value, input.Tags.Elements()["key"].(types.String).ValueString(), t) + test.CompareStrings(got.CustomConfigurationsName, input.CustomConfigurationsName.ValueString(), t) + test.CompareStrings(got.Image.CatalogName, input.Image.Attributes()["catalog"].(types.String).ValueString(), t) + test.CompareStrings(got.Image.ID, input.Image.Attributes()["id"].(types.String).ValueString(), t) + test.CompareStrings(got.Image.Os, input.Image.Attributes()["os"].(types.String).ValueString(), t) + test.CompareStrings(got.RequestTemplate, input.RequestTemplate.ValueString(), t) + test.CompareStrings(string(got.DatahubDatabase), input.DatahubDatabase.ValueString(), t) + test.CompareStrings(got.ClusterExtension.CustomProperties, input.ClusterExtension.Attributes()["custom_properties"].(types.String).ValueString(), t) + test.CompareBools(got.EnableLoadBalancer, input.EnableLoadBalancer.ValueBool(), t) + test.CompareInt32PointerToTypesInt64(&got.JavaVersion, input.JavaVersion, t) } func TestFromModelToRequestRecipe(t *testing.T) { @@ -78,8 +79,8 @@ func TestFromModelToRequestRecipe(t *testing.T) { got := fromModelToAwsRequest(input, context.TODO()) - compareInts(len(got.InstanceGroups), len(input.InstanceGroup), t) - compareInts(len(got.InstanceGroups[0].RecipeNames), len(input.InstanceGroup[0].Recipes), t) + test.CompareInts(len(got.InstanceGroups), len(input.InstanceGroup), t) + test.CompareInts(len(got.InstanceGroups[0].RecipeNames), len(input.InstanceGroup[0].Recipes), t) for _, convertedRecipe := range got.InstanceGroups[0].RecipeNames { var contains bool @@ -105,13 +106,13 @@ func TestFromModelToRequestAttachedVolumeConfiguration(t *testing.T) { got := fromModelToAwsRequest(input, context.TODO()) - compareInts(len(got.InstanceGroups), len(input.InstanceGroup), t) - compareInts(len(got.InstanceGroups[0].AttachedVolumeConfiguration), len(avcs), t) + test.CompareInts(len(got.InstanceGroups), len(input.InstanceGroup), t) + test.CompareInts(len(got.InstanceGroups[0].AttachedVolumeConfiguration), len(avcs), t) resultAvcs := got.InstanceGroups[0].AttachedVolumeConfiguration[0] - compareInt32PointerToTypesInt64(resultAvcs.VolumeCount, avcs[0].VolumeCount, t) - compareInt32PointerToTypesInt64(resultAvcs.VolumeSize, avcs[0].VolumeSize, t) - compareStrings(*resultAvcs.VolumeType, avcs[0].VolumeType.ValueString(), t) + test.CompareInt32PointerToTypesInt64(resultAvcs.VolumeCount, avcs[0].VolumeCount, t) + test.CompareInt32PointerToTypesInt64(resultAvcs.VolumeSize, avcs[0].VolumeSize, t) + test.CompareStrings(*resultAvcs.VolumeType, avcs[0].VolumeType.ValueString(), t) } func TestFromModelToRequestInstanceGroups(t *testing.T) { @@ -128,13 +129,13 @@ func TestFromModelToRequestInstanceGroups(t *testing.T) { got := fromModelToAwsRequest(input, context.TODO()) - compareInts(len(got.InstanceGroups), len(igs), t) + test.CompareInts(len(got.InstanceGroups), len(igs), t) resultIg := got.InstanceGroups[0] - compareStrings(*resultIg.InstanceGroupName, igs[0].InstanceGroupName.ValueString(), t) - compareStrings(*resultIg.InstanceGroupType, igs[0].InstanceGroupType.ValueString(), t) - compareStrings(*resultIg.InstanceType, igs[0].InstanceType.ValueString(), t) - compareInt32PointerToTypesInt64(&resultIg.RootVolumeSize, igs[0].RootVolumeSize, t) - compareStrings(resultIg.RecoveryMode, igs[0].RecoveryMode.ValueString(), t) + test.CompareStrings(*resultIg.InstanceGroupName, igs[0].InstanceGroupName.ValueString(), t) + test.CompareStrings(*resultIg.InstanceGroupType, igs[0].InstanceGroupType.ValueString(), t) + test.CompareStrings(*resultIg.InstanceType, igs[0].InstanceType.ValueString(), t) + test.CompareInt32PointerToTypesInt64(&resultIg.RootVolumeSize, igs[0].RootVolumeSize, t) + test.CompareStrings(resultIg.RecoveryMode, igs[0].RecoveryMode.ValueString(), t) } func TestFromModelToRequestVolumeEncryption(t *testing.T) { @@ -146,12 +147,12 @@ func TestFromModelToRequestVolumeEncryption(t *testing.T) { got := fromModelToAwsRequest(input, context.TODO()) - compareInts(len(got.InstanceGroups), len(igs), t) + test.CompareInts(len(got.InstanceGroups), len(igs), t) resultVolumeEncryption := got.InstanceGroups[0].VolumeEncryption if resultVolumeEncryption == nil { t.Errorf("Volume encryption is not filled though it should've been!") } else { - compareBools(*resultVolumeEncryption.EnableEncryption, igs[0].VolumeEncryption.Encryption.ValueBool(), t) + test.CompareBools(*resultVolumeEncryption.EnableEncryption, igs[0].VolumeEncryption.Encryption.ValueBool(), t) } } @@ -159,7 +160,7 @@ func TestFromModelToRequestClusterDefinition(t *testing.T) { input := awsDatahubResourceModel{ClusterDefinition: types.StringValue("SomeClusterDef")} got := fromModelToAwsRequest(input, context.TODO()) - compareStrings(got.ClusterDefinition, input.ClusterDefinition.ValueString(), t) + test.CompareStrings(got.ClusterDefinition, input.ClusterDefinition.ValueString(), t) } func TestFromModelToGcpRequestBasicFields(t *testing.T) { @@ -193,19 +194,19 @@ func TestFromModelToGcpRequestBasicFields(t *testing.T) { } got := fromModelToGcpRequest(input, context.TODO()) - compareStrings(got.ClusterName, input.Name.ValueString(), t) - compareStrings(got.EnvironmentName, input.Environment.ValueString(), t) - compareStrings(got.ClusterTemplateName, input.ClusterTemplate.ValueString(), t) - compareStrings(got.SubnetName, input.SubnetName.ValueString(), t) - compareStrings(*got.Tags[0].Value, input.Tags.Elements()["key"].(types.String).ValueString(), t) - compareStrings(got.CustomConfigurationsName, input.CustomConfigurationsName.ValueString(), t) - compareStrings(got.Image.CatalogName, input.Image.Attributes()["catalog"].(types.String).ValueString(), t) - compareStrings(got.Image.ID, input.Image.Attributes()["id"].(types.String).ValueString(), t) - compareStrings(got.Image.Os, input.Image.Attributes()["os"].(types.String).ValueString(), t) - compareStrings(got.RequestTemplate, input.RequestTemplate.ValueString(), t) - compareStrings(string(got.DatahubDatabase), input.DatahubDatabase.ValueString(), t) - compareStrings(got.ClusterExtension.CustomProperties, input.ClusterExtension.Attributes()["custom_properties"].(types.String).ValueString(), t) - compareInt32PointerToTypesInt64(&got.JavaVersion, input.JavaVersion, t) + test.CompareStrings(got.ClusterName, input.Name.ValueString(), t) + test.CompareStrings(got.EnvironmentName, input.Environment.ValueString(), t) + test.CompareStrings(got.ClusterTemplateName, input.ClusterTemplate.ValueString(), t) + test.CompareStrings(got.SubnetName, input.SubnetName.ValueString(), t) + test.CompareStrings(*got.Tags[0].Value, input.Tags.Elements()["key"].(types.String).ValueString(), t) + test.CompareStrings(got.CustomConfigurationsName, input.CustomConfigurationsName.ValueString(), t) + test.CompareStrings(got.Image.CatalogName, input.Image.Attributes()["catalog"].(types.String).ValueString(), t) + test.CompareStrings(got.Image.ID, input.Image.Attributes()["id"].(types.String).ValueString(), t) + test.CompareStrings(got.Image.Os, input.Image.Attributes()["os"].(types.String).ValueString(), t) + test.CompareStrings(got.RequestTemplate, input.RequestTemplate.ValueString(), t) + test.CompareStrings(string(got.DatahubDatabase), input.DatahubDatabase.ValueString(), t) + test.CompareStrings(got.ClusterExtension.CustomProperties, input.ClusterExtension.Attributes()["custom_properties"].(types.String).ValueString(), t) + test.CompareInt32PointerToTypesInt64(&got.JavaVersion, input.JavaVersion, t) } func TestFromModelToGcpRequestRecipe(t *testing.T) { @@ -215,8 +216,8 @@ func TestFromModelToGcpRequestRecipe(t *testing.T) { got := fromModelToGcpRequest(input, context.TODO()) - compareInts(len(got.InstanceGroups), len(input.InstanceGroup), t) - compareInts(len(got.InstanceGroups[0].RecipeNames), len(input.InstanceGroup[0].Recipes), t) + test.CompareInts(len(got.InstanceGroups), len(input.InstanceGroup), t) + test.CompareInts(len(got.InstanceGroups[0].RecipeNames), len(input.InstanceGroup[0].Recipes), t) for _, convertedRecipe := range got.InstanceGroups[0].RecipeNames { var contains bool @@ -242,13 +243,13 @@ func TestFromModelToGcpRequestAttachedVolumeConfiguration(t *testing.T) { got := fromModelToGcpRequest(input, context.TODO()) - compareInts(len(got.InstanceGroups), len(input.InstanceGroup), t) - compareInts(len(got.InstanceGroups[0].AttachedVolumeConfiguration), len(avcs), t) + test.CompareInts(len(got.InstanceGroups), len(input.InstanceGroup), t) + test.CompareInts(len(got.InstanceGroups[0].AttachedVolumeConfiguration), len(avcs), t) resultAvcs := got.InstanceGroups[0].AttachedVolumeConfiguration[0] - compareInt32PointerToTypesInt64(resultAvcs.VolumeCount, avcs[0].VolumeCount, t) - compareInt32PointerToTypesInt64(resultAvcs.VolumeSize, avcs[0].VolumeSize, t) - compareStrings(*resultAvcs.VolumeType, avcs[0].VolumeType.ValueString(), t) + test.CompareInt32PointerToTypesInt64(resultAvcs.VolumeCount, avcs[0].VolumeCount, t) + test.CompareInt32PointerToTypesInt64(resultAvcs.VolumeSize, avcs[0].VolumeSize, t) + test.CompareStrings(*resultAvcs.VolumeType, avcs[0].VolumeType.ValueString(), t) } func TestFromModelToGcpRequestInstanceGroups(t *testing.T) { @@ -265,20 +266,20 @@ func TestFromModelToGcpRequestInstanceGroups(t *testing.T) { got := fromModelToGcpRequest(input, context.TODO()) - compareInts(len(got.InstanceGroups), len(igs), t) + test.CompareInts(len(got.InstanceGroups), len(igs), t) resultIg := got.InstanceGroups[0] - compareStrings(*resultIg.InstanceGroupName, igs[0].InstanceGroupName.ValueString(), t) - compareStrings(*resultIg.InstanceGroupType, igs[0].InstanceGroupType.ValueString(), t) - compareStrings(*resultIg.InstanceType, igs[0].InstanceType.ValueString(), t) - compareInt32PointerToTypesInt64(resultIg.RootVolumeSize, igs[0].RootVolumeSize, t) - compareStrings(resultIg.RecoveryMode, igs[0].RecoveryMode.ValueString(), t) + test.CompareStrings(*resultIg.InstanceGroupName, igs[0].InstanceGroupName.ValueString(), t) + test.CompareStrings(*resultIg.InstanceGroupType, igs[0].InstanceGroupType.ValueString(), t) + test.CompareStrings(*resultIg.InstanceType, igs[0].InstanceType.ValueString(), t) + test.CompareInt32PointerToTypesInt64(resultIg.RootVolumeSize, igs[0].RootVolumeSize, t) + test.CompareStrings(resultIg.RecoveryMode, igs[0].RecoveryMode.ValueString(), t) } func TestFromModelToGcpRequestClusterDefinition(t *testing.T) { input := gcpDatahubResourceModel{ClusterDefinition: types.StringValue("SomeClusterDef")} got := fromModelToGcpRequest(input, context.TODO()) - compareStrings(got.ClusterDefinitionName, input.ClusterDefinition.ValueString(), t) + test.CompareStrings(got.ClusterDefinitionName, input.ClusterDefinition.ValueString(), t) } func TestFromModelToAzureRequestBasicFields(t *testing.T) { @@ -315,22 +316,22 @@ func TestFromModelToAzureRequestBasicFields(t *testing.T) { } got := fromModelToAzureRequest(input, context.TODO()) - compareStrings(got.ClusterName, input.Name.ValueString(), t) - compareStrings(got.EnvironmentName, input.Environment.ValueString(), t) - compareStrings(got.ClusterTemplateName, input.ClusterTemplate.ValueString(), t) - compareStrings(got.SubnetID, input.SubnetId.ValueString(), t) - compareBools(*got.MultiAz, input.MultiAz.ValueBool(), t) - compareStrings(*got.Tags[0].Value, input.Tags.Elements()["key"].(types.String).ValueString(), t) - compareStrings(got.CustomConfigurationsName, input.CustomConfigurationsName.ValueString(), t) - compareStrings(got.Image.CatalogName, input.Image.Attributes()["catalog"].(types.String).ValueString(), t) - compareStrings(got.Image.ID, input.Image.Attributes()["id"].(types.String).ValueString(), t) - compareStrings(got.Image.Os, input.Image.Attributes()["os"].(types.String).ValueString(), t) - compareStrings(got.RequestTemplate, input.RequestTemplate.ValueString(), t) - compareStrings(string(got.DatahubDatabase), input.DatahubDatabase.ValueString(), t) - compareStrings(got.ClusterExtension.CustomProperties, input.ClusterExtension.Attributes()["custom_properties"].(types.String).ValueString(), t) - compareBools(got.EnableLoadBalancer, input.EnableLoadBalancer.ValueBool(), t) - compareInt32PointerToTypesInt64(&got.JavaVersion, input.JavaVersion, t) - compareStrings(got.FlexibleServerDelegatedSubnetID, input.FlexibleServerDelegatedSubnetId.ValueString(), t) + test.CompareStrings(got.ClusterName, input.Name.ValueString(), t) + test.CompareStrings(got.EnvironmentName, input.Environment.ValueString(), t) + test.CompareStrings(got.ClusterTemplateName, input.ClusterTemplate.ValueString(), t) + test.CompareStrings(got.SubnetID, input.SubnetId.ValueString(), t) + test.CompareBools(*got.MultiAz, input.MultiAz.ValueBool(), t) + test.CompareStrings(*got.Tags[0].Value, input.Tags.Elements()["key"].(types.String).ValueString(), t) + test.CompareStrings(got.CustomConfigurationsName, input.CustomConfigurationsName.ValueString(), t) + test.CompareStrings(got.Image.CatalogName, input.Image.Attributes()["catalog"].(types.String).ValueString(), t) + test.CompareStrings(got.Image.ID, input.Image.Attributes()["id"].(types.String).ValueString(), t) + test.CompareStrings(got.Image.Os, input.Image.Attributes()["os"].(types.String).ValueString(), t) + test.CompareStrings(got.RequestTemplate, input.RequestTemplate.ValueString(), t) + test.CompareStrings(string(got.DatahubDatabase), input.DatahubDatabase.ValueString(), t) + test.CompareStrings(got.ClusterExtension.CustomProperties, input.ClusterExtension.Attributes()["custom_properties"].(types.String).ValueString(), t) + test.CompareBools(got.EnableLoadBalancer, input.EnableLoadBalancer.ValueBool(), t) + test.CompareInt32PointerToTypesInt64(&got.JavaVersion, input.JavaVersion, t) + test.CompareStrings(got.FlexibleServerDelegatedSubnetID, input.FlexibleServerDelegatedSubnetId.ValueString(), t) } func TestFromModelToAzureRequestRecipe(t *testing.T) { @@ -340,8 +341,8 @@ func TestFromModelToAzureRequestRecipe(t *testing.T) { got := fromModelToAzureRequest(input, context.TODO()) - compareInts(len(got.InstanceGroups), len(input.InstanceGroup), t) - compareInts(len(got.InstanceGroups[0].RecipeNames), len(input.InstanceGroup[0].Recipes), t) + test.CompareInts(len(got.InstanceGroups), len(input.InstanceGroup), t) + test.CompareInts(len(got.InstanceGroups[0].RecipeNames), len(input.InstanceGroup[0].Recipes), t) for _, convertedRecipe := range got.InstanceGroups[0].RecipeNames { var contains bool @@ -367,13 +368,13 @@ func TestFromModelToAzureRequestAttachedVolumeConfiguration(t *testing.T) { got := fromModelToAzureRequest(input, context.TODO()) - compareInts(len(got.InstanceGroups), len(input.InstanceGroup), t) - compareInts(len(got.InstanceGroups[0].AttachedVolumeConfiguration), len(avcs), t) + test.CompareInts(len(got.InstanceGroups), len(input.InstanceGroup), t) + test.CompareInts(len(got.InstanceGroups[0].AttachedVolumeConfiguration), len(avcs), t) resultAvcs := got.InstanceGroups[0].AttachedVolumeConfiguration[0] - compareInt32PointerToTypesInt64(resultAvcs.VolumeCount, avcs[0].VolumeCount, t) - compareInt32PointerToTypesInt64(resultAvcs.VolumeSize, avcs[0].VolumeSize, t) - compareStrings(*resultAvcs.VolumeType, avcs[0].VolumeType.ValueString(), t) + test.CompareInt32PointerToTypesInt64(resultAvcs.VolumeCount, avcs[0].VolumeCount, t) + test.CompareInt32PointerToTypesInt64(resultAvcs.VolumeSize, avcs[0].VolumeSize, t) + test.CompareStrings(*resultAvcs.VolumeType, avcs[0].VolumeType.ValueString(), t) } func TestFromModelToAzureRequestInstanceGroups(t *testing.T) { @@ -390,55 +391,18 @@ func TestFromModelToAzureRequestInstanceGroups(t *testing.T) { got := fromModelToAzureRequest(input, context.TODO()) - compareInts(len(got.InstanceGroups), len(igs), t) + test.CompareInts(len(got.InstanceGroups), len(igs), t) resultIg := got.InstanceGroups[0] - compareStrings(*resultIg.InstanceGroupName, igs[0].InstanceGroupName.ValueString(), t) - compareStrings(*resultIg.InstanceGroupType, igs[0].InstanceGroupType.ValueString(), t) - compareStrings(*resultIg.InstanceType, igs[0].InstanceType.ValueString(), t) - compareInt32PointerToTypesInt64(resultIg.RootVolumeSize, igs[0].RootVolumeSize, t) - compareStrings(resultIg.RecoveryMode, igs[0].RecoveryMode.ValueString(), t) + test.CompareStrings(*resultIg.InstanceGroupName, igs[0].InstanceGroupName.ValueString(), t) + test.CompareStrings(*resultIg.InstanceGroupType, igs[0].InstanceGroupType.ValueString(), t) + test.CompareStrings(*resultIg.InstanceType, igs[0].InstanceType.ValueString(), t) + test.CompareInt32PointerToTypesInt64(resultIg.RootVolumeSize, igs[0].RootVolumeSize, t) + test.CompareStrings(resultIg.RecoveryMode, igs[0].RecoveryMode.ValueString(), t) } func TestFromModelToAzureRequestClusterDefinition(t *testing.T) { input := azureDatahubResourceModel{ClusterDefinition: types.StringValue("SomeClusterDef")} got := fromModelToAzureRequest(input, context.TODO()) - compareStrings(got.ClusterDefinitionName, input.ClusterDefinition.ValueString(), t) -} - -func compareStrings(got string, expected string, t *testing.T) { - if got != expected { - t.Errorf("Assertion error! Expected: %s, got: %s", expected, got) - } -} - -func compareStringSlices(got []string, expected []attr.Value, t *testing.T) { - if len(got) != len(expected) { - t.Errorf("Assertion error! Expected length: %d, got length: %d", len(expected), len(got)) - return - } - - for i, exp := range expected { - if got[i] != exp.(types.String).ValueString() { - t.Errorf("Assertion error! Expected: %s, got: %s", expected, got) - } - } -} - -func compareInt32PointerToTypesInt64(got *int32, expected types.Int64, t *testing.T) { - if *got != *int64To32Pointer(expected) { - t.Errorf("Assertion error! Expected: %d, got: %d", expected.ValueInt64(), *got) - } -} - -func compareInts(got int, expected int, t *testing.T) { - if got != expected { - t.Errorf("Assertion error! Expected: %d, got: %d", expected, got) - } -} - -func compareBools(got bool, expected bool, t *testing.T) { - if got != expected { - t.Errorf("Assertion error! Expected: %t, got: %t", expected, got) - } + test.CompareStrings(got.ClusterDefinitionName, input.ClusterDefinition.ValueString(), t) } diff --git a/resources/datalake/model_azure_datalake.go b/resources/datalake/model_azure_datalake.go index 0c15fef1..02bb707c 100644 --- a/resources/datalake/model_azure_datalake.go +++ b/resources/datalake/model_azure_datalake.go @@ -64,6 +64,12 @@ type azureDatalakeResourceModel struct { Tags types.Map `tfsdk:"tags"` DatabaseType types.String `tfsdk:"database_type"` + + LoadBalancerSku types.String `tfsdk:"load_balancer_sku"` + + FlexibleServerDelegatedSubnetId types.String `tfsdk:"flexible_server_delegated_subnet_id"` + + MultiAz types.Bool `tfsdk:"multi_az"` } type azureDatalakeImage struct { diff --git a/resources/datalake/resource_azure_datalake.go b/resources/datalake/resource_azure_datalake.go index 09db4728..bcbfee06 100644 --- a/resources/datalake/resource_azure_datalake.go +++ b/resources/datalake/resource_azure_datalake.go @@ -92,6 +92,9 @@ func toAzureDatalakeRequest(ctx context.Context, model *azureDatalakeResourceMod i++ } } + req.LoadBalancerSku = datalakemodels.DatalakeLoadBalancerSkuType(model.LoadBalancerSku.ValueString()) + req.FlexibleServerDelegatedSubnetID = model.FlexibleServerDelegatedSubnetId.ValueString() + req.MultiAz = model.MultiAz.ValueBoolPointer() return req } diff --git a/resources/datalake/resource_azure_datalake_test.go b/resources/datalake/resource_azure_datalake_test.go new file mode 100644 index 00000000..f4337f15 --- /dev/null +++ b/resources/datalake/resource_azure_datalake_test.go @@ -0,0 +1,70 @@ +// 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 datalake + +import ( + "context" + "testing" + + "github.com/cloudera/terraform-provider-cdp/utils/test" + "github.com/hashicorp/terraform-plugin-framework/attr" + "github.com/hashicorp/terraform-plugin-framework/types" +) + +func TestFromModelToAzureRequestBasicFields(t *testing.T) { + tags, _ := types.MapValue(types.StringType, map[string]attr.Value{"key": types.StringValue("value")}) + image := &azureDatalakeImage{ + CatalogName: types.StringValue("someCatalog"), + ID: types.StringValue("someId"), + Os: types.StringValue("someOs"), + } + recipes, _ := types.SetValue(types.StringType, []attr.Value{types.StringValue("recipe")}) + input := azureDatalakeResourceModel{ + DatalakeName: types.StringValue("someClusterName"), + EnvironmentName: types.StringValue("someEnvironment"), + DatabaseType: types.StringValue("someClusterTemplateNameOrCRN"), + ManagedIdentity: types.StringValue("someManagedIdentity"), + StorageLocationBase: types.StringValue("someStorageLocationBase"), + MultiAz: types.BoolValue(true), + Tags: tags, + Recipes: []*instanceGroupRecipe{&instanceGroupRecipe{ + InstanceGroupName: types.StringValue("someSubnetID"), + RecipeNames: recipes, + }}, + Runtime: types.StringValue("someRuntime"), + Image: image, + Scale: types.StringValue("someScale"), + LoadBalancerSku: types.StringValue("someLoadBalancerSku"), + EnableRangerRaz: types.BoolValue(true), + JavaVersion: types.Int64Value(11), + FlexibleServerDelegatedSubnetId: types.StringValue("someFlexibleServerDelegatedSubnetId"), + } + got := toAzureDatalakeRequest(context.TODO(), &input) + + test.CompareStrings(*got.DatalakeName, input.DatalakeName.ValueString(), t) + test.CompareStrings(*got.EnvironmentName, input.EnvironmentName.ValueString(), t) + test.CompareStrings(got.DatabaseType, input.DatabaseType.ValueString(), t) + test.CompareStrings(*got.CloudProviderConfiguration.ManagedIdentity, input.ManagedIdentity.ValueString(), t) + test.CompareStrings(*got.CloudProviderConfiguration.StorageLocation, input.StorageLocationBase.ValueString(), t) + test.CompareBools(*got.MultiAz, input.MultiAz.ValueBool(), t) + test.CompareStrings(*got.Tags[0].Value, input.Tags.Elements()["key"].(types.String).ValueString(), t) + test.CompareStrings(*got.Recipes[0].InstanceGroupName, input.Recipes[0].InstanceGroupName.ValueString(), t) + test.CompareStrings(*&got.Recipes[0].RecipeNames[0], input.Recipes[0].RecipeNames.Elements()[0].(types.String).ValueString(), t) + test.CompareStrings(got.Runtime, input.Runtime.ValueString(), t) + test.CompareStrings(*got.Image.CatalogName, input.Image.CatalogName.ValueString(), t) + test.CompareStrings(got.Image.ID, input.Image.ID.ValueString(), t) + test.CompareStrings(got.Image.Os, input.Image.Os.ValueString(), t) + test.CompareStrings(string(got.Scale), input.Scale.ValueString(), t) + test.CompareStrings(string(got.LoadBalancerSku), input.LoadBalancerSku.ValueString(), t) + test.CompareBools(got.EnableRangerRaz, input.EnableRangerRaz.ValueBool(), t) + test.CompareInt32PointerToTypesInt64(&got.JavaVersion, input.JavaVersion, t) + test.CompareStrings(got.FlexibleServerDelegatedSubnetID, input.FlexibleServerDelegatedSubnetId.ValueString(), t) +} diff --git a/resources/datalake/schema_azure_datalake.go b/resources/datalake/schema_azure_datalake.go index dca7c3e0..b6b4485a 100644 --- a/resources/datalake/schema_azure_datalake.go +++ b/resources/datalake/schema_azure_datalake.go @@ -335,5 +335,17 @@ var azureDatalakeResourceSchema = schema.Schema{ Optional: true, ElementType: types.StringType, }, + "load_balancer_sku": schema.StringAttribute{ + MarkdownDescription: "Represents the Azure load balancer SKU type. The current default is BASIC. To disable the load balancer, use type NONE. Possible values: BASIC, STANDARD, NONE", + Optional: true, + }, + "flexible_server_delegated_subnet_id": schema.StringAttribute{ + MarkdownDescription: "This argument allows you to specify the subnet ID for the subnet within which you want to configure your Azure Flexible Server.", + Optional: true, + }, + "multi_az": schema.BoolAttribute{ + MarkdownDescription: "Creates CDP datalake distributed across multiple availability zones in an Azure region.", + Optional: true, + }, }, } diff --git a/resources/datalake/schema_azure_datalake_test.go b/resources/datalake/schema_azure_datalake_test.go index d3bc0f37..9b0f1f14 100644 --- a/resources/datalake/schema_azure_datalake_test.go +++ b/resources/datalake/schema_azure_datalake_test.go @@ -12,9 +12,10 @@ package datalake import ( "context" + "testing" + "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" - "testing" ) func TestAzureCommonSchemaElementsExist(t *testing.T) { @@ -30,6 +31,27 @@ func TestAzureSpecificElements(t *testing.T) { shouldBeRequired: false, attributeType: schema.StringAttribute{}, }, + { + name: "'load_balancer_sku' should exist", + field: "load_balancer_sku", + computed: false, + shouldBeRequired: false, + attributeType: schema.StringAttribute{}, + }, + { + name: "'flexible_server_delegated_subnet_id' should exist", + field: "flexible_server_delegated_subnet_id", + computed: false, + shouldBeRequired: false, + attributeType: schema.StringAttribute{}, + }, + { + name: "'multi_az' should exist", + field: "multi_az", + computed: false, + shouldBeRequired: false, + attributeType: schema.BoolAttribute{}, + }, } underTestAttributes := createFilledAzureTestObject() diff --git a/utils/test/compare.go b/utils/test/compare.go index 6a7d8acf..321cc11e 100644 --- a/utils/test/compare.go +++ b/utils/test/compare.go @@ -10,7 +10,14 @@ package test -func CompareStrings(actual, expected []string) (unexpected, missing []string) { +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-framework/attr" + "github.com/hashicorp/terraform-plugin-framework/types" +) + +func CompareStringSlices(actual, expected []string) (unexpected, missing []string) { for _, res := range actual { if !containsString(expected, res) { unexpected = append(unexpected, res) @@ -24,6 +31,12 @@ func CompareStrings(actual, expected []string) (unexpected, missing []string) { return } +func CompareStrings(got string, expected string, t *testing.T) { + if got != expected { + t.Errorf("Assertion error! Expected: %s, got: %s", expected, got) + } +} + func containsString(resources []string, target string) bool { for _, res := range resources { if res == target { @@ -40,3 +53,40 @@ func ToStringSliceFunc[T any](elements []T, f func(T) string) []string { } return result } + +func CompareStringValueSlices(got []string, expected []attr.Value, t *testing.T) { + if len(got) != len(expected) { + t.Errorf("Assertion error! Expected length: %d, got length: %d", len(expected), len(got)) + return + } + + for i, exp := range expected { + if got[i] != exp.(types.String).ValueString() { + t.Errorf("Assertion error! Expected: %s, got: %s", expected, got) + } + } +} + +func CompareInt32PointerToTypesInt64(got *int32, expected types.Int64, t *testing.T) { + if *got != *Int64To32Pointer(expected) { + t.Errorf("Assertion error! Expected: %d, got: %d", expected.ValueInt64(), *got) + } +} + +func CompareInts(got int, expected int, t *testing.T) { + if got != expected { + t.Errorf("Assertion error! Expected: %d, got: %d", expected, got) + } +} + +func CompareBools(got bool, expected bool, t *testing.T) { + if got != expected { + t.Errorf("Assertion error! Expected: %t, got: %t", expected, got) + } +} + +func Int64To32Pointer(in types.Int64) *int32 { + n64 := in.ValueInt64() + var n2 = int32(n64) + return &n2 +} diff --git a/utils/utils.go b/utils/utils.go index 3f97d0b4..62f9766b 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -13,9 +13,10 @@ package utils import ( "context" "fmt" - "github.com/hashicorp/terraform-plugin-log/tflog" "time" + "github.com/hashicorp/terraform-plugin-log/tflog" + "github.com/hashicorp/terraform-plugin-framework/datasource" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/types" @@ -128,3 +129,9 @@ func FromSetValueToStringList(tl types.Set) []string { } return res } + +func Int64To32Pointer(in types.Int64) *int32 { + n64 := in.ValueInt64() + var n2 = int32(n64) + return &n2 +}