diff --git a/resources/datalake/common_schema.go b/resources/datalake/common_schema.go index b48e9fc4..228931b8 100644 --- a/resources/datalake/common_schema.go +++ b/resources/datalake/common_schema.go @@ -101,10 +101,13 @@ var generalAttributes = map[string]schema.Attribute{ NestedObject: schema.NestedAttributeObject{ Attributes: map[string]schema.Attribute{ "instance_group_name": schema.StringAttribute{ - Required: true, + MarkdownDescription: "The name of the designated instance group.", + Required: true, }, - "recipe_names": schema.SetNestedAttribute{ - Required: true, + "recipe_names": schema.SetAttribute{ + MarkdownDescription: "The set of recipe names that are going to be applied on the given instance group.", + ElementType: types.StringType, + Required: true, }, }, }, diff --git a/resources/datalake/common_schema_test.go b/resources/datalake/common_schema_test.go index de7d73be..918bfdbb 100644 --- a/resources/datalake/common_schema_test.go +++ b/resources/datalake/common_schema_test.go @@ -11,6 +11,7 @@ package datalake import ( + "reflect" "testing" "github.com/hashicorp/terraform-plugin-framework/resource/schema" @@ -21,112 +22,132 @@ type TestCaseStructure struct { field string computed bool shouldBeRequired bool + attributeType schema.Attribute } -var commonElementCaseSet = []TestCaseStructure{ - { - name: "'id' field must exist", - field: "id", - computed: true, - shouldBeRequired: false, - }, - { - name: "'polling_options' should exist", - field: "polling_options", - computed: false, - shouldBeRequired: false, - }, - { - name: "'creation_date' should exist", - field: "creation_date", - computed: true, - shouldBeRequired: false, - }, - { - name: "'crn' should exist", - field: "crn", - computed: true, - shouldBeRequired: false, - }, - { - name: "'datalake_name' must exist", - field: "datalake_name", - computed: false, - shouldBeRequired: true, - }, - { - name: "'enable_ranger_raz' should exist", - field: "enable_ranger_raz", - computed: true, - shouldBeRequired: false, - }, - { - name: "'environment_crn' should exist", - field: "environment_crn", - computed: true, - shouldBeRequired: false, - }, - { - name: "'environment_name' must exist", - field: "environment_name", - computed: false, - shouldBeRequired: true, - }, - { - name: "'image' should exist", - field: "image", - computed: false, - shouldBeRequired: false, - }, - { - name: "'java_version' should exist", - field: "java_version", - computed: false, - shouldBeRequired: false, - }, - { - name: "'recipes' should exist", - field: "recipes", - computed: false, - shouldBeRequired: false, - }, - { - name: "'runtime' should exist", - field: "runtime", - computed: false, - shouldBeRequired: false, - }, - { - name: "'scale' should exist", - field: "scale", - computed: true, - shouldBeRequired: false, - }, - { - name: "'status' should exist", - field: "status", - computed: true, - shouldBeRequired: false, - }, - { - name: "'status_reason' should exist", - field: "status_reason", - computed: true, - shouldBeRequired: false, - }, - { - name: "'multi_az' should exist", - field: "multi_az", - computed: true, - shouldBeRequired: false, - }, - { - name: "'tags' should exist", - field: "tags", - computed: false, - shouldBeRequired: false, - }, -} +var ( + commonElementCaseSet = []TestCaseStructure{ + { + name: "'id' field must exist", + field: "id", + computed: true, + shouldBeRequired: false, + attributeType: schema.StringAttribute{}, + }, + { + name: "'polling_options' should exist", + field: "polling_options", + computed: false, + shouldBeRequired: false, + attributeType: schema.SingleNestedAttribute{}, + }, + { + name: "'creation_date' should exist", + field: "creation_date", + computed: true, + shouldBeRequired: false, + attributeType: schema.StringAttribute{}, + }, + { + name: "'crn' should exist", + field: "crn", + computed: true, + shouldBeRequired: false, + attributeType: schema.StringAttribute{}, + }, + { + name: "'datalake_name' must exist", + field: "datalake_name", + computed: false, + shouldBeRequired: true, + attributeType: schema.StringAttribute{}, + }, + { + name: "'enable_ranger_raz' should exist", + field: "enable_ranger_raz", + computed: true, + shouldBeRequired: false, + attributeType: schema.BoolAttribute{}, + }, + { + name: "'environment_crn' should exist", + field: "environment_crn", + computed: true, + shouldBeRequired: false, + attributeType: schema.StringAttribute{}, + }, + { + name: "'environment_name' must exist", + field: "environment_name", + computed: false, + shouldBeRequired: true, + attributeType: schema.StringAttribute{}, + }, + { + name: "'image' should exist", + field: "image", + computed: false, + shouldBeRequired: false, + attributeType: schema.SingleNestedAttribute{}, + }, + { + name: "'java_version' should exist", + field: "java_version", + computed: false, + shouldBeRequired: false, + attributeType: schema.Int64Attribute{}, + }, + { + name: "'recipes' should exist", + field: "recipes", + computed: false, + shouldBeRequired: false, + attributeType: schema.SetNestedAttribute{}, + }, + { + name: "'runtime' should exist", + field: "runtime", + computed: false, + shouldBeRequired: false, + attributeType: schema.StringAttribute{}, + }, + { + name: "'scale' should exist", + field: "scale", + computed: true, + shouldBeRequired: false, + attributeType: schema.StringAttribute{}, + }, + { + name: "'status' should exist", + field: "status", + computed: true, + shouldBeRequired: false, + attributeType: schema.StringAttribute{}, + }, + { + name: "'status_reason' should exist", + field: "status_reason", + computed: true, + shouldBeRequired: false, + attributeType: schema.StringAttribute{}, + }, + { + name: "'multi_az' should exist", + field: "multi_az", + computed: true, + shouldBeRequired: false, + attributeType: schema.BoolAttribute{}, + }, + { + name: "'tags' should exist", + field: "tags", + computed: false, + shouldBeRequired: false, + attributeType: schema.MapAttribute{}, + }, + } +) func TestRootElements(t *testing.T) { SchemaContainsCommonElements(t, generalAttributes) @@ -145,6 +166,11 @@ func SchemaContainsCommonElements(t *testing.T, providerSpecificSchema map[strin if providerSpecificSchema[test.field].IsComputed() != test.computed { t.Errorf("The '%s' filed's >computed< property should be: %t", test.field, test.computed) } + var currentType = reflect.TypeOf(providerSpecificSchema[test.field]) + var expectedType = reflect.TypeOf(test.attributeType) + if currentType != expectedType { + t.Errorf("The '%s' field's type should be: %t, instead of %t", test.field, expectedType, currentType) + } }) } } diff --git a/resources/datalake/schema_gcp_datalake_test.go b/resources/datalake/schema_gcp_datalake_test.go index 0ecfe011..58cd66a7 100644 --- a/resources/datalake/schema_gcp_datalake_test.go +++ b/resources/datalake/schema_gcp_datalake_test.go @@ -28,12 +28,14 @@ func TestGcpSpecificElements(t *testing.T) { field: "custom_instance_groups", computed: false, shouldBeRequired: false, + attributeType: schema.SetNestedAttribute{}, }, { name: "cloud_provider_configuration should exist", field: "cloud_provider_configuration", computed: false, shouldBeRequired: true, + attributeType: schema.SingleNestedAttribute{}, }, }