Skip to content

Commit 48e5773

Browse files
jiangongafedorch
authored andcommitted
[Terraform] Exadata Sparse disk group [SDK 11.29]
add exadata db example
1 parent d104524 commit 48e5773

14 files changed

+325
-5
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Gets a list of Availability Domains
2+
data "oci_identity_availability_domains" "ADs" {
3+
compartment_id = "${var.tenancy_ocid}"
4+
}
5+
6+
# Get DB node list
7+
data "oci_database_db_nodes" "db_nodes" {
8+
compartment_id = "${var.compartment_ocid}"
9+
db_system_id = "${oci_database_db_system.test_db_system.id}"
10+
}
11+
12+
# Get DB node details
13+
data "oci_database_db_node" "db_node_details" {
14+
db_node_id = "${lookup(data.oci_database_db_nodes.db_nodes.db_nodes[0], "id")}"
15+
}
16+
17+
# Gets the OCID of the first (default) vNIC
18+
#data "oci_core_vnic" "db_node_vnic" {
19+
# vnic_id = "${data.oci_database_db_node.db_node_details.vnic_id}"
20+
#}
21+
22+
data "oci_database_db_homes" "db_homes" {
23+
compartment_id = "${var.compartment_ocid}"
24+
db_system_id = "${oci_database_db_system.test_db_system.id}"
25+
}
26+
27+
data "oci_database_databases" "databases" {
28+
compartment_id = "${var.compartment_ocid}"
29+
db_home_id = "${data.oci_database_db_homes.db_homes.db_homes.0.db_home_id}"
30+
}
31+
32+
data "oci_database_db_versions" "test_db_versions_by_db_system_id" {
33+
compartment_id = "${var.compartment_ocid}"
34+
db_system_id = "${oci_database_db_system.test_db_system.id}"
35+
}
36+
37+
data "oci_database_db_system_shapes" "test_db_system_shapes" {
38+
availability_domain = "${lookup(data.oci_identity_availability_domains.ADs.availability_domains[var.availability_domain - 1],"name")}"
39+
compartment_id = "${var.compartment_ocid}"
40+
41+
filter {
42+
name = "shape"
43+
values = ["${var.db_system_shape}"]
44+
}
45+
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
resource "oci_core_virtual_network" "vcn" {
2+
cidr_block = "10.1.0.0/16"
3+
compartment_id = "${var.compartment_ocid}"
4+
display_name = "TFExampleVCNDBSystem"
5+
dns_label = "tfexvcndbsys"
6+
}
7+
8+
resource "oci_core_subnet" "subnet" {
9+
availability_domain = "${lookup(data.oci_identity_availability_domains.ADs.availability_domains[var.availability_domain - 1],"name")}"
10+
cidr_block = "10.1.20.0/24"
11+
display_name = "TFExampleSubnetDBSystem"
12+
dns_label = "tfexsubdbsys"
13+
security_list_ids = ["${oci_core_security_list.ExampleSecurityList.id}"]
14+
compartment_id = "${var.compartment_ocid}"
15+
vcn_id = "${oci_core_virtual_network.vcn.id}"
16+
route_table_id = "${oci_core_route_table.route_table.id}"
17+
dhcp_options_id = "${oci_core_virtual_network.vcn.default_dhcp_options_id}"
18+
}
19+
20+
resource "oci_core_subnet" "subnet_backup" {
21+
availability_domain = "${lookup(data.oci_identity_availability_domains.ADs.availability_domains[var.availability_domain - 1],"name")}"
22+
cidr_block = "10.1.1.0/24"
23+
display_name = "TFExampleSubnetDBSystemBackup"
24+
dns_label = "tfexsubdbsysbp"
25+
security_list_ids = ["${oci_core_security_list.ExampleSecurityList.id}"]
26+
compartment_id = "${var.compartment_ocid}"
27+
vcn_id = "${oci_core_virtual_network.vcn.id}"
28+
route_table_id = "${oci_core_route_table.route_table_backup.id}"
29+
dhcp_options_id = "${oci_core_virtual_network.vcn.default_dhcp_options_id}"
30+
}
31+
32+
resource "oci_core_internet_gateway" "internet_gateway" {
33+
compartment_id = "${var.compartment_ocid}"
34+
display_name = "TFExampleIGDBSystem"
35+
vcn_id = "${oci_core_virtual_network.vcn.id}"
36+
}
37+
38+
resource "oci_core_route_table" "route_table" {
39+
compartment_id = "${var.compartment_ocid}"
40+
vcn_id = "${oci_core_virtual_network.vcn.id}"
41+
display_name = "TFExampleRouteTableDBSystem"
42+
43+
route_rules {
44+
destination = "0.0.0.0/0"
45+
destination_type = "CIDR_BLOCK"
46+
network_entity_id = "${oci_core_internet_gateway.internet_gateway.id}"
47+
}
48+
}
49+
50+
resource "oci_core_route_table" "route_table_backup" {
51+
compartment_id = "${var.compartment_ocid}"
52+
vcn_id = "${oci_core_virtual_network.vcn.id}"
53+
display_name = "TFExampleRouteTableDBSystemBackup"
54+
55+
route_rules {
56+
destination = "0.0.0.0/0"
57+
destination_type = "CIDR_BLOCK"
58+
network_entity_id = "${oci_core_internet_gateway.internet_gateway.id}"
59+
}
60+
}
61+
62+
resource "oci_core_security_list" "ExampleSecurityList" {
63+
compartment_id = "${var.compartment_ocid}"
64+
vcn_id = "${oci_core_virtual_network.vcn.id}"
65+
display_name = "TFExampleSecurityList"
66+
67+
// allow outbound tcp traffic on all ports
68+
egress_security_rules {
69+
destination = "0.0.0.0/0"
70+
protocol = "6"
71+
}
72+
73+
// allow outbound udp traffic on a port range
74+
egress_security_rules {
75+
destination = "0.0.0.0/0"
76+
protocol = "17" // udp
77+
stateless = true
78+
}
79+
80+
egress_security_rules {
81+
destination = "0.0.0.0/0"
82+
protocol = "1"
83+
stateless = true
84+
}
85+
86+
// allow inbound ssh traffic from a specific port
87+
ingress_security_rules {
88+
protocol = "6" // tcp
89+
source = "0.0.0.0/0"
90+
stateless = false
91+
}
92+
93+
// allow inbound icmp traffic of a specific type
94+
ingress_security_rules {
95+
protocol = 1
96+
source = "0.0.0.0/0"
97+
stateless = true
98+
}
99+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
provider "oci" {
2+
tenancy_ocid = "${var.tenancy_ocid}"
3+
user_ocid = "${var.user_ocid}"
4+
fingerprint = "${var.fingerprint}"
5+
private_key_path = "${var.private_key_path}"
6+
region = "${var.region}"
7+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
resource "oci_database_db_system" "test_db_system" {
2+
availability_domain = "${lookup(data.oci_identity_availability_domains.ADs.availability_domains[var.availability_domain - 1],"name")}"
3+
compartment_id = "${var.compartment_ocid}"
4+
cpu_core_count = "${var.cpu_core_count}"
5+
database_edition = "${var.db_edition}"
6+
7+
db_home {
8+
database {
9+
admin_password = "${var.db_admin_password}"
10+
db_name = "${var.db_name}"
11+
character_set = "${var.character_set}"
12+
ncharacter_set = "${var.n_character_set}"
13+
db_workload = "${var.db_workload}"
14+
pdb_name = "${var.pdb_name}"
15+
16+
db_backup_config {
17+
auto_backup_enabled = false
18+
}
19+
}
20+
21+
db_version = "${var.db_version}"
22+
display_name = "${var.db_home_display_name}"
23+
}
24+
25+
disk_redundancy = "${var.db_disk_redundancy}"
26+
shape = "${var.db_system_shape}"
27+
subnet_id = "${oci_core_subnet.subnet.id}"
28+
backup_subnet_id = "${oci_core_subnet.subnet_backup.id}"
29+
ssh_public_keys = ["${var.ssh_public_key}"]
30+
display_name = "${var.db_system_display_name}"
31+
sparse_diskgroup = "${var.sparse_diskgroup}"
32+
33+
hostname = "${var.hostname}"
34+
data_storage_percentage = "${var.data_storage_percentage}"
35+
36+
#data_storage_size_in_gb = "${var.data_storage_size_in_gb}"
37+
license_model = "${var.license_model}"
38+
node_count = "${lookup(data.oci_database_db_system_shapes.test_db_system_shapes.db_system_shapes[0], "minimum_node_count")}"
39+
40+
#To use defined_tags, set the values below to an existing tag namespace, refer to the identity example on how to create tag namespaces
41+
#defined_tags = "${map("example-tag-namespace-all.example-tag", "originalValue")}"
42+
43+
freeform_tags = {
44+
"Department" = "Finance"
45+
}
46+
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
variable "tenancy_ocid" {}
2+
variable "user_ocid" {}
3+
variable "fingerprint" {}
4+
variable "private_key_path" {}
5+
variable "region" {}
6+
7+
variable "compartment_ocid" {}
8+
variable "ssh_public_key" {}
9+
variable "ssh_private_key" {}
10+
11+
# Choose an Availability Domain
12+
variable "availability_domain" {
13+
default = "2"
14+
}
15+
16+
# DBSystem specific
17+
variable "db_system_shape" {
18+
default = "Exadata.Quarter1.84"
19+
}
20+
21+
variable "cpu_core_count" {
22+
default = "22"
23+
}
24+
25+
variable "db_edition" {
26+
default = "ENTERPRISE_EDITION_EXTREME_PERFORMANCE"
27+
}
28+
29+
variable "db_admin_password" {
30+
default = "BEstrO0ng_#12"
31+
}
32+
33+
variable "db_name" {
34+
default = "aTFdb"
35+
}
36+
37+
variable "db_version" {
38+
default = "12.1.0.2"
39+
}
40+
41+
variable "db_home_display_name" {
42+
default = "MyTFDBHome"
43+
}
44+
45+
variable "db_disk_redundancy" {
46+
default = "HIGH"
47+
}
48+
49+
variable "sparse_diskgroup" {
50+
default = true
51+
}
52+
53+
variable "db_system_display_name" {
54+
default = "MyTFDBSystem"
55+
}
56+
57+
variable "hostname" {
58+
default = "myoracledb"
59+
}
60+
61+
variable "host_user_name" {
62+
default = "opc"
63+
}
64+
65+
variable "n_character_set" {
66+
default = "AL16UTF16"
67+
}
68+
69+
variable "character_set" {
70+
default = "AL32UTF8"
71+
}
72+
73+
variable "db_workload" {
74+
default = "OLTP"
75+
}
76+
77+
variable "pdb_name" {
78+
default = "pdbName"
79+
}
80+
81+
variable "data_storage_size_in_gb" {
82+
default = "256"
83+
}
84+
85+
variable "license_model" {
86+
default = "LICENSE_INCLUDED"
87+
}
88+
89+
variable "node_count" {
90+
default = "2"
91+
}
92+
93+
variable "data_storage_percentage" {
94+
default = "40"
95+
}

oci/database_db_system_resource.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,12 @@ func DbSystemResource() *schema.Resource {
275275
"NONE",
276276
}, true),
277277
},
278+
"sparse_diskgroup": {
279+
Type: schema.TypeBool,
280+
Optional: true,
281+
Computed: true,
282+
ForceNew: true,
283+
},
278284

279285
// Computed
280286
"last_patch_history_entry_id": {
@@ -590,6 +596,10 @@ func (s *DbSystemResourceCrud) SetData() error {
590596
s.D.Set("shape", *s.Res.Shape)
591597
}
592598

599+
if s.Res.SparseDiskgroup != nil {
600+
s.D.Set("sparse_diskgroup", *s.Res.SparseDiskgroup)
601+
}
602+
593603
s.D.Set("ssh_public_keys", s.Res.SshPublicKeys)
594604

595605
s.D.Set("state", s.Res.LifecycleState)
@@ -922,6 +932,11 @@ func (s *DbSystemResourceCrud) populateTopLevelPolymorphicLaunchDbSystemRequest(
922932
tmp := shape.(string)
923933
details.Shape = &tmp
924934
}
935+
if sparseDiskgroup, ok := s.D.GetOkExists("sparse_diskgroup"); ok {
936+
tmp := sparseDiskgroup.(bool)
937+
details.SparseDiskgroup = &tmp
938+
}
939+
details.SshPublicKeys = []string{}
925940
if sshPublicKeys, ok := s.D.GetOkExists("ssh_public_keys"); ok {
926941
interfaces := sshPublicKeys.([]interface{})
927942
tmp := make([]string, len(interfaces))
@@ -1016,6 +1031,11 @@ func (s *DbSystemResourceCrud) populateTopLevelPolymorphicLaunchDbSystemRequest(
10161031
tmp := shape.(string)
10171032
details.Shape = &tmp
10181033
}
1034+
if sparseDiskgroup, ok := s.D.GetOkExists("sparse_diskgroup"); ok {
1035+
tmp := sparseDiskgroup.(bool)
1036+
details.SparseDiskgroup = &tmp
1037+
}
1038+
details.SshPublicKeys = []string{}
10191039
if sshPublicKeys, ok := s.D.GetOkExists("ssh_public_keys"); ok {
10201040
interfaces := sshPublicKeys.([]interface{})
10211041
tmp := make([]string, len(interfaces))

oci/database_db_systems_data_source.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,10 @@ func (s *DbSystemsDataSourceCrud) SetData() error {
226226
dbSystem["shape"] = *r.Shape
227227
}
228228

229+
if r.SparseDiskgroup != nil {
230+
dbSystem["sparse_diskgroup"] = *r.SparseDiskgroup
231+
}
232+
229233
dbSystem["ssh_public_keys"] = r.SshPublicKeys
230234

231235
dbSystem["state"] = r.LifecycleState

oci/examples_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ func GetConfigPaths(t *testing.T, rootPath string) (pathList []string, err error
131131
}
132132

133133
func shouldSkip(dir string) bool {
134-
blackList := []string{"/db_systems", "/adw_backup", "/atp_backup", "/block", "launch_by_subscription", "subscription"}
134+
blackList := []string{"/db_exadata", "/db_systems", "/adw_backup", "/atp_backup", "/block", "launch_by_subscription", "subscription"}
135135
var flag bool
136136
for _, blackDir := range blackList {
137137
flag = flag || strings.HasSuffix(dir, blackDir)

website/docs/d/database_autonomous_data_warehouse_wallet.html.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ data "oci_database_autonomous_data_warehouse_wallet" "test_autonomous_data_wareh
2626
The following arguments are supported:
2727

2828
* `autonomous_data_warehouse_id` - (Required) The database [OCID](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm).
29-
* `password` - (Required) The password to encrypt the keys inside the wallet.
29+
* `password` - (Required) The password to encrypt the keys inside the wallet. The password must be at least 8 characters long and must include at least 1 letter and either 1 numeric character or 1 special character.
3030

3131

3232
## Attributes Reference

website/docs/d/database_autonomous_database_wallet.html.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ data "oci_database_autonomous_database_wallet" "test_autonomous_database_wallet"
2626
The following arguments are supported:
2727

2828
* `autonomous_database_id` - (Required) The database [OCID](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm).
29-
* `password` - (Required) The password to encrypt the keys inside the wallet.
29+
* `password` - (Required) The password to encrypt the keys inside the wallet. The password must be at least 8 characters long and must include at least 1 letter and either 1 numeric character or 1 special character.
3030

3131

3232
## Attributes Reference

0 commit comments

Comments
 (0)