| // Copyright (c) HashiCorp, Inc. |
| // SPDX-License-Identifier: MPL-2.0 |
| |
| // ---------------------------------------------------------------------------- |
| // |
| // *** AUTO GENERATED CODE *** Type: MMv1 *** |
| // |
| // ---------------------------------------------------------------------------- |
| // |
| // This file is automatically generated by Magic Modules and manual |
| // changes will be clobbered when the file is regenerated. |
| // |
| // Please read more about how to change this file in |
| // .github/CONTRIBUTING.md. |
| // |
| // ---------------------------------------------------------------------------- |
| |
| package migrationcenter_test |
| |
| import ( |
| "fmt" |
| "strings" |
| "testing" |
| |
| "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" |
| "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" |
| |
| "github.com/hashicorp/terraform-provider-google-beta/google-beta/acctest" |
| "github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgresource" |
| transport_tpg "github.com/hashicorp/terraform-provider-google-beta/google-beta/transport" |
| ) |
| |
| func TestAccMigrationCenterPreferenceSet_preferenceSetBasicExample(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: testAccCheckMigrationCenterPreferenceSetDestroyProducer(t), |
| Steps: []resource.TestStep{ |
| { |
| Config: testAccMigrationCenterPreferenceSet_preferenceSetBasicExample(context), |
| }, |
| { |
| ResourceName: "google_migration_center_preference_set.default", |
| ImportState: true, |
| ImportStateVerify: true, |
| ImportStateVerifyIgnore: []string{"location", "preference_set_id"}, |
| }, |
| }, |
| }) |
| } |
| |
| func testAccMigrationCenterPreferenceSet_preferenceSetBasicExample(context map[string]interface{}) string { |
| return acctest.Nprintf(` |
| resource "google_migration_center_preference_set" "default" { |
| location = "us-central1" |
| preference_set_id = "tf-test-preference-set-test%{random_suffix}" |
| description = "Terraform integration test description" |
| display_name = "Terraform integration test display" |
| virtual_machine_preferences { |
| vmware_engine_preferences { |
| cpu_overcommit_ratio = 1.5 |
| } |
| sizing_optimization_strategy = "SIZING_OPTIMIZATION_STRATEGY_SAME_AS_SOURCE" |
| target_product = "COMPUTE_MIGRATION_TARGET_PRODUCT_COMPUTE_ENGINE" |
| } |
| } |
| `, context) |
| } |
| |
| func TestAccMigrationCenterPreferenceSet_preferenceSetFullExample(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: testAccCheckMigrationCenterPreferenceSetDestroyProducer(t), |
| Steps: []resource.TestStep{ |
| { |
| Config: testAccMigrationCenterPreferenceSet_preferenceSetFullExample(context), |
| }, |
| { |
| ResourceName: "google_migration_center_preference_set.default", |
| ImportState: true, |
| ImportStateVerify: true, |
| ImportStateVerifyIgnore: []string{"location", "preference_set_id"}, |
| }, |
| }, |
| }) |
| } |
| |
| func testAccMigrationCenterPreferenceSet_preferenceSetFullExample(context map[string]interface{}) string { |
| return acctest.Nprintf(` |
| resource "google_migration_center_preference_set" "default" { |
| location = "us-central1" |
| preference_set_id = "tf-test-preference-set-test%{random_suffix}" |
| description = "Terraform integration test description" |
| display_name = "Terraform integration test display" |
| virtual_machine_preferences { |
| vmware_engine_preferences { |
| cpu_overcommit_ratio = 1.5 |
| storage_deduplication_compression_ratio = 1.3 |
| commitment_plan = "ON_DEMAND" |
| } |
| sizing_optimization_strategy = "SIZING_OPTIMIZATION_STRATEGY_SAME_AS_SOURCE" |
| target_product = "COMPUTE_MIGRATION_TARGET_PRODUCT_COMPUTE_ENGINE" |
| commitment_plan = "COMMITMENT_PLAN_ONE_YEAR" |
| region_preferences { |
| preferred_regions = ["us-central1"] |
| } |
| sole_tenancy_preferences { |
| commitment_plan = "ON_DEMAND" |
| cpu_overcommit_ratio = 1.2 |
| host_maintenance_policy = "HOST_MAINTENANCE_POLICY_DEFAULT" |
| node_types { |
| node_name = "tf-test" |
| } |
| } |
| compute_engine_preferences { |
| license_type = "LICENSE_TYPE_BRING_YOUR_OWN_LICENSE" |
| machine_preferences { |
| allowed_machine_series { |
| code = "C3" |
| } |
| } |
| } |
| } |
| } |
| `, context) |
| } |
| |
| func testAccCheckMigrationCenterPreferenceSetDestroyProducer(t *testing.T) func(s *terraform.State) error { |
| return func(s *terraform.State) error { |
| for name, rs := range s.RootModule().Resources { |
| if rs.Type != "google_migration_center_preference_set" { |
| continue |
| } |
| if strings.HasPrefix(name, "data.") { |
| continue |
| } |
| |
| config := acctest.GoogleProviderConfig(t) |
| |
| url, err := tpgresource.ReplaceVarsForTest(config, rs, "{{MigrationCenterBasePath}}projects/{{project}}/locations/{{location}}/preferenceSets/{{preference_set_id}}") |
| if err != nil { |
| return err |
| } |
| |
| billingProject := "" |
| |
| if config.BillingProject != "" { |
| billingProject = config.BillingProject |
| } |
| |
| _, err = transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ |
| Config: config, |
| Method: "GET", |
| Project: billingProject, |
| RawURL: url, |
| UserAgent: config.UserAgent, |
| }) |
| if err == nil { |
| return fmt.Errorf("MigrationCenterPreferenceSet still exists at %s", url) |
| } |
| } |
| |
| return nil |
| } |
| } |