Skip to content

Commit 72ff788

Browse files
aapkumarvsin12
authored andcommitted
Added - Support for DBCS | Support A1 (Ampere) for VM DB
1 parent e860b85 commit 72ff788

File tree

2 files changed

+461
-0
lines changed

2 files changed

+461
-0
lines changed
Lines changed: 373 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,373 @@
1+
// Copyright (c) 2017, 2023, Oracle and/or its affiliates. All rights reserved.
2+
// Licensed under the Mozilla Public License v2.0
3+
variable "tenancy_ocid" {
4+
}
5+
6+
variable "user_ocid" {
7+
}
8+
9+
variable "fingerprint" {
10+
}
11+
12+
variable "private_key_path" {
13+
}
14+
15+
variable "region" {
16+
}
17+
18+
#variable "kms_key_id" {
19+
#}
20+
#
21+
#variable "kms_key_version_id" {
22+
#}
23+
#
24+
#variable "vault_id" {
25+
#}
26+
27+
variable "compartment_ocid" {
28+
}
29+
30+
variable "ssh_public_key" {
31+
default = "ssh-rsa KKKLK3NzaC1yc2EAAAADAQABAAABAQC+UC9MFNA55NIVtKPIBCNw7++ACXhD0hx+Zyj25JfHykjz/QU3Q5FAU3DxDbVXyubgXfb/GJnrKRY8O4QDdvnZZRvQFFEOaApThAmCAM5MuFUIHdFvlqP+0W+ZQnmtDhwVe2NCfcmOrMuaPEgOKO3DOW6I/qOOdO691Xe2S9NgT9HhN0ZfFtEODVgvYulgXuCCXsJs+NUqcHAOxxFUmwkbPvYi0P0e2DT8JKeiOOC8VKUEgvVx+GKmqasm+Y6zHFW7vv3g2GstE1aRs3mttHRoC/JPM86PRyIxeWXEMzyG5wHqUu4XZpDbnWNxi6ugxnAGiL3CrIFdCgRNgHz5qS1l MustWin"
32+
}
33+
34+
variable "ssh_private_key" {
35+
}
36+
37+
# DBSystem specific
38+
variable "db_system_shape" {
39+
default = "VM.Standard.A1.Flex"
40+
}
41+
42+
variable "cpu_core_count" {
43+
default = "2"
44+
}
45+
46+
variable "db_system_storage_volume_performance_mode" {
47+
default = "BALANCED"
48+
}
49+
50+
variable "db_edition" {
51+
default = "ENTERPRISE_EDITION"
52+
}
53+
54+
variable "db_admin_password" {
55+
default = "BEstrO0ng_#12"
56+
}
57+
58+
variable "db_version" {
59+
default = "19.0.0.0"
60+
}
61+
62+
variable "db_disk_redundancy" {
63+
default = "NORMAL"
64+
}
65+
66+
variable "sparse_diskgroup" {
67+
default = true
68+
}
69+
70+
variable "hostname" {
71+
default = "myoracledb"
72+
}
73+
74+
variable "host_user_name" {
75+
default = "opc"
76+
}
77+
78+
variable "n_character_set" {
79+
default = "AL16UTF16"
80+
}
81+
82+
variable "character_set" {
83+
default = "AL32UTF8"
84+
}
85+
86+
variable "db_workload" {
87+
default = "OLTP"
88+
}
89+
90+
variable "pdb_name" {
91+
default = "pdbName"
92+
}
93+
94+
variable "data_storage_size_in_gb" {
95+
default = "256"
96+
}
97+
98+
variable "license_model" {
99+
default = "LICENSE_INCLUDED"
100+
}
101+
102+
variable "node_count" {
103+
default = "1"
104+
}
105+
106+
variable "test_database_software_image_ocid" {
107+
108+
}
109+
110+
provider "oci" {
111+
# version = "4.70.0"
112+
tenancy_ocid = var.tenancy_ocid
113+
user_ocid = var.user_ocid
114+
fingerprint = var.fingerprint
115+
private_key_path = var.private_key_path
116+
region = var.region
117+
}
118+
119+
data "oci_identity_availability_domain" "ad" {
120+
compartment_id = var.tenancy_ocid
121+
ad_number = 1
122+
}
123+
124+
# Get DB node list
125+
data "oci_database_db_nodes" "db_nodes" {
126+
compartment_id = var.compartment_ocid
127+
db_system_id = oci_database_db_system.test_db_system.id
128+
}
129+
130+
# Get DB node details
131+
data "oci_database_db_node" "db_node_details" {
132+
db_node_id = data.oci_database_db_nodes.db_nodes.db_nodes[0]["id"]
133+
}
134+
135+
# Gets the OCID of the first (default) vNIC
136+
#data "oci_core_vnic" "db_node_vnic" {
137+
# vnic_id = data.oci_database_db_node.db_node_details.vnic_id
138+
#}
139+
140+
data "oci_database_db_homes" "db_homes" {
141+
compartment_id = var.compartment_ocid
142+
db_system_id = oci_database_db_system.test_db_system.id
143+
}
144+
145+
data "oci_database_databases" "databases" {
146+
compartment_id = var.compartment_ocid
147+
db_home_id = data.oci_database_db_homes.db_homes.db_homes[0].db_home_id
148+
}
149+
150+
data "oci_database_db_versions" "test_db_versions_by_db_system_id" {
151+
compartment_id = var.compartment_ocid
152+
db_system_id = oci_database_db_system.test_db_system.id
153+
}
154+
155+
resource "oci_database_backup" "test_backup" {
156+
database_id = "${data.oci_database_databases.databases.databases.0.id}"
157+
display_name = "Monthly Backup"
158+
}
159+
160+
data "oci_database_db_system_shapes" "test_db_system_shapes" {
161+
availability_domain = data.oci_identity_availability_domain.ad.name
162+
compartment_id = var.compartment_ocid
163+
164+
filter {
165+
name = "shape"
166+
values = [var.db_system_shape]
167+
}
168+
}
169+
170+
data "oci_database_db_systems" "db_systems" {
171+
compartment_id = var.compartment_ocid
172+
173+
filter {
174+
name = "id"
175+
values = [oci_database_db_system.test_db_system.id]
176+
}
177+
}
178+
179+
resource "oci_core_vcn" "vcn" {
180+
cidr_block = "10.1.0.0/16"
181+
compartment_id = var.compartment_ocid
182+
display_name = "TFExampleVCNDBSystem"
183+
dns_label = "tfexvcndbsys"
184+
}
185+
186+
resource "oci_core_subnet" "subnet" {
187+
availability_domain = data.oci_identity_availability_domain.ad.name
188+
cidr_block = "10.1.20.0/24"
189+
display_name = "TFExampleSubnetDBSystem"
190+
dns_label = "tfexsubdbsys"
191+
security_list_ids = [oci_core_security_list.ExampleSecurityList.id]
192+
compartment_id = var.compartment_ocid
193+
vcn_id = oci_core_vcn.vcn.id
194+
route_table_id = oci_core_route_table.route_table.id
195+
dhcp_options_id = oci_core_vcn.vcn.default_dhcp_options_id
196+
}
197+
198+
resource "oci_core_subnet" "subnet_backup" {
199+
availability_domain = data.oci_identity_availability_domain.ad.name
200+
cidr_block = "10.1.1.0/24"
201+
display_name = "TFExampleSubnetDBSystemBackup"
202+
dns_label = "tfexsubdbsysbp"
203+
security_list_ids = [oci_core_security_list.ExampleSecurityList.id]
204+
compartment_id = var.compartment_ocid
205+
vcn_id = oci_core_vcn.vcn.id
206+
route_table_id = oci_core_route_table.route_table_backup.id
207+
dhcp_options_id = oci_core_vcn.vcn.default_dhcp_options_id
208+
}
209+
210+
resource "oci_core_internet_gateway" "internet_gateway" {
211+
compartment_id = var.compartment_ocid
212+
display_name = "TFExampleIGDBSystem"
213+
vcn_id = oci_core_vcn.vcn.id
214+
}
215+
216+
resource "oci_core_route_table" "route_table" {
217+
compartment_id = var.compartment_ocid
218+
vcn_id = oci_core_vcn.vcn.id
219+
display_name = "TFExampleRouteTableDBSystem"
220+
221+
route_rules {
222+
destination = "0.0.0.0/0"
223+
destination_type = "CIDR_BLOCK"
224+
network_entity_id = oci_core_internet_gateway.internet_gateway.id
225+
}
226+
}
227+
228+
resource "oci_core_route_table" "route_table_backup" {
229+
compartment_id = var.compartment_ocid
230+
vcn_id = oci_core_vcn.vcn.id
231+
display_name = "TFExampleRouteTableDBSystemBackup"
232+
233+
route_rules {
234+
destination = "0.0.0.0/0"
235+
destination_type = "CIDR_BLOCK"
236+
network_entity_id = oci_core_internet_gateway.internet_gateway.id
237+
}
238+
}
239+
240+
resource "oci_core_security_list" "ExampleSecurityList" {
241+
compartment_id = var.compartment_ocid
242+
vcn_id = oci_core_vcn.vcn.id
243+
display_name = "TFExampleSecurityList"
244+
245+
// allow outbound tcp traffic on all ports
246+
egress_security_rules {
247+
destination = "0.0.0.0/0"
248+
protocol = "6"
249+
}
250+
251+
// allow outbound udp traffic on a port range
252+
egress_security_rules {
253+
destination = "0.0.0.0/0"
254+
protocol = "17" // udp
255+
stateless = true
256+
}
257+
258+
egress_security_rules {
259+
destination = "0.0.0.0/0"
260+
protocol = "1"
261+
stateless = true
262+
}
263+
264+
// allow inbound ssh traffic from a specific port
265+
ingress_security_rules {
266+
protocol = "6" // tcp
267+
source = "0.0.0.0/0"
268+
stateless = false
269+
}
270+
271+
// allow inbound icmp traffic of a specific type
272+
ingress_security_rules {
273+
protocol = 1
274+
source = "0.0.0.0/0"
275+
stateless = true
276+
}
277+
}
278+
279+
resource "oci_core_network_security_group" "test_network_security_group" {
280+
compartment_id = var.compartment_ocid
281+
vcn_id = oci_core_vcn.vcn.id
282+
display_name = "displayName"
283+
}
284+
285+
resource "oci_core_network_security_group" "test_network_security_group_backup" {
286+
compartment_id = var.compartment_ocid
287+
vcn_id = oci_core_vcn.vcn.id
288+
display_name = "displayName"
289+
}
290+
291+
resource "oci_database_db_system" "test_db_system" {
292+
availability_domain = data.oci_identity_availability_domain.ad.name
293+
compartment_id = var.compartment_ocid
294+
database_edition = var.db_edition
295+
296+
db_home {
297+
database {
298+
admin_password = var.db_admin_password
299+
# kms_key_version_id = var.kms_key_version_id
300+
# kms_key_id = var.kms_key_id
301+
# vault_id = var.vault_id
302+
db_name = "aTFdbVm"
303+
character_set = var.character_set
304+
ncharacter_set = var.n_character_set
305+
db_workload = var.db_workload
306+
pdb_name = var.pdb_name
307+
308+
db_backup_config {
309+
auto_backup_enabled = false
310+
}
311+
}
312+
313+
db_version = "19.0.0.0"
314+
display_name = "MyTFDBHomeVm"
315+
}
316+
317+
db_system_options {
318+
storage_management = "LVM"
319+
}
320+
321+
disk_redundancy = var.db_disk_redundancy
322+
shape = var.db_system_shape
323+
cpu_core_count = var.cpu_core_count
324+
storage_volume_performance_mode = var.db_system_storage_volume_performance_mode
325+
subnet_id = oci_core_subnet.subnet.id
326+
ssh_public_keys = [var.ssh_public_key]
327+
display_name = "MyTFDBSystemVM"
328+
hostname = var.hostname
329+
data_storage_size_in_gb = var.data_storage_size_in_gb
330+
license_model = var.license_model
331+
node_count = data.oci_database_db_system_shapes.test_db_system_shapes.db_system_shapes[0]["minimum_node_count"]
332+
nsg_ids = [oci_core_network_security_group.test_network_security_group_backup.id, oci_core_network_security_group.test_network_security_group.id]
333+
334+
#To use defined_tags, set the values below to an existing tag namespace, refer to the identity example on how to create tag namespaces
335+
#defined_tags = {"${oci_identity_tag_namespace.tag-namespace1.name}.${oci_identity_tag.tag1.name}" = "value"}
336+
337+
freeform_tags = {
338+
"Department" = "Finance"
339+
}
340+
}
341+
342+
resource "oci_database_db_system" "db_system_bkup" {
343+
source = "DB_BACKUP"
344+
availability_domain = data.oci_identity_availability_domain.ad.name
345+
compartment_id = var.compartment_ocid
346+
subnet_id = oci_core_subnet.subnet.id
347+
database_edition = var.db_edition
348+
disk_redundancy = var.db_disk_redundancy
349+
shape = var.db_system_shape
350+
cpu_core_count= var.cpu_core_count
351+
storage_volume_performance_mode= var.db_system_storage_volume_performance_mode
352+
ssh_public_keys = [var.ssh_public_key]
353+
hostname = var.hostname
354+
data_storage_size_in_gb = var.data_storage_size_in_gb
355+
license_model = var.license_model
356+
node_count = data.oci_database_db_system_shapes.test_db_system_shapes.db_system_shapes[0]["minimum_node_count"]
357+
display_name = "tfDbSystemFromBackupWithCustImg"
358+
359+
db_system_options {
360+
storage_management = "LVM"
361+
}
362+
363+
db_home {
364+
db_version = "19.0.0.0"
365+
# database_software_image_id = var.test_database_software_image_ocid
366+
database {
367+
admin_password = "BEstrO0ng_#11"
368+
backup_tde_password = "BEstrO0ng_#11"
369+
backup_id = "${oci_database_backup.test_backup.id}"
370+
db_name = "dbback"
371+
}
372+
}
373+
}

0 commit comments

Comments
 (0)