diff --git a/resources/datahub/common_scheme.go b/resources/datahub/common_scheme.go index 500573ad..120e9760 100644 --- a/resources/datahub/common_scheme.go +++ b/resources/datahub/common_scheme.go @@ -57,18 +57,6 @@ var generalAttributes = map[string]schema.Attribute{ MarkdownDescription: "The name of the cluster.", Required: true, }, - "cluster_template": schema.StringAttribute{ - MarkdownDescription: "The name of the cluster template.", - Required: true, - }, - "cluster_definition": schema.StringAttribute{ - MarkdownDescription: "The name of the cluster definition.", - Required: true, - }, - "environment": schema.StringAttribute{ - MarkdownDescription: "The name of the environment where the cluster will belong to.", - Required: true, - }, "destroy_options": schema.SingleNestedAttribute{ Optional: true, Description: "Cluster deletion options.", diff --git a/resources/datahub/common_scheme_test.go b/resources/datahub/common_scheme_test.go index 4db709bd..53282451 100644 --- a/resources/datahub/common_scheme_test.go +++ b/resources/datahub/common_scheme_test.go @@ -54,24 +54,6 @@ var commonElementCaseSet = []TestCaseStructure{ computed: false, shouldBeRequired: true, }, - { - name: "cluster_template must exist", - field: "cluster_template", - computed: false, - shouldBeRequired: true, - }, - { - name: "cluster_definition must exist", - field: "cluster_definition", - computed: false, - shouldBeRequired: true, - }, - { - name: "environment must exist", - field: "environment", - computed: false, - shouldBeRequired: true, - }, { name: "destroy_options should exist", field: "destroy_options", diff --git a/resources/datahub/converter.go b/resources/datahub/converter.go index 46f0507c..4ca5a3d7 100644 --- a/resources/datahub/converter.go +++ b/resources/datahub/converter.go @@ -19,21 +19,21 @@ import ( datahubmodels "github.com/cloudera/terraform-provider-cdp/cdp-sdk-go/gen/datahub/models" ) -func fromModelToAwsRequest(model datahubResourceModel, ctx context.Context) *datahubmodels.CreateAWSClusterRequest { - debug(ctx, "Conversion from datahubResourceModel to CreateAWSClusterRequest started.") +func fromModelToAwsRequest(model awsDatahubResourceModel, ctx context.Context) *datahubmodels.CreateAWSClusterRequest { + tflog.Debug(ctx, "Conversion from datahubResourceModel to CreateAWSClusterRequest started.") req := datahubmodels.CreateAWSClusterRequest{} req.ClusterName = model.Name.ValueString() req.ClusterTemplate = model.ClusterTemplate.ValueString() req.Environment = model.Environment.ValueString() req.ClusterDefinition = model.ClusterDefinition.ValueString() var igs []*datahubmodels.InstanceGroupRequest - debug(ctx, fmt.Sprintf("%d instance group found in the input model.", len(model.InstanceGroup))) + tflog.Debug(ctx, fmt.Sprintf("%d instance group found in the input model.", len(model.InstanceGroup))) for _, group := range model.InstanceGroup { - debug(ctx, fmt.Sprintf("Converting InstanceGroupRequest: %+v.", group)) + tflog.Debug(ctx, fmt.Sprintf("Converting InstanceGroupRequest: %+v.", group)) var volReqs []*datahubmodels.AttachedVolumeRequest - debug(ctx, fmt.Sprintf("%d attached volume request found in the input model.", len(model.InstanceGroup))) + tflog.Debug(ctx, fmt.Sprintf("%d attached volume request found in the input model.", len(model.InstanceGroup))) for _, vrs := range group.AttachedVolumeConfiguration { - debug(ctx, fmt.Sprintf("Converting AttachedVolumeConfiguration: %+v.", vrs)) + tflog.Debug(ctx, fmt.Sprintf("Converting AttachedVolumeConfiguration: %+v.", vrs)) volReqs = append(volReqs, createAttachedVolumeRequest(vrs)) } var igRecipes []string @@ -58,25 +58,25 @@ func fromModelToAwsRequest(model datahubResourceModel, ctx context.Context) *dat igs = append(igs, ig) } req.InstanceGroups = igs - debug(ctx, "Conversion from datahubResourceModel to CreateAWSClusterRequest has finished.") + tflog.Debug(ctx, fmt.Sprintf("Conversion from datahubResourceModel to CreateAWSClusterRequest has finished with request: %+v.", req)) return &req } func fromModelToGcpRequest(model gcpDatahubResourceModel, ctx context.Context) *datahubmodels.CreateGCPClusterRequest { - debug(ctx, "Conversion from gcpDatahubResourceModel to CreateGCPClusterRequest started.") + tflog.Debug(ctx, "Conversion from gcpDatahubResourceModel to CreateGCPClusterRequest started.") req := datahubmodels.CreateGCPClusterRequest{} req.ClusterName = model.Name.ValueString() req.EnvironmentName = model.Environment.ValueString() req.ClusterTemplateName = model.ClusterTemplate.ValueString() req.ClusterDefinitionName = model.ClusterDefinition.ValueString() var igs []*datahubmodels.GCPInstanceGroupRequest - debug(ctx, fmt.Sprintf("%d instance group found in the input model.", len(model.InstanceGroup))) + tflog.Debug(ctx, fmt.Sprintf("%d instance group found in the input model.", len(model.InstanceGroup))) for _, group := range model.InstanceGroup { - debug(ctx, fmt.Sprintf("Converting GCPInstanceGroupRequest: %+v.", group)) + tflog.Debug(ctx, fmt.Sprintf("Converting GCPInstanceGroupRequest: %+v.", group)) var volReqs []*datahubmodels.AttachedVolumeRequest - debug(ctx, fmt.Sprintf("%d attached volume request found in the input model.", len(model.InstanceGroup))) + tflog.Debug(ctx, fmt.Sprintf("%d attached volume request found in the input model.", len(model.InstanceGroup))) for _, vrs := range group.AttachedVolumeConfiguration { - debug(ctx, fmt.Sprintf("Converting AttachedVolumeConfiguration: %+v.", vrs)) + tflog.Debug(ctx, fmt.Sprintf("Converting AttachedVolumeConfiguration: %+v.", vrs)) volReqs = append(volReqs, createAttachedVolumeRequest(vrs)) } var igRecipes []string @@ -99,12 +99,12 @@ func fromModelToGcpRequest(model gcpDatahubResourceModel, ctx context.Context) * igs = append(igs, ig) } req.InstanceGroups = igs - debug(ctx, "Conversion from gcpDatahubResourceModel to CreateGCPClusterRequest has finished.") + tflog.Debug(ctx, "Conversion from gcpDatahubResourceModel to CreateGCPClusterRequest has finished.") return &req } -func fromModelToAzureRequest(model datahubResourceModel, ctx context.Context) *datahubmodels.CreateAzureClusterRequest { - debug(ctx, "Conversion from datahubResourceModel to CreateAzureClusterRequest started.") +func fromModelToAzureRequest(model azureDatahubResourceModel, ctx context.Context) *datahubmodels.CreateAzureClusterRequest { + tflog.Debug(ctx, "Conversion from datahubResourceModel to CreateAzureClusterRequest started.") req := datahubmodels.CreateAzureClusterRequest{} req.DatabaseType = model.DatabaseType.ValueString() req.ClusterName = model.Name.ValueString() @@ -112,13 +112,13 @@ func fromModelToAzureRequest(model datahubResourceModel, ctx context.Context) *d req.EnvironmentName = model.Environment.ValueString() req.ClusterDefinitionName = model.ClusterDefinition.ValueString() var igs []*datahubmodels.AzureInstanceGroupRequest - debug(ctx, fmt.Sprintf("%d instance group found in the input model.", len(model.InstanceGroup))) + tflog.Debug(ctx, fmt.Sprintf("%d instance group found in the input model.", len(model.InstanceGroup))) for _, group := range model.InstanceGroup { - debug(ctx, fmt.Sprintf("Converting InstanceGroupRequest: %+v.", group)) + tflog.Debug(ctx, fmt.Sprintf("Converting InstanceGroupRequest: %+v.", group)) var volReqs []*datahubmodels.AttachedVolumeRequest - debug(ctx, fmt.Sprintf("%d attached volume request found in the input model.", len(model.InstanceGroup))) + tflog.Debug(ctx, fmt.Sprintf("%d attached volume request found in the input model.", len(model.InstanceGroup))) for _, vrs := range group.AttachedVolumeConfiguration { - debug(ctx, fmt.Sprintf("Converting AttachedVolumeConfiguration: %+v.", vrs)) + tflog.Debug(ctx, fmt.Sprintf("Converting AttachedVolumeConfiguration: %+v.", vrs)) volReqs = append(volReqs, createAttachedVolumeRequest(vrs)) } var igRecipes []string @@ -162,9 +162,3 @@ func int64To32Pointer(in types.Int64) *int32 { var n2 = int32(n64) return &n2 } - -func debug(ctx context.Context, msg string) { - if ctx != nil { - tflog.Debug(ctx, msg) - } -} diff --git a/resources/datahub/converter_test.go b/resources/datahub/converter_test.go index 8362c4a1..f43fc9eb 100644 --- a/resources/datahub/converter_test.go +++ b/resources/datahub/converter_test.go @@ -11,17 +11,18 @@ package datahub import ( + "context" "github.com/hashicorp/terraform-plugin-framework/types" "testing" ) func TestFromModelToRequestBasicFields(t *testing.T) { - input := datahubResourceModel{ + input := awsDatahubResourceModel{ Name: types.StringValue("someClusterName"), Environment: types.StringValue("someEnvironment"), ClusterTemplate: types.StringValue("someClusterTemplateNameOrCRN"), } - got := fromModelToAwsRequest(input, nil) + got := fromModelToAwsRequest(input, context.TODO()) compareStrings(got.ClusterName, input.Name.ValueString(), t) compareStrings(got.Environment, input.Environment.ValueString(), t) @@ -31,9 +32,9 @@ func TestFromModelToRequestBasicFields(t *testing.T) { func TestFromModelToRequestRecipe(t *testing.T) { recipes := []types.String{types.StringValue("recipe1"), types.StringValue("recipe2")} igs := []InstanceGroup{{Recipes: recipes}} - input := datahubResourceModel{InstanceGroup: igs} + input := awsDatahubResourceModel{InstanceGroup: igs} - got := fromModelToAwsRequest(input, nil) + 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) @@ -58,9 +59,9 @@ func TestFromModelToRequestAttachedVolumeConfiguration(t *testing.T) { VolumeType: types.StringValue("ephemeral"), }} igs := []InstanceGroup{{AttachedVolumeConfiguration: avcs}} - input := datahubResourceModel{InstanceGroup: igs} + input := awsDatahubResourceModel{InstanceGroup: igs} - got := fromModelToAwsRequest(input, nil) + got := fromModelToAwsRequest(input, context.TODO()) compareInts(len(got.InstanceGroups), len(input.InstanceGroup), t) compareInts(len(got.InstanceGroups[0].AttachedVolumeConfiguration), len(avcs), t) @@ -81,9 +82,9 @@ func TestFromModelToRequestInstanceGroups(t *testing.T) { RecoveryMode: types.StringValue("MANUAL"), }} - input := datahubResourceModel{InstanceGroup: igs} + input := awsDatahubResourceModel{InstanceGroup: igs} - got := fromModelToAwsRequest(input, nil) + got := fromModelToAwsRequest(input, context.TODO()) compareInts(len(got.InstanceGroups), len(igs), t) resultIg := got.InstanceGroups[0] @@ -99,9 +100,9 @@ func TestFromModelToRequestVolumeEncryption(t *testing.T) { VolumeEncryption: VolumeEncryption{Encryption: types.BoolValue(true)}, }} - input := datahubResourceModel{InstanceGroup: igs} + input := awsDatahubResourceModel{InstanceGroup: igs} - got := fromModelToAwsRequest(input, nil) + got := fromModelToAwsRequest(input, context.TODO()) compareInts(len(got.InstanceGroups), len(igs), t) resultVolumeEncryption := got.InstanceGroups[0].VolumeEncryption @@ -113,8 +114,8 @@ func TestFromModelToRequestVolumeEncryption(t *testing.T) { } func TestFromModelToRequestClusterDefinition(t *testing.T) { - input := datahubResourceModel{ClusterDefinition: types.StringValue("SomeClusterDef")} - got := fromModelToAwsRequest(input, nil) + input := awsDatahubResourceModel{ClusterDefinition: types.StringValue("SomeClusterDef")} + got := fromModelToAwsRequest(input, context.TODO()) compareStrings(got.ClusterDefinition, input.ClusterDefinition.ValueString(), t) } @@ -125,7 +126,7 @@ func TestFromModelToGcpRequestBasicFields(t *testing.T) { Environment: types.StringValue("someEnvironment"), ClusterTemplate: types.StringValue("someClusterTemplateNameOrCRN"), } - got := fromModelToGcpRequest(input, nil) + got := fromModelToGcpRequest(input, context.TODO()) compareStrings(got.ClusterName, input.Name.ValueString(), t) compareStrings(got.EnvironmentName, input.Environment.ValueString(), t) @@ -137,7 +138,7 @@ func TestFromModelToGcpRequestRecipe(t *testing.T) { igs := []GcpInstanceGroup{{Recipes: recipes}} input := gcpDatahubResourceModel{InstanceGroup: igs} - got := fromModelToGcpRequest(input, nil) + 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) @@ -164,7 +165,7 @@ func TestFromModelToGcpRequestAttachedVolumeConfiguration(t *testing.T) { igs := []GcpInstanceGroup{{AttachedVolumeConfiguration: avcs}} input := gcpDatahubResourceModel{InstanceGroup: igs} - got := fromModelToGcpRequest(input, nil) + got := fromModelToGcpRequest(input, context.TODO()) compareInts(len(got.InstanceGroups), len(input.InstanceGroup), t) compareInts(len(got.InstanceGroups[0].AttachedVolumeConfiguration), len(avcs), t) @@ -187,7 +188,7 @@ func TestFromModelToGcpRequestInstanceGroups(t *testing.T) { input := gcpDatahubResourceModel{InstanceGroup: igs} - got := fromModelToGcpRequest(input, nil) + got := fromModelToGcpRequest(input, context.TODO()) compareInts(len(got.InstanceGroups), len(igs), t) resultIg := got.InstanceGroups[0] @@ -200,18 +201,18 @@ func TestFromModelToGcpRequestInstanceGroups(t *testing.T) { func TestFromModelToGcpRequestClusterDefinition(t *testing.T) { input := gcpDatahubResourceModel{ClusterDefinition: types.StringValue("SomeClusterDef")} - got := fromModelToGcpRequest(input, nil) + got := fromModelToGcpRequest(input, context.TODO()) compareStrings(got.ClusterDefinitionName, input.ClusterDefinition.ValueString(), t) } func TestFromModelToAzureRequestBasicFields(t *testing.T) { - input := datahubResourceModel{ + input := azureDatahubResourceModel{ Name: types.StringValue("someClusterName"), Environment: types.StringValue("someEnvironment"), ClusterTemplate: types.StringValue("someClusterTemplateNameOrCRN"), } - got := fromModelToAzureRequest(input, nil) + got := fromModelToAzureRequest(input, context.TODO()) compareStrings(got.ClusterName, input.Name.ValueString(), t) compareStrings(got.EnvironmentName, input.Environment.ValueString(), t) @@ -221,9 +222,9 @@ func TestFromModelToAzureRequestBasicFields(t *testing.T) { func TestFromModelToAzureRequestRecipe(t *testing.T) { recipes := []types.String{types.StringValue("recipe1"), types.StringValue("recipe2")} igs := []InstanceGroup{{Recipes: recipes}} - input := datahubResourceModel{InstanceGroup: igs} + input := azureDatahubResourceModel{InstanceGroup: igs} - got := fromModelToAzureRequest(input, nil) + 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) @@ -248,9 +249,9 @@ func TestFromModelToAzureRequestAttachedVolumeConfiguration(t *testing.T) { VolumeType: types.StringValue("ephemeral"), }} igs := []InstanceGroup{{AttachedVolumeConfiguration: avcs}} - input := datahubResourceModel{InstanceGroup: igs} + input := azureDatahubResourceModel{InstanceGroup: igs} - got := fromModelToAzureRequest(input, nil) + got := fromModelToAzureRequest(input, context.TODO()) compareInts(len(got.InstanceGroups), len(input.InstanceGroup), t) compareInts(len(got.InstanceGroups[0].AttachedVolumeConfiguration), len(avcs), t) @@ -271,9 +272,9 @@ func TestFromModelToAzureRequestInstanceGroups(t *testing.T) { RecoveryMode: types.StringValue("MANUAL"), }} - input := datahubResourceModel{InstanceGroup: igs} + input := azureDatahubResourceModel{InstanceGroup: igs} - got := fromModelToAzureRequest(input, nil) + got := fromModelToAzureRequest(input, context.TODO()) compareInts(len(got.InstanceGroups), len(igs), t) resultIg := got.InstanceGroups[0] @@ -285,8 +286,8 @@ func TestFromModelToAzureRequestInstanceGroups(t *testing.T) { } func TestFromModelToAzureRequestClusterDefinition(t *testing.T) { - input := datahubResourceModel{ClusterDefinition: types.StringValue("SomeClusterDef")} - got := fromModelToAzureRequest(input, nil) + input := azureDatahubResourceModel{ClusterDefinition: types.StringValue("SomeClusterDef")} + got := fromModelToAzureRequest(input, context.TODO()) compareStrings(got.ClusterDefinitionName, input.ClusterDefinition.ValueString(), t) } diff --git a/resources/datahub/model_aws_datahub.go b/resources/datahub/model_aws_datahub.go new file mode 100644 index 00000000..84ff7574 --- /dev/null +++ b/resources/datahub/model_aws_datahub.go @@ -0,0 +1,34 @@ +// Copyright 2023 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 datahub + +import ( + "github.com/hashicorp/terraform-plugin-framework/types" + + "github.com/cloudera/terraform-provider-cdp/utils" +) + +type awsDatahubResourceModel struct { + ID types.String `tfsdk:"id"` + Crn types.String `tfsdk:"crn"` + Name types.String `tfsdk:"name"` + Status types.String `tfsdk:"status"` + InstanceGroup []InstanceGroup `tfsdk:"instance_group"` + PollingOptions *utils.PollingOptions `tfsdk:"polling_options"` + DestroyOptions *DestroyOptions `tfsdk:"destroy_options"` + ClusterDefinition types.String `tfsdk:"cluster_definition"` + ClusterTemplate types.String `tfsdk:"cluster_template"` + Environment types.String `tfsdk:"environment"` +} + +func (d *awsDatahubResourceModel) forceDeleteRequested() bool { + return d.DestroyOptions != nil && !d.DestroyOptions.ForceDeleteCluster.IsNull() && d.DestroyOptions.ForceDeleteCluster.ValueBool() +} diff --git a/resources/datahub/model_azure_datahub.go b/resources/datahub/model_azure_datahub.go new file mode 100644 index 00000000..d55e4bcc --- /dev/null +++ b/resources/datahub/model_azure_datahub.go @@ -0,0 +1,35 @@ +// Copyright 2023 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 datahub + +import ( + "github.com/hashicorp/terraform-plugin-framework/types" + + "github.com/cloudera/terraform-provider-cdp/utils" +) + +type azureDatahubResourceModel struct { + ID types.String `tfsdk:"id"` + Crn types.String `tfsdk:"crn"` + Name types.String `tfsdk:"name"` + Status types.String `tfsdk:"status"` + InstanceGroup []InstanceGroup `tfsdk:"instance_group"` + PollingOptions *utils.PollingOptions `tfsdk:"polling_options"` + DestroyOptions *DestroyOptions `tfsdk:"destroy_options"` + Environment types.String `tfsdk:"environment"` + DatabaseType types.String `tfsdk:"database_type"` + ClusterTemplate types.String `tfsdk:"cluster_template"` + ClusterDefinition types.String `tfsdk:"cluster_definition"` +} + +func (d *azureDatahubResourceModel) forceDeleteRequested() bool { + return d.DestroyOptions != nil && !d.DestroyOptions.ForceDeleteCluster.IsNull() && d.DestroyOptions.ForceDeleteCluster.ValueBool() +} diff --git a/resources/datahub/model_datahub.go b/resources/datahub/model_datahub.go index 55ca6ad8..0d860174 100644 --- a/resources/datahub/model_datahub.go +++ b/resources/datahub/model_datahub.go @@ -12,27 +12,8 @@ package datahub import ( "github.com/hashicorp/terraform-plugin-framework/types" - - "github.com/cloudera/terraform-provider-cdp/utils" ) -type datahubResourceModel struct { - ID types.String `tfsdk:"id"` - Crn types.String `tfsdk:"crn"` - Name types.String `tfsdk:"name"` - Status types.String `tfsdk:"status"` - Environment types.String `tfsdk:"environment"` - DatabaseType types.String `tfsdk:"database_type"` - GcpEnvironment types.String `tfsdk:"environment_name"` - InstanceGroup []InstanceGroup `tfsdk:"instance_group"` - PollingOptions *utils.PollingOptions `tfsdk:"polling_options"` - DestroyOptions *DestroyOptions `tfsdk:"destroy_options"` - ClusterTemplate types.String `tfsdk:"cluster_template"` - GcpClusterTemplate types.String `tfsdk:"cluster_template_name"` - ClusterDefinition types.String `tfsdk:"cluster_definition"` - GcpClusterDefinition types.String `tfsdk:"cluster_definition_name"` -} - type InstanceGroup struct { NodeCount types.Int64 `tfsdk:"node_count"` InstanceGroupName types.String `tfsdk:"instance_group_name"` @@ -58,7 +39,3 @@ type VolumeEncryption struct { type DestroyOptions struct { ForceDeleteCluster types.Bool `tfsdk:"force_delete_cluster"` } - -func (d *datahubResourceModel) forceDeleteRequested() bool { - return d.DestroyOptions != nil && !d.DestroyOptions.ForceDeleteCluster.IsNull() && d.DestroyOptions.ForceDeleteCluster.ValueBool() -} diff --git a/resources/datahub/model_datahub_test.go b/resources/datahub/model_datahub_test.go index ca042a8b..fcda5d8b 100644 --- a/resources/datahub/model_datahub_test.go +++ b/resources/datahub/model_datahub_test.go @@ -15,30 +15,66 @@ import ( "testing" ) -func TestForceDeleteRequested(t *testing.T) { +func TestForceDeleteRequestedForAws(t *testing.T) { tests := []struct { name string - model *datahubResourceModel + model *awsDatahubResourceModel expectedResult bool }{ { name: "when DestroyOptions nil", - model: &datahubResourceModel{DestroyOptions: nil}, + model: &awsDatahubResourceModel{DestroyOptions: nil}, expectedResult: false, }, { name: "when DestroyOptions not nil but ForceDeleteCluster is", - model: &datahubResourceModel{DestroyOptions: &DestroyOptions{ForceDeleteCluster: types.BoolNull()}}, + model: &awsDatahubResourceModel{DestroyOptions: &DestroyOptions{ForceDeleteCluster: types.BoolNull()}}, expectedResult: false, }, { name: "when neither DestroyOptions or ForceDeleteCluster are nil but ForceDeleteCluster is false", - model: &datahubResourceModel{DestroyOptions: &DestroyOptions{ForceDeleteCluster: types.BoolValue(false)}}, + model: &awsDatahubResourceModel{DestroyOptions: &DestroyOptions{ForceDeleteCluster: types.BoolValue(false)}}, expectedResult: false, }, { name: "when ForceDeleteCluster is true", - model: &datahubResourceModel{DestroyOptions: &DestroyOptions{ForceDeleteCluster: types.BoolValue(true)}}, + model: &awsDatahubResourceModel{DestroyOptions: &DestroyOptions{ForceDeleteCluster: types.BoolValue(true)}}, + expectedResult: true, + }, + } + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + if test.model.forceDeleteRequested() != test.expectedResult { + t.Errorf("Did not get the expected output! Expected: %t, got: %t", test.expectedResult, test.model.forceDeleteRequested()) + } + }) + } +} + +func TestForceDeleteRequestedForAzure(t *testing.T) { + tests := []struct { + name string + model *azureDatahubResourceModel + expectedResult bool + }{ + { + name: "when DestroyOptions nil", + model: &azureDatahubResourceModel{DestroyOptions: nil}, + expectedResult: false, + }, + { + name: "when DestroyOptions not nil but ForceDeleteCluster is", + model: &azureDatahubResourceModel{DestroyOptions: &DestroyOptions{ForceDeleteCluster: types.BoolNull()}}, + expectedResult: false, + }, + { + name: "when neither DestroyOptions or ForceDeleteCluster are nil but ForceDeleteCluster is false", + model: &azureDatahubResourceModel{DestroyOptions: &DestroyOptions{ForceDeleteCluster: types.BoolValue(false)}}, + expectedResult: false, + }, + { + name: "when ForceDeleteCluster is true", + model: &azureDatahubResourceModel{DestroyOptions: &DestroyOptions{ForceDeleteCluster: types.BoolValue(true)}}, expectedResult: true, }, } diff --git a/resources/datahub/gcp_model_datahub.go b/resources/datahub/model_gcp_datahub.go similarity index 100% rename from resources/datahub/gcp_model_datahub.go rename to resources/datahub/model_gcp_datahub.go diff --git a/resources/datahub/gcp_model_datahub_test.go b/resources/datahub/model_gcp_datahub_test.go similarity index 100% rename from resources/datahub/gcp_model_datahub_test.go rename to resources/datahub/model_gcp_datahub_test.go diff --git a/resources/datahub/resource_aws_datahub.go b/resources/datahub/resource_aws_datahub.go index e3dfdc2f..bb153293 100644 --- a/resources/datahub/resource_aws_datahub.go +++ b/resources/datahub/resource_aws_datahub.go @@ -45,17 +45,23 @@ func (r *awsDatahubResource) Configure(_ context.Context, req resource.Configure func (r *awsDatahubResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { tflog.Info(ctx, "AWS cluster creation process requested.") - var data datahubResourceModel + var data awsDatahubResourceModel + tflog.Info(ctx, fmt.Sprintf("Creating AWS Datahub with name: %s", data.Name.ValueString())) diags := req.Plan.Get(ctx, &data) + tflog.Info(ctx, fmt.Sprintf("Datahub resource model: %+v", data)) resp.Diagnostics.Append(diags...) + tflog.Info(ctx, fmt.Sprintf("Diags: %+v", resp.Diagnostics)) if resp.Diagnostics.HasError() { + tflog.Warn(ctx, "Datahub resource model has error, stopping the creation process.") return } params := operations.NewCreateAWSClusterParamsWithContext(ctx) params.WithInput(fromModelToAwsRequest(data, ctx)) + tflog.Info(ctx, fmt.Sprintf("Sending create request for AWS Datahub with name: %s", data.Name.ValueString())) res, err := r.client.Datahub.Operations.CreateAWSCluster(params) + tflog.Info(ctx, fmt.Sprintf("Create request for AWS Datahub with name: %s has been sent with the result of: %+v", data.Name.ValueString(), res)) if err != nil { utils.AddDatahubDiagnosticsError(err, &resp.Diagnostics, "create AWS Datahub") return @@ -88,7 +94,7 @@ func (r *awsDatahubResource) Create(ctx context.Context, req resource.CreateRequ } func (r *awsDatahubResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { - var state datahubResourceModel + var state awsDatahubResourceModel diags := req.State.Get(ctx, &state) resp.Diagnostics.Append(diags...) if resp.Diagnostics.HasError() { @@ -130,7 +136,7 @@ func (r *awsDatahubResource) Update(ctx context.Context, _ resource.UpdateReques } func (r *awsDatahubResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { - var state datahubResourceModel + var state awsDatahubResourceModel diags := req.State.Get(ctx, &state) resp.Diagnostics.Append(diags...) if resp.Diagnostics.HasError() { diff --git a/resources/datahub/resource_azure_datahub.go b/resources/datahub/resource_azure_datahub.go index c6370be4..cf728a14 100644 --- a/resources/datahub/resource_azure_datahub.go +++ b/resources/datahub/resource_azure_datahub.go @@ -46,7 +46,7 @@ func (r *azureDatahubResource) Configure(_ context.Context, req resource.Configu func (r *azureDatahubResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { tflog.Info(ctx, "Azure cluster creation process requested.") - var data datahubResourceModel + var data azureDatahubResourceModel diags := req.Plan.Get(ctx, &data) resp.Diagnostics.Append(diags...) if resp.Diagnostics.HasError() { @@ -89,7 +89,7 @@ func (r *azureDatahubResource) Create(ctx context.Context, req resource.CreateRe } func (r *azureDatahubResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { - var state datahubResourceModel + var state azureDatahubResourceModel diags := req.State.Get(ctx, &state) resp.Diagnostics.Append(diags...) if resp.Diagnostics.HasError() { @@ -131,7 +131,7 @@ func (r *azureDatahubResource) Update(ctx context.Context, _ resource.UpdateRequ } func (r *azureDatahubResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { - var state datahubResourceModel + var state azureDatahubResourceModel diags := req.State.Get(ctx, &state) resp.Diagnostics.Append(diags...) if resp.Diagnostics.HasError() { diff --git a/resources/datahub/schema_aws_datahub.go b/resources/datahub/schema_aws_datahub.go index b7ffc239..06c57e1a 100644 --- a/resources/datahub/schema_aws_datahub.go +++ b/resources/datahub/schema_aws_datahub.go @@ -22,6 +22,20 @@ func (r *awsDatahubResource) Schema(_ context.Context, _ resource.SchemaRequest, attr := map[string]schema.Attribute{} utils.Append(attr, generalAttributes) utils.Append(attr, instanceGroupSchemaAttributes) + utils.Append(attr, map[string]schema.Attribute{ + "cluster_template": schema.StringAttribute{ + MarkdownDescription: "The name of the cluster template.", + Required: true, + }, + "cluster_definition": schema.StringAttribute{ + MarkdownDescription: "The name of the cluster definition.", + Required: true, + }, + "environment": schema.StringAttribute{ + MarkdownDescription: "The name of the environment where the cluster will belong to.", + Required: true, + }, + }) resp.Schema = schema.Schema{ MarkdownDescription: "Creates an AWS Data hub cluster.", Attributes: attr, diff --git a/resources/datahub/schema_azure_datahub.go b/resources/datahub/schema_azure_datahub.go index db1a45b6..dedca533 100644 --- a/resources/datahub/schema_azure_datahub.go +++ b/resources/datahub/schema_azure_datahub.go @@ -25,6 +25,18 @@ func (r *azureDatahubResource) Schema(_ context.Context, _ resource.SchemaReques utils.Append(attr, generalAttributes) utils.Append(attr, instanceGroupSchemaAttributes) utils.Append(attr, map[string]schema.Attribute{ + "cluster_template": schema.StringAttribute{ + MarkdownDescription: "The name of the cluster template.", + Required: true, + }, + "cluster_definition": schema.StringAttribute{ + MarkdownDescription: "The name of the cluster definition.", + Required: true, + }, + "environment": schema.StringAttribute{ + MarkdownDescription: "The name of the environment where the cluster will belong to.", + Required: true, + }, "database_type": schema.StringAttribute{ Optional: true, Computed: false, diff --git a/resources/datalake/common_schema.go b/resources/datalake/common_scheme.go similarity index 100% rename from resources/datalake/common_schema.go rename to resources/datalake/common_scheme.go diff --git a/resources/datalake/common_schema_test.go b/resources/datalake/common_scheme_test.go similarity index 100% rename from resources/datalake/common_schema_test.go rename to resources/datalake/common_scheme_test.go diff --git a/resources/datalake/resource_aws_datalake.go b/resources/datalake/resource_aws_datalake.go index 7329325e..98a3ccfb 100644 --- a/resources/datalake/resource_aws_datalake.go +++ b/resources/datalake/resource_aws_datalake.go @@ -134,7 +134,7 @@ func (r *awsDatalakeResource) Create(ctx context.Context, req resource.CreateReq return } - if !state.PollingOptions.Async.ValueBool() { + if state.PollingOptions != nil && !state.PollingOptions.Async.ValueBool() { if err := waitForDatalakeToBeRunning(ctx, state.DatalakeName.ValueString(), time.Hour, r.client.Datalake, state.PollingOptions); err != nil { utils.AddDatalakeDiagnosticsError(err, &resp.Diagnostics, "create AWS Datalake") return @@ -407,7 +407,7 @@ func (r *awsDatalakeResource) Delete(ctx context.Context, req resource.DeleteReq return } - if !state.PollingOptions.Async.ValueBool() { + if state.PollingOptions != nil && !state.PollingOptions.Async.ValueBool() { if err := waitForDatalakeToBeDeleted(ctx, state.DatalakeName.ValueString(), time.Hour, r.client.Datalake, state.PollingOptions); err != nil { utils.AddDatalakeDiagnosticsError(err, &resp.Diagnostics, "delete AWS Datalake") return diff --git a/resources/datalake/resource_azure_datalake.go b/resources/datalake/resource_azure_datalake.go index dfcbf8da..b6429580 100644 --- a/resources/datalake/resource_azure_datalake.go +++ b/resources/datalake/resource_azure_datalake.go @@ -123,7 +123,7 @@ func (r *azureDatalakeResource) Create(ctx context.Context, req resource.CreateR return } - if !state.PollingOptions.Async.ValueBool() { + if state.PollingOptions != nil && !state.PollingOptions.Async.ValueBool() { if err := waitForDatalakeToBeRunning(ctx, state.DatalakeName.ValueString(), time.Hour, r.client.Datalake, state.PollingOptions); err != nil { utils.AddDatalakeDiagnosticsError(err, &resp.Diagnostics, "create AWS Datalake") return @@ -363,7 +363,7 @@ func (r *azureDatalakeResource) Delete(ctx context.Context, req resource.DeleteR return } - if !state.PollingOptions.Async.ValueBool() { + if state.PollingOptions != nil && !state.PollingOptions.Async.ValueBool() { if err := waitForDatalakeToBeDeleted(ctx, state.DatalakeName.ValueString(), time.Hour, r.client.Datalake, state.PollingOptions); err != nil { utils.AddDatalakeDiagnosticsError(err, &resp.Diagnostics, "delete Azure Datalake") return diff --git a/resources/datalake/resource_gcp_datalake.go b/resources/datalake/resource_gcp_datalake.go index 2d309c93..0ae7a4c9 100644 --- a/resources/datalake/resource_gcp_datalake.go +++ b/resources/datalake/resource_gcp_datalake.go @@ -71,7 +71,7 @@ func (r *gcpDatalakeResource) Create(ctx context.Context, req resource.CreateReq return } - if !state.PollingOptions.Async.ValueBool() { + if state.PollingOptions != nil && !state.PollingOptions.Async.ValueBool() { if err := waitForDatalakeToBeRunning(ctx, state.DatalakeName.ValueString(), time.Hour, r.client.Datalake, state.PollingOptions); err != nil { utils.AddDatalakeDiagnosticsError(err, &resp.Diagnostics, "create AWS Datalake") return @@ -165,7 +165,7 @@ func (r *gcpDatalakeResource) Delete(ctx context.Context, req resource.DeleteReq return } - if !state.PollingOptions.Async.ValueBool() { + if state.PollingOptions != nil && !state.PollingOptions.Async.ValueBool() { if err := waitForDatalakeToBeDeleted(ctx, state.DatalakeName.ValueString(), time.Hour, r.client.Datalake, state.PollingOptions); err != nil { utils.AddDatalakeDiagnosticsError(err, &resp.Diagnostics, "delete GCP Datalake") return diff --git a/resources/datalake/schema_azure_datalake.go b/resources/datalake/schema_azure_datalake.go index c3c9cb07..653aba57 100644 --- a/resources/datalake/schema_azure_datalake.go +++ b/resources/datalake/schema_azure_datalake.go @@ -271,7 +271,7 @@ var azureDatalakeResourceSchema = schema.Schema{ "java_version": schema.Int64Attribute{ Optional: true, }, - "database_type": schema.Int64Attribute{ + "database_type": schema.StringAttribute{ MarkdownDescription: "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.", Optional: true, },