Skip to content

Commit 3be00d6

Browse files
authored
Merge pull request #56 from yasinbaskan/feature/terraform_adg
Terraform examples for local and cross-region standby
2 parents deb2aab + ff2ecb6 commit 3be00d6

15 files changed

Lines changed: 296 additions & 0 deletions

File tree

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,10 @@ Temporary Items
3232
.csr
3333
.pem
3434
replace-default-config.sh
35+
36+
# Terraform
37+
**/.terraform/
38+
*.tfstate
39+
*.tfstate.*
40+
crash.log
41+
crash.*.log
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Autonomous AI Database with a cross-region standby
2+
3+
This Terraform example creates an Autonomous AI Database with a cross-region standby.
4+
5+
You can run it by updating the file _terraform.tfvars_ file with the settings you want.
6+
7+
Enter your tenancy OCID, user OCID, user fingerprint, private key file path, region name, and compartment OCID. Change the other settings like database name and compute count to your liking and enter the ADMIN user password you want.
8+
9+
```tenancy_ocid = ""
10+
user_ocid = ""
11+
fingerprint = ""
12+
private_key_path = ""
13+
14+
compartment_ocid = ""
15+
16+
primary_region = "us-ashburn-1"
17+
standby_region = "us-phoenix-1"
18+
19+
adb_display_name = "primarydb"
20+
adb_db_name = "primarydb"
21+
22+
admin_password = ""
23+
24+
db_workload = "OLTP"
25+
26+
compute_count = 2
27+
data_storage_size_in_tbs = 1
28+
```
29+
30+
31+
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
resource "oci_database_autonomous_database" "primary" {
2+
provider = oci.primary
3+
4+
compartment_id = var.compartment_ocid
5+
6+
display_name = var.adb_display_name
7+
db_name = var.adb_db_name
8+
9+
db_workload = var.db_workload
10+
compute_model = var.compute_model
11+
compute_count = var.compute_count
12+
data_storage_size_in_tbs = var.data_storage_size_in_tbs
13+
14+
admin_password = var.admin_password
15+
}
16+
17+
# Cross-region standby (Autonomous Data Guard)
18+
resource "oci_database_autonomous_database" "standby" {
19+
provider = oci.standby
20+
21+
compartment_id = var.compartment_ocid
22+
23+
# Create standby in another region:
24+
source = "CROSS_REGION_DATAGUARD"
25+
source_id = oci_database_autonomous_database.primary.id
26+
27+
display_name = "${var.adb_display_name}-standby"
28+
db_name = oci_database_autonomous_database.primary.db_name
29+
30+
depends_on = [oci_database_autonomous_database.primary]
31+
}
32+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
output "primary_adb_id" {
2+
value = oci_database_autonomous_database.primary.id
3+
}
4+
5+
output "standby_adb_id" {
6+
value = oci_database_autonomous_database.standby.id
7+
}
8+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
provider "oci" {
2+
alias = "primary"
3+
tenancy_ocid = var.tenancy_ocid
4+
user_ocid = var.user_ocid
5+
fingerprint = var.fingerprint
6+
private_key_path = var.private_key_path
7+
region = var.primary_region
8+
}
9+
10+
provider "oci" {
11+
alias = "standby"
12+
tenancy_ocid = var.tenancy_ocid
13+
user_ocid = var.user_ocid
14+
fingerprint = var.fingerprint
15+
private_key_path = var.private_key_path
16+
region = var.standby_region
17+
}
18+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
tenancy_ocid = ""
2+
user_ocid = ""
3+
fingerprint = ""
4+
private_key_path = ""
5+
6+
compartment_ocid = ""
7+
8+
primary_region = "us-ashburn-1"
9+
standby_region = "us-phoenix-1"
10+
11+
adb_display_name = "primarydb"
12+
adb_db_name = "primarydb"
13+
14+
admin_password = ""
15+
16+
db_workload = "OLTP"
17+
18+
compute_count = 2
19+
data_storage_size_in_tbs = 1
20+
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
variable "tenancy_ocid" { type = string }
2+
variable "user_ocid" { type = string }
3+
variable "fingerprint" { type = string }
4+
variable "private_key_path" { type = string }
5+
6+
variable "compartment_ocid" { type = string }
7+
8+
variable "primary_region" { type = string }
9+
variable "standby_region" { type = string }
10+
11+
variable "adb_display_name" { type = string }
12+
variable "adb_db_name" { type = string }
13+
14+
variable "admin_password" {
15+
type = string
16+
sensitive = true
17+
}
18+
19+
variable "db_workload" {
20+
type = string
21+
}
22+
23+
variable "compute_model" {
24+
type = string
25+
default = "ECPU"
26+
}
27+
28+
variable "compute_count" {
29+
type = number
30+
}
31+
32+
variable "data_storage_size_in_tbs" {
33+
type = number
34+
}
35+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
terraform {
2+
required_version = ">= 1.5.0"
3+
4+
required_providers {
5+
oci = {
6+
source = "oracle/oci"
7+
version = ">= 5.0.0"
8+
}
9+
}
10+
}
11+
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Autonomous AI Database with a local standby
2+
3+
This Terraform example creates an Autonomous AI Database with a local standby.
4+
5+
You can run it by updating the file _terraform.tfvars_ file with the settings you want.
6+
7+
Enter your tenancy OCID, user OCID, user fingerprint, private key file path, region name, and compartment OCID. Change the other settings like database name and compute count to your liking and enter the ADMIN user password you want.
8+
9+
```tenancy_ocid = ""
10+
user_ocid = ""
11+
fingerprint = ""
12+
private_key_path = ""
13+
region = "us-ashburn-1"
14+
15+
compartment_ocid = ""
16+
17+
db_name = "primarydb"
18+
display_name = "primarydb"
19+
admin_password = ""
20+
compute_count = 2
21+
data_storage_tbs = 1
22+
db_workload = "OLTP"
23+
```
24+
25+
26+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
resource "oci_database_autonomous_database" "primary" {
2+
compartment_id = var.compartment_ocid
3+
4+
db_name = var.db_name
5+
display_name = var.display_name
6+
db_workload = var.db_workload
7+
8+
admin_password = var.admin_password
9+
compute_model = var.compute_model
10+
compute_count = var.compute_count
11+
data_storage_size_in_tbs = var.data_storage_tbs
12+
13+
# Local (in-region) standby
14+
is_local_data_guard_enabled = true
15+
}
16+

0 commit comments

Comments
 (0)