Skip to content

Commit 36b9c6d

Browse files
Yue Dengsagarp337
authored andcommitted
Added - Support for VM Instance - Snapshot/Restore Read only
1 parent 0b5cdf8 commit 36b9c6d

16 files changed

+1937
-19
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// use oci_database_db_node_snapshot_management resource to create dbnode snapshot(s)
2+
resource "oci_database_db_node_snapshot_management" "test_db_node_snapshot_management" {
3+
#Required
4+
exadb_vm_cluster_id = oci_database_exadb_vm_cluster.test_exadb_vm_cluster.id
5+
source_dbnode_ids = oci_database_exadb_vm_cluster.test_exadb_vm_cluster.node_resource[*].node_id
6+
name = "snapshot-tf-test"
7+
#Optional
8+
defined_tags = {
9+
"example-tag-namespace-all.example-tag" = "value"
10+
}
11+
freeform_tags = {
12+
"Department" = "Finance"
13+
}
14+
lifecycle {
15+
ignore_changes = [defined_tags, freeform_tags]
16+
}
17+
}
18+
19+
// use oci_database_db_node_snapshot resource to mount / unmount / delete dbnode snapshot
20+
resource "oci_database_db_node_snapshot" "test_db_node_snapshot" {
21+
#Required
22+
dbnode_snapshot_id = oci_database_db_node_snapshot_management.test_db_node_snapshot_management.snapshots[0].id
23+
mount_dbnode_id = "null"
24+
}
25+
26+
data "oci_database_db_node_snapshots" "test_db_node_snapshots" {
27+
#Required
28+
compartment_id = oci_database_exadb_vm_cluster.test_exadb_vm_cluster.compartment_id
29+
30+
#Optional
31+
cluster_id = oci_database_db_node_snapshot_management.test_db_node_snapshot_management.exadb_vm_cluster_id
32+
name = oci_database_db_node_snapshot_management.test_db_node_snapshot_management.snapshots[0].name
33+
source_dbnode_id = oci_database_db_node_snapshot_management.test_db_node_snapshot_management.snapshots[0].source_dbnode_id
34+
state = oci_database_db_node_snapshot_management.test_db_node_snapshot_management.snapshots[0].state
35+
36+
## Example: filter db_node_snapshots by name
37+
#filter {
38+
# name = "name"
39+
# regex = true
40+
# values = ["^\\w+-${oci_database_db_node_snapshot_management.test_db_node_snapshot_management.name}$"]
41+
#}
42+
#
43+
## Example: Get all but Terminated db_node_snapshots
44+
#filter {
45+
# name = "state"
46+
# values = ["CREATING", "AVAILABLE", "FAILED", "MOUNTED", "MOUNTING", "UNMOUNTING"]
47+
#}
48+
}
49+
50+
data "oci_database_db_node_snapshot" "test_db_node_snapshot" {
51+
#Required
52+
dbnode_snapshot_id = oci_database_db_node_snapshot_management.test_db_node_snapshot_management.snapshots[0].id
53+
}
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
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

Comments
 (0)