|
| 1 | +// Copyright (c) 2017, 2024, Oracle and/or its affiliates. All rights reserved. |
| 2 | +// Licensed under the Mozilla Public License v2.0 |
| 3 | + |
| 4 | +package integrationtest |
| 5 | + |
| 6 | +import ( |
| 7 | + "fmt" |
| 8 | + "strconv" |
| 9 | + "testing" |
| 10 | + |
| 11 | + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" |
| 12 | + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" |
| 13 | + |
| 14 | + "github.com/oracle/terraform-provider-oci/httpreplay" |
| 15 | + "github.com/oracle/terraform-provider-oci/internal/acctest" |
| 16 | + "github.com/oracle/terraform-provider-oci/internal/resourcediscovery" |
| 17 | + |
| 18 | + "github.com/oracle/terraform-provider-oci/internal/utils" |
| 19 | +) |
| 20 | + |
| 21 | +var ( |
| 22 | + DatabaseDbNodeSnapshotManagementRepresentation = map[string]interface{}{ |
| 23 | + "exadb_vm_cluster_id": acctest.Representation{RepType: acctest.Required, Create: `${data.oci_database_exadb_vm_cluster.test_exadb_vm_cluster.id}`}, |
| 24 | + "name": acctest.Representation{RepType: acctest.Required, Create: `snapshot1`}, |
| 25 | + "source_dbnode_ids": acctest.Representation{RepType: acctest.Required, Create: `${data.oci_database_exadb_vm_cluster.test_exadb_vm_cluster.node_resource[*].node_id}`}, |
| 26 | + "defined_tags": acctest.Representation{RepType: acctest.Optional, Create: map[string]string{"example-tag-namespace-all.example-tag": "value"}}, |
| 27 | + "freeform_tags": acctest.Representation{RepType: acctest.Optional, Create: map[string]string{"Department": "Finance"}}, |
| 28 | + "lifecycle": acctest.RepresentationGroup{RepType: acctest.Required, Group: DatabaseDbNodeSnapshotManagementIgnoreTagsRepresentation}, |
| 29 | + } |
| 30 | + |
| 31 | + DatabaseDbNodeSnapshotManagementIgnoreTagsRepresentation = map[string]interface{}{ |
| 32 | + "ignore_changes": acctest.Representation{RepType: acctest.Required, Create: []string{`defined_tags`, `freeform_tags`}}, |
| 33 | + } |
| 34 | + |
| 35 | + DatabaseDbNodeSnapshotManagementResourceDependencies = ` |
| 36 | + variable exadb_vm_cluster_id {} |
| 37 | +
|
| 38 | + data "oci_database_exadb_vm_cluster" "test_exadb_vm_cluster" { |
| 39 | + exadb_vm_cluster_id = var.exadb_vm_cluster_id |
| 40 | + } |
| 41 | + ` |
| 42 | +) |
| 43 | + |
| 44 | +// issue-routing-tag: database/default |
| 45 | +func TestDatabaseDbNodeSnapshotManagementResource_basic(t *testing.T) { |
| 46 | + httpreplay.SetScenario("TestDatabaseDbNodeSnapshotManagementResource_basic") |
| 47 | + defer httpreplay.SaveScenario() |
| 48 | + |
| 49 | + config := acctest.ProviderTestConfig() |
| 50 | + |
| 51 | + compartmentId := utils.GetEnvSettingWithBlankDefault("compartment_ocid") |
| 52 | + compartmentIdVariableStr := fmt.Sprintf("variable \"compartment_id\" { default = \"%s\" }\n", compartmentId) |
| 53 | + |
| 54 | + resourceName := "oci_database_db_node_snapshot_management.test_db_node_snapshot_management" |
| 55 | + |
| 56 | + var resId string |
| 57 | + // 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. |
| 58 | + acctest.SaveConfigContent(config+compartmentIdVariableStr+DatabaseDbNodeSnapshotManagementResourceDependencies+ |
| 59 | + acctest.GenerateResourceFromRepresentationMap("oci_database_db_node_snapshot_management", "test_db_node_snapshot_management", acctest.Optional, acctest.Create, DatabaseDbNodeSnapshotManagementRepresentation), "database", "dbNodeSnapshotManagement", t) |
| 60 | + |
| 61 | + acctest.ResourceTest(t, nil, []resource.TestStep{ |
| 62 | + // verify Create |
| 63 | + { |
| 64 | + Config: config + compartmentIdVariableStr + DatabaseDbNodeSnapshotManagementResourceDependencies + |
| 65 | + acctest.GenerateResourceFromRepresentationMap("oci_database_db_node_snapshot_management", "test_db_node_snapshot_management", acctest.Required, acctest.Create, DatabaseDbNodeSnapshotManagementRepresentation), |
| 66 | + Check: acctest.ComposeAggregateTestCheckFuncWrapper( |
| 67 | + resource.TestCheckResourceAttrSet(resourceName, "exadb_vm_cluster_id"), |
| 68 | + resource.TestCheckResourceAttr(resourceName, "name", "snapshot1"), |
| 69 | + resource.TestCheckResourceAttr(resourceName, "source_dbnode_ids.#", "3"), |
| 70 | + resource.TestCheckResourceAttr(resourceName, "snapshots.#", "3"), |
| 71 | + ), |
| 72 | + }, |
| 73 | + |
| 74 | + // delete before next Create |
| 75 | + { |
| 76 | + Config: config + compartmentIdVariableStr + DatabaseDbNodeSnapshotManagementResourceDependencies, |
| 77 | + }, |
| 78 | + // verify Create with optionals |
| 79 | + { |
| 80 | + Config: config + compartmentIdVariableStr + DatabaseDbNodeSnapshotManagementResourceDependencies + |
| 81 | + acctest.GenerateResourceFromRepresentationMap("oci_database_db_node_snapshot_management", "test_db_node_snapshot_management", acctest.Optional, acctest.Create, |
| 82 | + acctest.RepresentationCopyWithNewProperties(DatabaseDbNodeSnapshotManagementRepresentation, map[string]interface{}{ |
| 83 | + "name": acctest.Representation{RepType: acctest.Required, Create: `snapshot2`}, |
| 84 | + })), |
| 85 | + Check: acctest.ComposeAggregateTestCheckFuncWrapper( |
| 86 | + resource.TestCheckResourceAttrSet(resourceName, "exadb_vm_cluster_id"), |
| 87 | + resource.TestCheckResourceAttr(resourceName, "name", "snapshot2"), |
| 88 | + resource.TestCheckResourceAttr(resourceName, "source_dbnode_ids.#", "3"), |
| 89 | + resource.TestCheckResourceAttr(resourceName, "snapshots.#", "3"), |
| 90 | + resource.TestCheckResourceAttr(resourceName, "freeform_tags.%", "1"), |
| 91 | + resource.TestCheckResourceAttr(resourceName, "freeform_tags.Department", "Finance"), |
| 92 | + |
| 93 | + func(s *terraform.State) (err error) { |
| 94 | + resId, err = acctest.FromInstanceState(s, resourceName, "id") |
| 95 | + if isEnableExportCompartment, _ := strconv.ParseBool(utils.GetEnvSettingWithDefault("enable_export_compartment", "true")); isEnableExportCompartment { |
| 96 | + if errExport := resourcediscovery.TestExportCompartmentWithResourceName(&resId, &compartmentId, resourceName); errExport != nil { |
| 97 | + return errExport |
| 98 | + } |
| 99 | + } |
| 100 | + return err |
| 101 | + }, |
| 102 | + ), |
| 103 | + }, |
| 104 | + }) |
| 105 | +} |
0 commit comments