Skip to content

Commit c2a0837

Browse files
committed
Merge branch 'hyder-12-examples-lb'
2 parents b4f2d30 + 7675908 commit c2a0837

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+682
-571
lines changed

README.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
:uri-oracle: https://www.oracle.com
2828
:uri-prereqs: {uri-docs}/prerequisites.adoc
2929
:uri-quickstart: {uri-docs}/quickstart.adoc
30-
:uri-reuse-module: {uri-rel-tree-base}/examples/gitlab
30+
:uri-reuse-module: {uri-rel-tree-base}/examples/db
3131
:uri-terraform: https://www.terraform.io
3232
:uri-terraform-cidrsubnet-deconstructed: http://blog.itsjustcode.net/blog/2017/11/18/terraform-cidrsubnet-deconstructed/
3333
:uri-terraform-hashircorp-examples: https://github.com/hashicorp/terraform-guides/tree/master/infrastructure-as-code/terraform-0.12-examples

datasources.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Copyright 2017, 2019, Oracle Corporation and/or affiliates. All rights reserved.
2-
# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl
2+
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
33

44
data "oci_identity_availability_domains" "ad_list" {
55
compartment_id = var.oci_base_identity.tenancy_id

docs/README.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
:uri-oci-documentation: https://docs.cloud.oracle.com/iaas/Content/home.htm
2222
:uri-prereqs: {uri-docs}/prerequisites.adoc
2323
:uri-quickstart: {uri-docs}/quickstart.adoc
24-
:uri-reuse-module: {uri-rel-tree-base}/examples/gitlab
24+
:uri-reuse-module: {uri-rel-tree-base}/examples/db
2525
:uri-terraform-cidrsubnet-deconstructed: http://blog.itsjustcode.net/blog/2017/11/18/terraform-cidrsubnet-deconstructed/
2626
:uri-terraform-hashircorp-examples: https://github.com/hashicorp/terraform-guides/tree/master/infrastructure-as-code/terraform-0.12-examples
2727
:uri-terraform-oci: https://www.terraform.io/docs/providers/oci/index.html

docs/quickstart.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
:uri-docs: {uri-rel-file-base}/docs
1212
:uri-instance-principal: {uri-docs}/instanceprincipal.adoc
1313
:uri-ons: {uri-docs}/notifcations.adoc
14-
:uri-reusing: {uri-rel-tree-base}/examples/gitlab
14+
:uri-reusing: {uri-rel-tree-base}/examples/db
1515
:uri-oci-keys: https://docs.cloud.oracle.com/iaas/Content/API/Concepts/apisigningkey.htm
1616
:uri-oci-ocids: https://docs.cloud.oracle.com/iaas/Content/API/Concepts/apisigningkey.htm#five
1717
:uri-terraform: https://www.terraform.io

examples/db/README.md

Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
[rootvariables]:https://github.com/oracle/terraform-oci-base/blob/master/examples/db/variables.tf
2+
[rootlocals]:https://github.com/oracle/terraform-oci-base/blob/master/examples/db/locals.tf
3+
[terraformoptions]:https://github.com/oracle/terraform-oci-base/blob/master/docs/terraformoptions.adoc
4+
[dbvariables]:https://github.com/oracle/terraform-oci-base/blob/master/examples/db/modules/db/variables.tf
5+
[dbvariables]:https://github.com/oracle/terraform-oci-base/blob/master/examples/db/modules/db/security.tf
6+
[dbsubnet]:https://github.com/oracle/terraform-oci-base/blob/master/examples/db/modules/db/subnets.tf
7+
8+
Example reusing terraform-oci-base and extending to create a db instance from OCI Marketplace
9+
10+
## Create a new Terraform project
11+
12+
As an example, we’ll be using terraform-oci-base to create an Oracle Database on OCI. The steps required are the following:
13+
14+
1. Create a new directory for your project e.g. oracle-database
15+
16+
2. Create the following files in root directory of your project:
17+
18+
- variables.tf
19+
- locals.tf
20+
- provider.tf
21+
- main.tf
22+
- terraform.tfvars
23+
24+
3. Define the oci provider
25+
26+
```
27+
provider "oci" {
28+
tenancy_ocid = var.tenancy_id
29+
user_ocid = var.user_id
30+
fingerprint = var.api_fingerprint
31+
private_key_path = var.api_private_key_path
32+
region = var.region
33+
disable_auto_retries = false
34+
}
35+
```
36+
37+
4. Create the modules directory
38+
39+
```
40+
mkdir modules
41+
cd modules
42+
```
43+
44+
5. Add the terraform-oci-base module
45+
46+
```
47+
git clone https://github.com/oracle/terraform-oci-base.git base
48+
```
49+
50+
N.B. Cloning will be required until the module is published in Hashicorp's registry
51+
52+
## Define project variables
53+
54+
### Variables to reuse the base module
55+
56+
1. Define the base parameters in the root variables.tf. You can choose to keep the same object-oriented structure like in the base’s variables.tf or keep it flat.
57+
58+
See [variables.tf][rootvariables] in this directory.
59+
60+
2. Initialize the variables as in [locals.tf][rootlocals]
61+
62+
## Define your modules
63+
64+
1. Define the base module in root main.tf
65+
66+
```
67+
module "base" {
68+
source = "./modules/base"
69+
70+
# identity
71+
oci_base_identity = local.oci_base_identity
72+
73+
# general oci parameters
74+
oci_base_general = local.oci_base_general
75+
76+
# vcn parameters
77+
oci_base_vcn = local.oci_base_vcn
78+
79+
# bastion parameters
80+
oci_base_bastion = local.oci_base_bastion
81+
}
82+
```
83+
84+
2. Enter appropriate values for terraform.tfvars. Review [Terraform Options][terraformoptions] for reference
85+
86+
## Add your own modules
87+
88+
1. Create your own module e.g. db. In modules directory, create a db directory:
89+
90+
```
91+
mkdir db
92+
```
93+
94+
2. Define the necessary variables, resources (e.g [security lists][dbvariables], [subnets][dbsubnet], [compute][dbcompute]) and [data sources][dbdatasources].
95+
96+
3. Update the [locals.tf][[rootlocals]] to initialize the db variables
97+
98+
4. Add the db module in the main.tf
99+
100+
```
101+
module "db" {
102+
source = "./modules/db"
103+
104+
db_identity = local.db_identity
105+
106+
db_ssh_keys = local.oci_base_ssh_keys
107+
108+
db_oci_general = local.oci_base_general
109+
110+
db_bastion = local.db_bastion
111+
112+
db_network = local.db_network
113+
114+
db_config = local.db_config
115+
}
116+
```
117+
118+
5. Update your terraform variable file and add the database parameters:
119+
120+
```
121+
# db
122+
123+
db_system_shape = "VM.Standard2.8"
124+
125+
cpu_core_count = 2
126+
127+
db_edition = "ENTERPRISE_EDITION"
128+
129+
db_admin_password = "BEstrO0ng_#12"
130+
131+
db_name = "basedb"
132+
133+
db_home_db_name = "basedb2"
134+
135+
db_version = "19.0.0.0"
136+
137+
db_home_display_name = "basedbhome"
138+
139+
db_disk_redundancy = "HIGH"
140+
141+
db_system_display_name = "basedb_system"
142+
143+
hostname = "myoracledb"
144+
145+
n_character_set = "AL16UTF16"
146+
147+
character_set = "AL32UTF8"
148+
149+
db_workload = "OLTP"
150+
151+
pdb_name = "pdb1"
152+
153+
data_storage_size_in_gb = 256
154+
155+
license_model = "LICENSE_INCLUDED"
156+
157+
node_count = 2
158+
159+
data_storage_percentage = 40
160+
```
161+
162+
## Test access to your database:
163+
164+
1. Login to the OCI Console and note down the IP address of 1 of the database nodes.
165+
166+
2. ssh to the Database node:
167+
168+
```
169+
ssh -i </path/to/private_ssh_key> -J opc<bastion_public_ip_address> opc@<database_private_ip_address>
170+
```
171+
172+
3. Login to your database:
173+
174+
```
175+
sudo su - oracle
176+
sqlplus / as sysdba
177+
```

examples/db/locals.tf

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# Copyright 2017, 2019, Oracle Corporation and/or affiliates. All rights reserved.
2+
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
3+
4+
locals {
5+
oci_base_identity = {
6+
api_fingerprint = var.api_fingerprint
7+
api_private_key_path = var.api_private_key_path
8+
compartment_id = var.compartment_id
9+
tenancy_id = var.tenancy_id
10+
user_id = var.user_id
11+
}
12+
oci_base_general = {
13+
label_prefix = var.label_prefix
14+
region = var.region
15+
}
16+
17+
oci_base_ssh_keys = {
18+
ssh_private_key_path = var.ssh_private_key_path
19+
ssh_public_key_path = var.ssh_public_key_path
20+
}
21+
22+
oci_base_vcn = {
23+
create_nat_gateway = var.create_nat_gateway
24+
create_service_gateway = var.create_service_gateway
25+
vcn_cidr = var.vcn_cidr
26+
vcn_dns_label = var.vcn_dns_label
27+
vcn_name = var.vcn_name
28+
}
29+
30+
oci_base_bastion = {
31+
availability_domains = var.availability_domains["bastion"]
32+
bastion_access = var.bastion_access
33+
bastion_image_id = "NONE"
34+
bastion_shape = var.bastion_shape
35+
bastion_upgrade = false
36+
create_bastion = var.create_bastion
37+
enable_instance_principal = var.enable_instance_principal
38+
enable_notification = false
39+
newbits = var.newbits["bastion"]
40+
netnum = var.subnets["bastion"]
41+
notification_endpoint = ""
42+
notification_protocol = "EMAIL"
43+
notification_topic = "bastion"
44+
ssh_private_key_path = var.ssh_private_key_path
45+
ssh_public_key_path = var.ssh_public_key_path
46+
timezone = "Australia/Sydney"
47+
use_autonomous = false
48+
}
49+
50+
db_identity = {
51+
compartment_id = var.compartment_id
52+
tenancy_id = var.tenancy_id
53+
}
54+
55+
db_oci_general = {
56+
ad_names = module.base.ad_names
57+
availability_domain = var.availability_domains["db"]
58+
label_prefix = var.label_prefix
59+
region = var.region
60+
}
61+
62+
db_bastion = {
63+
bastion_public_ip = module.base.bastion_public_ip
64+
}
65+
66+
db_network = {
67+
ig_route_id = module.base.ig_route_id
68+
is_service_gateway_enabled = var.create_service_gateway
69+
nat_route_id = module.base.nat_route_id
70+
newbits = var.newbits
71+
subnets = var.subnets
72+
vcn_cidr = var.vcn_cidr
73+
vcn_id = module.base.vcn_id
74+
}
75+
76+
db_config = {
77+
db_system_shape = var.db_system_shape
78+
cpu_core_count = var.cpu_core_count
79+
db_edition = var.db_edition
80+
db_admin_password = var.db_admin_password
81+
db_name = var.db_name
82+
db_home_db_name = var.db_home_db_name
83+
db_version = var.db_version
84+
db_home_display_name = var.db_home_display_name
85+
db_disk_redundancy = var.db_disk_redundancy
86+
db_system_display_name = var.db_system_display_name
87+
hostname = var.hostname
88+
n_character_set = var.n_character_set
89+
character_set = var.character_set
90+
db_workload = var.db_workload
91+
pdb_name = var.pdb_name
92+
data_storage_size_in_gb = var.data_storage_size_in_gb
93+
license_model = var.license_model
94+
node_count = var.node_count
95+
data_storage_percentage = var.data_storage_percentage
96+
}
97+
98+
}
Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
# Copyright 2017, 2019, Oracle Corporation and/or affiliates. All rights reserved.
2-
# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl
2+
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
33

44
module "base" {
55
source = "./modules/base"
66

77
# identity
88
oci_base_identity = local.oci_base_identity
99

10-
# ssh keys
11-
oci_base_ssh_keys = local.oci_base_ssh_keys
12-
1310
# general oci parameters
1411
oci_base_general = local.oci_base_general
1512

@@ -20,19 +17,19 @@ module "base" {
2017
oci_base_bastion = local.oci_base_bastion
2118
}
2219

23-
module "gitlab" {
24-
source = "./modules/gitlab"
20+
module "db" {
21+
source = "./modules/db"
2522

26-
gitlab_identity = local.gitlab_identity
23+
db_identity = local.db_identity
2724

2825
# since they have the same signature, we can reuse that
29-
gitlab_ssh_keys = local.oci_base_ssh_keys
26+
db_ssh_keys = local.oci_base_ssh_keys
3027

31-
gitlab_oci_general = local.oci_base_general
28+
db_oci_general = local.db_oci_general
3229

33-
gitlab_bastion = local.gitlab_bastion
30+
db_bastion = local.db_bastion
3431

35-
gitlab_network = local.gitlab_network
32+
db_network = local.db_network
3633

37-
gitlab_config = local.gitlab_config
34+
db_config = local.db_config
3835
}

0 commit comments

Comments
 (0)