Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add scaling_config to google_dataproc_metastore_service resource in google #15476

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/8526.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
dataproc_metastore: added `scaling_config` field to `google_dataproc_metastore_service` resource
```
138 changes: 138 additions & 0 deletions google/resource_dataproc_metastore_service_generated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,144 @@ resource "google_dataproc_metastore_service" "telemetry" {
`, context)
}

func TestAccDataprocMetastoreService_dataprocMetastoreServiceDpms2Example(t *testing.T) {
t.Parallel()

context := map[string]interface{}{
"random_suffix": acctest.RandString(t, 10),
}

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckDataprocMetastoreServiceDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccDataprocMetastoreService_dataprocMetastoreServiceDpms2Example(context),
},
{
ResourceName: "google_dataproc_metastore_service.dpms2",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"service_id", "location"},
},
},
})
}

func testAccDataprocMetastoreService_dataprocMetastoreServiceDpms2Example(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_dataproc_metastore_service" "dpms2" {
service_id = "dpms2%{random_suffix}"
location = "us-central1"

# DPMS 2 requires SPANNER database type, and does not require
# a maintenance window.
database_type = "SPANNER"

hive_metastore_config {
version = "3.1.2"
}

scaling_config {
instance_size = "EXTRA_SMALL"
}
}
`, context)
}

func TestAccDataprocMetastoreService_dataprocMetastoreServiceDpms2ScalingFactorExample(t *testing.T) {
t.Parallel()

context := map[string]interface{}{
"random_suffix": acctest.RandString(t, 10),
}

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckDataprocMetastoreServiceDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccDataprocMetastoreService_dataprocMetastoreServiceDpms2ScalingFactorExample(context),
},
{
ResourceName: "google_dataproc_metastore_service.dpms2_scaling_factor",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"service_id", "location"},
},
},
})
}

func testAccDataprocMetastoreService_dataprocMetastoreServiceDpms2ScalingFactorExample(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_dataproc_metastore_service" "dpms2_scaling_factor" {
service_id = "dpms2sf%{random_suffix}"
location = "us-central1"

# DPMS 2 requires SPANNER database type, and does not require
# a maintenance window.
database_type = "SPANNER"

hive_metastore_config {
version = "3.1.2"
}

scaling_config {
scaling_factor = "2"
}
}
`, context)
}

func TestAccDataprocMetastoreService_dataprocMetastoreServiceDpms2ScalingFactorLt1Example(t *testing.T) {
t.Parallel()

context := map[string]interface{}{
"random_suffix": acctest.RandString(t, 10),
}

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckDataprocMetastoreServiceDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccDataprocMetastoreService_dataprocMetastoreServiceDpms2ScalingFactorLt1Example(context),
},
{
ResourceName: "google_dataproc_metastore_service.dpms2_scaling_factor_lt1",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"service_id", "location"},
},
},
})
}

func testAccDataprocMetastoreService_dataprocMetastoreServiceDpms2ScalingFactorLt1Example(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_dataproc_metastore_service" "dpms2_scaling_factor_lt1" {
service_id = "dpms2sflt1%{random_suffix}"
location = "us-central1"

# DPMS 2 requires SPANNER database type, and does not require
# a maintenance window.
database_type = "SPANNER"

hive_metastore_config {
version = "3.1.2"
}

scaling_config {
scaling_factor = "0.1"
}
}
`, context)
}

func testAccCheckDataprocMetastoreServiceDestroyProducer(t *testing.T) func(s *terraform.State) error {
return func(s *terraform.State) error {
for name, rs := range s.RootModule().Resources {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,29 @@ There must be at least one IP address available in the subnet's primary range. T
Description: `The release channel of the service. If unspecified, defaults to 'STABLE'. Default value: "STABLE" Possible values: ["CANARY", "STABLE"]`,
Default: "STABLE",
},
"scaling_config": {
Type: schema.TypeList,
Optional: true,
Description: `Represents the scaling configuration of a metastore service.`,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"instance_size": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: verify.ValidateEnum([]string{"EXTRA_SMALL", "SMALL", "MEDIUM", "LARGE", "EXTRA_LARGE", ""}),
Description: `Metastore instance sizes. Possible values: ["EXTRA_SMALL", "SMALL", "MEDIUM", "LARGE", "EXTRA_LARGE"]`,
ConflictsWith: []string{"tier"},
ExactlyOneOf: []string{"scaling_config.0.instance_size", "scaling_config.0.scaling_factor"},
},
"scaling_factor": {
Type: schema.TypeFloat,
Optional: true,
Description: `Scaling factor, in increments of 0.1 for values less than 1.0, and increments of 1.0 for values greater than 1.0.`,
},
},
},
},
"telemetry_config": {
Type: schema.TypeList,
Computed: true,
Expand All @@ -258,11 +281,12 @@ There must be at least one IP address available in the subnet's primary range. T
},
},
"tier": {
Type: schema.TypeString,
Computed: true,
Optional: true,
ValidateFunc: verify.ValidateEnum([]string{"DEVELOPER", "ENTERPRISE", ""}),
Description: `The tier of the service. Possible values: ["DEVELOPER", "ENTERPRISE"]`,
Type: schema.TypeString,
Computed: true,
Optional: true,
ValidateFunc: verify.ValidateEnum([]string{"DEVELOPER", "ENTERPRISE", ""}),
Description: `The tier of the service. Possible values: ["DEVELOPER", "ENTERPRISE"]`,
ConflictsWith: []string{"scaling_config"},
},
"artifact_gcs_uri": {
Type: schema.TypeString,
Expand Down Expand Up @@ -337,6 +361,12 @@ func resourceDataprocMetastoreServiceCreate(d *schema.ResourceData, meta interfa
} else if v, ok := d.GetOkExists("tier"); !tpgresource.IsEmptyValue(reflect.ValueOf(tierProp)) && (ok || !reflect.DeepEqual(v, tierProp)) {
obj["tier"] = tierProp
}
scalingConfigProp, err := expandDataprocMetastoreServiceScalingConfig(d.Get("scaling_config"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("scaling_config"); !tpgresource.IsEmptyValue(reflect.ValueOf(scalingConfigProp)) && (ok || !reflect.DeepEqual(v, scalingConfigProp)) {
obj["scalingConfig"] = scalingConfigProp
}
maintenanceWindowProp, err := expandDataprocMetastoreServiceMaintenanceWindow(d.Get("maintenance_window"), d, config)
if err != nil {
return err
Expand Down Expand Up @@ -501,6 +531,9 @@ func resourceDataprocMetastoreServiceRead(d *schema.ResourceData, meta interface
if err := d.Set("tier", flattenDataprocMetastoreServiceTier(res["tier"], d, config)); err != nil {
return fmt.Errorf("Error reading Service: %s", err)
}
if err := d.Set("scaling_config", flattenDataprocMetastoreServiceScalingConfig(res["scalingConfig"], d, config)); err != nil {
return fmt.Errorf("Error reading Service: %s", err)
}
if err := d.Set("maintenance_window", flattenDataprocMetastoreServiceMaintenanceWindow(res["maintenanceWindow"], d, config)); err != nil {
return fmt.Errorf("Error reading Service: %s", err)
}
Expand Down Expand Up @@ -563,6 +596,12 @@ func resourceDataprocMetastoreServiceUpdate(d *schema.ResourceData, meta interfa
} else if v, ok := d.GetOkExists("tier"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, tierProp)) {
obj["tier"] = tierProp
}
scalingConfigProp, err := expandDataprocMetastoreServiceScalingConfig(d.Get("scaling_config"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("scaling_config"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, scalingConfigProp)) {
obj["scalingConfig"] = scalingConfigProp
}
maintenanceWindowProp, err := expandDataprocMetastoreServiceMaintenanceWindow(d.Get("maintenance_window"), d, config)
if err != nil {
return err
Expand Down Expand Up @@ -608,6 +647,10 @@ func resourceDataprocMetastoreServiceUpdate(d *schema.ResourceData, meta interfa
updateMask = append(updateMask, "tier")
}

if d.HasChange("scaling_config") {
updateMask = append(updateMask, "scalingConfig")
}

if d.HasChange("maintenance_window") {
updateMask = append(updateMask, "maintenanceWindow")
}
Expand Down Expand Up @@ -784,6 +827,29 @@ func flattenDataprocMetastoreServiceTier(v interface{}, d *schema.ResourceData,
return v
}

func flattenDataprocMetastoreServiceScalingConfig(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
if v == nil {
return nil
}
original := v.(map[string]interface{})
if len(original) == 0 {
return nil
}
transformed := make(map[string]interface{})
transformed["instance_size"] =
flattenDataprocMetastoreServiceScalingConfigInstanceSize(original["instanceSize"], d, config)
transformed["scaling_factor"] =
flattenDataprocMetastoreServiceScalingConfigScalingFactor(original["scalingFactor"], d, config)
return []interface{}{transformed}
}
func flattenDataprocMetastoreServiceScalingConfigInstanceSize(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}

func flattenDataprocMetastoreServiceScalingConfigScalingFactor(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}

func flattenDataprocMetastoreServiceMaintenanceWindow(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
if v == nil {
return nil
Expand Down Expand Up @@ -996,6 +1062,40 @@ func expandDataprocMetastoreServiceTier(v interface{}, d tpgresource.TerraformRe
return v, nil
}

func expandDataprocMetastoreServiceScalingConfig(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
l := v.([]interface{})
if len(l) == 0 || l[0] == nil {
return nil, nil
}
raw := l[0]
original := raw.(map[string]interface{})
transformed := make(map[string]interface{})

transformedInstanceSize, err := expandDataprocMetastoreServiceScalingConfigInstanceSize(original["instance_size"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedInstanceSize); val.IsValid() && !tpgresource.IsEmptyValue(val) {
transformed["instanceSize"] = transformedInstanceSize
}

transformedScalingFactor, err := expandDataprocMetastoreServiceScalingConfigScalingFactor(original["scaling_factor"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedScalingFactor); val.IsValid() && !tpgresource.IsEmptyValue(val) {
transformed["scalingFactor"] = transformedScalingFactor
}

return transformed, nil
}

func expandDataprocMetastoreServiceScalingConfigInstanceSize(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

func expandDataprocMetastoreServiceScalingConfigScalingFactor(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

func expandDataprocMetastoreServiceMaintenanceWindow(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
l := v.([]interface{})
if len(l) == 0 || l[0] == nil {
Expand Down
Loading