|
| 1 | +package integrationtest |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "strconv" |
| 6 | + "testing" |
| 7 | + |
| 8 | + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" |
| 9 | + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" |
| 10 | + |
| 11 | + "github.com/terraform-providers/terraform-provider-oci/httpreplay" |
| 12 | + "github.com/terraform-providers/terraform-provider-oci/internal/acctest" |
| 13 | + "github.com/terraform-providers/terraform-provider-oci/internal/resourcediscovery" |
| 14 | + "github.com/terraform-providers/terraform-provider-oci/internal/utils" |
| 15 | +) |
| 16 | + |
| 17 | +var ( |
| 18 | + CloudVmClusterIormConfigRequiredOnlyResource = CloudVmClusterIormConfigResourceDependencies + |
| 19 | + acctest.GenerateResourceFromRepresentationMap("oci_database_cloud_vm_cluster_iorm_config", "test_cloud_vm_cluster_iorm_config", acctest.Required, acctest.Create, cloudVmClusterIormConfigRepresentation) |
| 20 | + |
| 21 | + CloudVmClusterIormConfigResourceConfig = CloudVmClusterIormConfigResourceDependencies + |
| 22 | + acctest.GenerateResourceFromRepresentationMap("oci_database_cloud_vm_cluster_iorm_config", "test_cloud_vm_cluster_iorm_config", acctest.Optional, acctest.Update, cloudVmClusterIormConfigRepresentation) |
| 23 | + |
| 24 | + cloudVmClusterIormConfigSingularDataSourceRepresentation = map[string]interface{}{ |
| 25 | + "cloud_vm_cluster_id": acctest.Representation{RepType: acctest.Required, Create: `${oci_database_cloud_vm_cluster.test_cloud_vm_cluster.id}`}, |
| 26 | + } |
| 27 | + |
| 28 | + cloudVmClusterIormConfigRepresentation = map[string]interface{}{ |
| 29 | + "cloud_vm_cluster_id": acctest.Representation{RepType: acctest.Required, Create: `${oci_database_cloud_vm_cluster.test_cloud_vm_cluster.id}`}, |
| 30 | + "objective": acctest.Representation{RepType: acctest.Optional, Create: `AUTO`, Update: `BALANCED`}, |
| 31 | + "db_plans": acctest.RepresentationGroup{RepType: acctest.Required, Group: dbPlanRepresentation}, |
| 32 | + } |
| 33 | + |
| 34 | + CloudVmClusterIormConfigResourceDependencies = AvailabilityDomainConfig + CloudVmClusterRequiredOnlyResource |
| 35 | +) |
| 36 | + |
| 37 | +// issue-routing-tag: database/ExaCS |
| 38 | +func TestDatabaseCloudVmClusterIormConfigResource_basic(t *testing.T) { |
| 39 | + |
| 40 | + httpreplay.SetScenario("TestDatabaseCloudVmClusterIormConfigResource_basic") |
| 41 | + defer httpreplay.SaveScenario() |
| 42 | + |
| 43 | + config := acctest.ProviderTestConfig() |
| 44 | + |
| 45 | + compartmentId := utils.GetEnvSettingWithBlankDefault("compartment_ocid") |
| 46 | + compartmentIdVariableStr := fmt.Sprintf("variable \"compartment_id\" { default = \"%s\" }\n", compartmentId) |
| 47 | + |
| 48 | + resourceName := "oci_database_cloud_vm_cluster_iorm_config.test_cloud_vm_cluster_iorm_config" |
| 49 | + |
| 50 | + singularDatasourceName := "data.oci_database_cloud_vm_cluster_iorm_config.test_cloud_vm_cluster_iorm_config" |
| 51 | + |
| 52 | + var resId, resId2 string |
| 53 | + // Save TF content to Create resource with optional properties. This has to be exactly the same as the config part in the "Create with optionals" step in the test. |
| 54 | + acctest.SaveConfigContent(config+compartmentIdVariableStr+CloudVmClusterIormConfigResourceDependencies+ |
| 55 | + acctest.GenerateResourceFromRepresentationMap("oci_database_cloud_vm_cluster_iorm_config", "test_cloud_vm_cluster_iorm_config", acctest.Optional, acctest.Create, cloudVmClusterIormConfigRepresentation), "database", "exadataIormConfig", t) |
| 56 | + |
| 57 | + acctest.ResourceTest(t, nil, []resource.TestStep{ |
| 58 | + // verify Create |
| 59 | + { |
| 60 | + Config: config + compartmentIdVariableStr + CloudVmClusterIormConfigResourceDependencies + |
| 61 | + acctest.GenerateResourceFromRepresentationMap("oci_database_cloud_vm_cluster_iorm_config", "test_cloud_vm_cluster_iorm_config", acctest.Required, acctest.Create, cloudVmClusterIormConfigRepresentation), |
| 62 | + Check: acctest.ComposeAggregateTestCheckFuncWrapper( |
| 63 | + resource.TestCheckResourceAttrSet(resourceName, "cloud_vm_cluster_id"), |
| 64 | + resource.TestCheckResourceAttr(resourceName, "db_plans.#", "1"), |
| 65 | + |
| 66 | + func(s *terraform.State) (err error) { |
| 67 | + resId, err = acctest.FromInstanceState(s, resourceName, "id") |
| 68 | + return err |
| 69 | + }, |
| 70 | + ), |
| 71 | + }, |
| 72 | + |
| 73 | + // delete before next Create |
| 74 | + { |
| 75 | + Config: config + compartmentIdVariableStr + CloudVmClusterIormConfigResourceDependencies, |
| 76 | + }, |
| 77 | + // verify Create with optionals |
| 78 | + { |
| 79 | + Config: config + compartmentIdVariableStr + CloudVmClusterIormConfigResourceDependencies + |
| 80 | + acctest.GenerateResourceFromRepresentationMap("oci_database_cloud_vm_cluster_iorm_config", "test_cloud_vm_cluster_iorm_config", acctest.Optional, acctest.Create, cloudVmClusterIormConfigRepresentation), |
| 81 | + Check: acctest.ComposeAggregateTestCheckFuncWrapper( |
| 82 | + resource.TestCheckResourceAttr(resourceName, "objective", "AUTO"), |
| 83 | + |
| 84 | + func(s *terraform.State) (err error) { |
| 85 | + resId, err = acctest.FromInstanceState(s, resourceName, "id") |
| 86 | + if isEnableExportCompartment, _ := strconv.ParseBool(utils.GetEnvSettingWithDefault("enable_export_compartment", "true")); isEnableExportCompartment { |
| 87 | + if errExport := resourcediscovery.TestExportCompartmentWithResourceName(&resId, &compartmentId, resourceName); errExport != nil { |
| 88 | + return errExport |
| 89 | + } |
| 90 | + } |
| 91 | + return err |
| 92 | + }, |
| 93 | + ), |
| 94 | + }, |
| 95 | + |
| 96 | + // verify updates to updatable parameters |
| 97 | + { |
| 98 | + Config: config + compartmentIdVariableStr + CloudVmClusterIormConfigResourceDependencies + |
| 99 | + acctest.GenerateResourceFromRepresentationMap("oci_database_cloud_vm_cluster_iorm_config", "test_cloud_vm_cluster_iorm_config", acctest.Optional, acctest.Update, cloudVmClusterIormConfigRepresentation), |
| 100 | + Check: acctest.ComposeAggregateTestCheckFuncWrapper( |
| 101 | + resource.TestCheckResourceAttrSet(resourceName, "cloud_vm_cluster_id"), |
| 102 | + resource.TestCheckResourceAttr(resourceName, "objective", "BALANCED"), |
| 103 | + resource.TestCheckResourceAttr(resourceName, "db_plans.#", "1"), |
| 104 | + |
| 105 | + func(s *terraform.State) (err error) { |
| 106 | + resId2, err = acctest.FromInstanceState(s, resourceName, "id") |
| 107 | + if resId != resId2 { |
| 108 | + return fmt.Errorf("Resource recreated when it was supposed to be updated.") |
| 109 | + } |
| 110 | + return err |
| 111 | + }, |
| 112 | + ), |
| 113 | + }, |
| 114 | + // verify singular datasource |
| 115 | + { |
| 116 | + Config: config + |
| 117 | + acctest.GenerateDataSourceFromRepresentationMap("oci_database_cloud_vm_cluster_iorm_config", "test_cloud_vm_cluster_iorm_config", acctest.Required, acctest.Create, cloudVmClusterIormConfigSingularDataSourceRepresentation) + |
| 118 | + compartmentIdVariableStr + CloudVmClusterIormConfigResourceConfig, |
| 119 | + Check: acctest.ComposeAggregateTestCheckFuncWrapper( |
| 120 | + resource.TestCheckResourceAttrSet(singularDatasourceName, "cloud_vm_cluster_id"), |
| 121 | + |
| 122 | + resource.TestCheckResourceAttr(singularDatasourceName, "db_plans.#", "1"), |
| 123 | + resource.TestCheckResourceAttr(singularDatasourceName, "objective", "BALANCED"), |
| 124 | + resource.TestCheckResourceAttrSet(singularDatasourceName, "state"), |
| 125 | + ), |
| 126 | + }, |
| 127 | + }) |
| 128 | +} |
0 commit comments