Skip to content

Commit 6d4612b

Browse files
Terraform Team AutomationNagaRajuPasunuri
authored andcommitted
Added - Support for Recovery Cloud Service Onboarding
1 parent 29bd8bc commit 6d4612b

File tree

37 files changed

+5087
-0
lines changed

37 files changed

+5087
-0
lines changed

examples/recovery/network.tf

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
2+
// Licensed under the Mozilla Public License v2.0
3+
4+
resource "oci_core_vcn" "test_vcn" {
5+
cidr_block = "10.0.0.0/16"
6+
compartment_id = var.compartment_id
7+
display_name = "exampleVCN"
8+
dns_label = "tfexamplevcn"
9+
}
10+
11+
resource "oci_core_subnet" "test_subnet" {
12+
cidr_block = "10.0.0.0/24"
13+
display_name = "tfexampleSubnet"
14+
dns_label = "tfexampleSubnet"
15+
compartment_id = var.compartment_id
16+
vcn_id = oci_core_vcn.test_vcn.id
17+
security_list_ids = [oci_core_vcn.test_vcn.default_security_list_id]
18+
route_table_id = oci_core_vcn.test_vcn.default_route_table_id
19+
dhcp_options_id = oci_core_vcn.test_vcn.default_dhcp_options_id
20+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
2+
// Licensed under the Mozilla Public License v2.0
3+
4+
variable "protected_database_database_size" {
5+
default = "XS"
6+
}
7+
8+
variable "protected_database_db_unique_name" {
9+
default = "dbUniqueName"
10+
}
11+
12+
variable "protected_database_defined_tags_value" {
13+
default = "value"
14+
}
15+
16+
variable "protected_database_display_name" {
17+
default = "displayName"
18+
}
19+
20+
variable "database_id" {
21+
default = "database-id"
22+
}
23+
24+
variable "protected_database_freeform_tags" {
25+
default = { "bar-key" = "value" }
26+
}
27+
28+
variable "protected_database_id" {
29+
default = "id"
30+
}
31+
32+
variable "protected_database_is_redo_logs_shipped" {
33+
default = false
34+
}
35+
36+
variable "protected_database_password" {
37+
default = "BEstrO0ng_secret#11"
38+
}
39+
40+
variable "protected_database_state" {
41+
default = "ACTIVE"
42+
}
43+
44+
45+
resource "oci_recovery_protected_database" "test_protected_database" {
46+
#Required
47+
compartment_id = var.compartment_id
48+
db_unique_name = var.protected_database_db_unique_name
49+
display_name = var.protected_database_display_name
50+
password = var.protected_database_password
51+
protection_policy_id = oci_recovery_protection_policy.test_protection_policy.id
52+
recovery_service_subnets {
53+
#Required
54+
recovery_service_subnet_id = oci_recovery_recovery_service_subnet.test_recovery_service_subnet.id
55+
}
56+
57+
#Optional
58+
database_id = var.database_id
59+
database_size = var.protected_database_database_size
60+
freeform_tags = var.protected_database_freeform_tags
61+
is_redo_logs_shipped = var.protected_database_is_redo_logs_shipped
62+
}
63+
64+
data "oci_recovery_protected_databases" "test_protected_databases" {
65+
#Required
66+
compartment_id = var.compartment_id
67+
68+
#Optional
69+
display_name = var.protected_database_display_name
70+
id = var.protected_database_id
71+
protection_policy_id = oci_recovery_protection_policy.test_protection_policy.id
72+
recovery_service_subnet_id = oci_recovery_recovery_service_subnet.test_recovery_service_subnet.id
73+
state = var.protected_database_state
74+
}
75+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
2+
// Licensed under the Mozilla Public License v2.0
3+
4+
5+
variable "protected_database_fetch_configuration_configuration_type" {
6+
default = "ALL"
7+
}
8+
9+
data "oci_recovery_protected_database_fetch_configuration" "test_protected_database_fetch_configuration" {
10+
#Required
11+
protected_database_id = oci_recovery_protected_database.test_protected_database.id
12+
13+
#Optional
14+
configuration_type = var.protected_database_fetch_configuration_configuration_type
15+
base64_encode_content = true
16+
}
17+
18+
resource "local_sensitive_file" "downloaded_configuration" {
19+
filename = "${path.module}/configuration.zip"
20+
content_base64 = data.oci_recovery_protected_database_fetch_configuration.test_protected_database_fetch_configuration.content
21+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
2+
// Licensed under the Mozilla Public License v2.0
3+
4+
variable "protection_policy_backup_retention_period_in_days" {
5+
default = 10
6+
}
7+
8+
variable "protection_policy_display_name" {
9+
default = "displayName"
10+
}
11+
12+
variable "protection_policy_freeform_tags" {
13+
default = { "bar-key" = "value" }
14+
}
15+
16+
variable "protection_policy_owner" {
17+
default = "customer"
18+
}
19+
20+
variable "protection_policy_state" {
21+
default = "ACTIVE"
22+
}
23+
24+
25+
resource "oci_recovery_protection_policy" "test_protection_policy" {
26+
#Required
27+
backup_retention_period_in_days = var.protection_policy_backup_retention_period_in_days
28+
compartment_id = var.compartment_id
29+
display_name = var.protection_policy_display_name
30+
31+
#Optional
32+
freeform_tags = var.protection_policy_freeform_tags
33+
}
34+
35+
data "oci_recovery_protection_policies" "test_protection_policies" {
36+
#Required
37+
compartment_id = var.compartment_id
38+
39+
#Optional
40+
display_name = var.protection_policy_display_name
41+
owner = var.protection_policy_owner
42+
protection_policy_id = oci_recovery_protection_policy.test_protection_policy.id
43+
state = var.protection_policy_state
44+
}

examples/recovery/provider.tf

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
2+
// Licensed under the Mozilla Public License v2.0
3+
4+
variable "tenancy_ocid" {}
5+
variable "user_ocid" {}
6+
variable "fingerprint" {}
7+
variable "private_key_path" {}
8+
variable "region" {}
9+
variable "compartment_id" {}
10+
11+
12+
provider "oci" {
13+
tenancy_ocid = var.tenancy_ocid
14+
user_ocid = var.user_ocid
15+
fingerprint = var.fingerprint
16+
private_key_path = var.private_key_path
17+
region = var.region
18+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
2+
// Licensed under the Mozilla Public License v2.0
3+
4+
variable "recovery_service_subnet_defined_tags_value" {
5+
default = "value"
6+
}
7+
8+
variable "recovery_service_subnet_display_name" {
9+
default = "displayName"
10+
}
11+
12+
variable "recovery_service_subnet_freeform_tags" {
13+
default = { "bar-key" = "value" }
14+
}
15+
16+
variable "recovery_service_subnet_id" {
17+
default = "id"
18+
}
19+
20+
variable "recovery_service_subnet_state" {
21+
default = "ACTIVE"
22+
}
23+
24+
25+
resource "oci_recovery_recovery_service_subnet" "test_recovery_service_subnet" {
26+
#Required
27+
compartment_id = var.compartment_id
28+
display_name = var.recovery_service_subnet_display_name
29+
subnet_id = oci_core_subnet.test_subnet.id
30+
vcn_id = oci_core_vcn.test_vcn.id
31+
32+
#Optional
33+
freeform_tags = var.recovery_service_subnet_freeform_tags
34+
}
35+
36+
data "oci_recovery_recovery_service_subnets" "test_recovery_service_subnets" {
37+
#Required
38+
compartment_id = var.compartment_id
39+
40+
#Optional
41+
display_name = var.recovery_service_subnet_display_name
42+
id = var.recovery_service_subnet_id
43+
state = var.recovery_service_subnet_state
44+
vcn_id = oci_core_vcn.test_vcn.id
45+
}
46+
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
2+
// Licensed under the Mozilla Public License v2.0
3+
4+
package client
5+
6+
import (
7+
oci_recovery "github.com/oracle/oci-go-sdk/v65/recovery"
8+
9+
oci_common "github.com/oracle/oci-go-sdk/v65/common"
10+
)
11+
12+
func init() {
13+
RegisterOracleClient("oci_recovery.DatabaseRecoveryClient", &OracleClient{InitClientFn: initRecoveryDatabaseRecoveryClient})
14+
}
15+
16+
func initRecoveryDatabaseRecoveryClient(configProvider oci_common.ConfigurationProvider, configureClient ConfigureClient, serviceClientOverrides ServiceClientOverrides) (interface{}, error) {
17+
client, err := oci_recovery.NewDatabaseRecoveryClientWithConfigurationProvider(configProvider)
18+
if err != nil {
19+
return nil, err
20+
}
21+
err = configureClient(&client.BaseClient)
22+
if err != nil {
23+
return nil, err
24+
}
25+
26+
if serviceClientOverrides.HostUrlOverride != "" {
27+
client.Host = serviceClientOverrides.HostUrlOverride
28+
}
29+
return &client, nil
30+
}
31+
32+
func (m *OracleClients) DatabaseRecoveryClient() *oci_recovery.DatabaseRecoveryClient {
33+
return m.GetClient("oci_recovery.DatabaseRecoveryClient").(*oci_recovery.DatabaseRecoveryClient)
34+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// Copyright (c) 2017, 2021, 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+
"testing"
9+
10+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
11+
12+
"github.com/oracle/terraform-provider-oci/httpreplay"
13+
"github.com/oracle/terraform-provider-oci/internal/acctest"
14+
15+
"github.com/oracle/terraform-provider-oci/internal/utils"
16+
)
17+
18+
var (
19+
RecoveryprotectedDatabaseFetchConfigurationSingularDataSourceRepresentation = map[string]interface{}{
20+
"protected_database_id": acctest.Representation{RepType: acctest.Required, Create: `${oci_recovery_protected_database.test_protected_database.id}`},
21+
"base64_encode_content": acctest.Representation{RepType: acctest.Optional, Create: `false`},
22+
"configuration_type": acctest.Representation{RepType: acctest.Optional, Create: `ALL`},
23+
}
24+
25+
RecoveryProtectedDatabaseFetchConfigurationResourceConfig = RecoveryProtectedDatabaseRequiredOnlyResource
26+
)
27+
28+
// issue-routing-tag: recovery/default
29+
func TestRecoveryProtectedDatabaseFetchConfigurationResource_basic(t *testing.T) {
30+
httpreplay.SetScenario("TestRecoveryProtectedDatabaseFetchConfigurationResource_basic")
31+
defer httpreplay.SaveScenario()
32+
33+
config := acctest.ProviderTestConfig()
34+
35+
compartmentId := utils.GetEnvSettingWithBlankDefault("compartment_ocid")
36+
compartmentIdVariableStr := fmt.Sprintf("variable \"compartment_id\" { default = \"%s\" }\n", compartmentId)
37+
38+
singularDatasourceName := "data.oci_recovery_protected_database_fetch_configuration.test_protected_database_fetch_configuration"
39+
40+
acctest.SaveConfigContent("", "", "", t)
41+
42+
acctest.ResourceTest(t, nil, []resource.TestStep{
43+
// verify singular datasource
44+
{
45+
Config: config +
46+
acctest.GenerateDataSourceFromRepresentationMap("oci_recovery_protected_database_fetch_configuration", "test_protected_database_fetch_configuration", acctest.Required, acctest.Create, RecoveryprotectedDatabaseFetchConfigurationSingularDataSourceRepresentation) +
47+
compartmentIdVariableStr + RecoveryProtectedDatabaseFetchConfigurationResourceConfig,
48+
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
49+
resource.TestCheckResourceAttr(singularDatasourceName, "base64_encode_content", "true"),
50+
resource.TestCheckResourceAttrSet(singularDatasourceName, "protected_database_id"),
51+
52+
resource.TestCheckResourceAttrSet(singularDatasourceName, "content"),
53+
),
54+
},
55+
56+
{
57+
Config: config +
58+
acctest.GenerateDataSourceFromRepresentationMap("oci_recovery_protected_database_fetch_configuration", "test_protected_database_fetch_configuration", acctest.Optional, acctest.Create, RecoveryprotectedDatabaseFetchConfigurationSingularDataSourceRepresentation) +
59+
compartmentIdVariableStr + RecoveryProtectedDatabaseFetchConfigurationResourceConfig,
60+
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
61+
resource.TestCheckResourceAttr(singularDatasourceName, "base64_encode_content", "false"),
62+
resource.TestCheckResourceAttr(singularDatasourceName, "configuration_type", "ALL"),
63+
resource.TestCheckResourceAttrSet(singularDatasourceName, "protected_database_id"),
64+
65+
resource.TestCheckResourceAttrSet(singularDatasourceName, "content"),
66+
),
67+
},
68+
})
69+
}

0 commit comments

Comments
 (0)