Skip to content

Commit dc1c1d8

Browse files
committed
Repo refactoring.
1 parent 3cebedb commit dc1c1d8

Some content is hidden

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

70 files changed

+1416
-1315
lines changed

README.md

Lines changed: 75 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,25 @@ Deploy Oracle Cloud services using Oracle [always free](https://docs.oracle.com/
2121
* [Requirements](#requirements)
2222
* [Setup RSA Key](#example-rsa-key-generation)
2323
* [Oracle provider setup](#oracle-provider-setup)
24-
* [Variables](#other-variables-to-adjust)
25-
* [Common resources](#common-resources)
24+
* [Project setup](#project-setup)
2625
* [Firewall](#firewall)
2726
* [OS](#os)
2827
* [Shape](#shape)
2928
* [Useful documentation](#useful-documentation)
3029

3130
### Repository structure
3231

33-
There are three examples:
32+
In this repositroy there are 7 terrafrom modules, in order of dependency:
3433

35-
* Deploy a [simple compute instance](simple-instance/)
36-
* Deploy two instances behind a network load balancer using an [instance pool](instance-pool/)
37-
* Deploy a [k3s-cluster](k3s-cluster/)
34+
* [simple-vcn](simple-vcn/) - Setup a VCN with two PUBLIC subnets
35+
* [private-vcn](private-vcn/) - Setup a VCN with one PUBLIC subnet and one PRIVATE subnet
36+
* [nat-instance](nat-instance/) - Setup a NAT instance (with the Oracle always free account you can't deploy a NAT gateway)
37+
* [simple-instance](simple-instance/) - Deploy a simple instance in a private or public subnet
38+
* [instance-pool](instance-pool/) - Deploy multiple instances using a Oracle instance pool and instance configurations
39+
* [load-balancer](load-balancer/) - Deploy a public load balancer (Layer 7 HTTP)
40+
* [network-load-balancer](network-load-balancer/) - Deploy a private load balancer (Layer 4 TCP)
41+
42+
For more information on how to use this modules follow the examples in the *examples* directory. To use this repository, clone this repository and use the *example* directory as base dir.
3843

3944
### Requirements
4045

@@ -44,6 +49,12 @@ To use this repo you will need:
4449

4550
Once you get the account, follow the *Before you begin* and *1. Prepare* step in [this](https://docs.oracle.com/en-us/iaas/developer-tutorials/tutorials/tf-provider/01-summary.htm) document.
4651

52+
You need also:
53+
54+
* [Terraform](https://www.terraform.io/) - Terraform is an open-source infrastructure as code software tool that provides a consistent CLI workflow to manage hundreds of cloud services. Terraform codifies cloud APIs into declarative configuration files.
55+
* [kubectl](https://kubernetes.io/docs/tasks/tools/) - The Kubernetes command-line tool (optional)
56+
* [oci cli](https://docs.oracle.com/en-us/iaas/Content/API/Concepts/cliconcepts.htm) - Oracle command line interface (optional)
57+
4758
#### Example RSA key generation
4859

4960
To use terraform with the Oracle Cloud infrastructure you need to generate an RSA key. Generate the rsa key with:
@@ -58,9 +69,15 @@ replace *<your_name>* with your name or a string you prefer.
5869

5970
**NOTE** ~/.oci/<your_name>-oracle-cloud_public.pem this string will be used on the *terraform.tfvars* used by the Oracle provider plugin, so please take note of this string.
6071

72+
### Project setup
73+
74+
Once you have cloned this repo, change directory to [examples](examples/) dir and choose the example you prefer: *private subnet* or main.tf or *public subnet* main.tf-public file. Edit the example file and set the needed variables (*change-me* variables). Crate a *terraform.tfvars* file, for more detail see [Oracle provider setup](#oracle-provider-setup) and read all the modules requirements in each module directory.
75+
76+
Or if you prefer you can create a new empty directory in your workspace and start a new project from scratch. To setup the project follow the README.md in the [examples](examples/) directory.
77+
6178
### Oracle provider setup
6279

63-
In any subdirectory of this repo you need to create a terraform.tfvars file, the file will look like:
80+
This is an example of the *terraform.tfvars* file:
6481

6582
```
6683
fingerprint = "<rsa_key_fingerprint>"
@@ -78,48 +95,71 @@ The compartment_ocid is the same as tenency_ocid.
7895

7996
The fingerprint is the fingerprint of your RSA key, you can find this vale under User setting > API Keys
8097

81-
### Other variables to adjust
98+
#### How to find the availability doamin name
8299

83-
Before triggering the infrastructure deployment adjust the following variables (vars.tf in each subdirectory):
100+
To find the list of the availability domains run this command on che Cloud Shell:
84101

85-
* region, set the correct region based on your needs
86-
* availability_domain, set you availability domain, you can get the availability domain string in the "*Create instance* form. Once you are in the create instance procedure under the placement section click "Edit" and copy the string that begin with *iAdc:*. Example iAdc:EU-ZURICH-1-AD-1
87-
* default_fault_domain, set de default fault domain, choose one of: FAULT-DOMAIN-1, FAULT-DOMAIN-2, FAULT-DOMAIN-3
88-
* PATH_TO_PUBLIC_KEY, this variable have to point at your ssh public key
89-
* oci_core_vcn_cidr, set the default VCN subnet cidr
90-
* oci_core_subnet_cidr10, set the default subnet cidr
91-
* oci_core_subnet_cidr11, set the secondary subnet cidr
92-
* tutorial_tag_key, set a key used to tag all the deployed resources
93-
* tutorial_tag_value, set the value of the tutorial_tag_key
94-
* my_public_ip_address, set your public ip address
95-
96-
### Common resources
97-
98-
All the environments share the same network and security list configurations.
102+
```
103+
oci iam availability-domain list
104+
{
105+
"data": [
106+
{
107+
"compartment-id": "<compartment_ocid>",
108+
"id": "ocid1.availabilitydomain.oc1..xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
109+
"name": "iAdc:EU-ZURICH-1-AD-1"
110+
}
111+
]
112+
}
113+
```
99114

100-
The network setup create:
115+
#### How to list all the OS images
101116

102-
* One VCN (10.0.0.0/16 subnet), you can setup a custom network CIDR in oci_core_vcn_cidr variable.
103-
* Two subnets, the first subnet (default) is the 10.0.0.0/24 range, the second subnet is 10.0.1.0/24 range. You can customize the subnets CIDR in oci_core_subnet_cidr10 and oci_core_subnet_cidr11 variables.
117+
To filter the OS images by shape and OS run this command on che Cloud Shell:
104118

105-
The security list rules are:
119+
```
120+
oci compute image list --compartment-id <compartment_ocid> --operating-system "Canonical Ubuntu" --shape "VM.Standard.A1.Flex"
121+
{
122+
"data": [
123+
{
124+
"agent-features": null,
125+
"base-image-id": null,
126+
"billable-size-in-gbs": 2,
127+
"compartment-id": null,
128+
"create-image-allowed": true,
129+
"defined-tags": {},
130+
"display-name": "Canonical-Ubuntu-20.04-aarch64-2022.01.18-0",
131+
"freeform-tags": {},
132+
"id": "ocid1.image.oc1.eu-zurich-1.aaaaaaaag2uyozo7266bmg26j5ixvi42jhaujso2pddpsigtib6vfnqy5f6q",
133+
"launch-mode": "NATIVE",
134+
"launch-options": {
135+
"boot-volume-type": "PARAVIRTUALIZED",
136+
"firmware": "UEFI_64",
137+
"is-consistent-volume-naming-enabled": true,
138+
"is-pv-encryption-in-transit-enabled": true,
139+
"network-type": "PARAVIRTUALIZED",
140+
"remote-data-volume-type": "PARAVIRTUALIZED"
141+
},
142+
"lifecycle-state": "AVAILABLE",
143+
"listing-type": null,
144+
"operating-system": "Canonical Ubuntu",
145+
"operating-system-version": "20.04",
146+
"size-in-mbs": 47694,
147+
"time-created": "2022-01-27T22:53:34.270000+00:00"
148+
},
149+
```
106150

107-
* By default only the incoming ICMP, SSH and HTTP traffic is allowed from your public ip. You can setup your public ip in my_public_ip_address variable.
108-
* By default all the outgoing traffic is allowed
109-
* A second security list rule (Custom security list) open all the incoming http traffic
110-
* Both default security list and the custom security list are associated on both subnets
111-
* Network flow from the private VCN subnet is allowed
151+
**Note:** this setup was only tested with Ubuntu 20.04
112152

113153
### Firewall
114154

115-
By default firewall on the compute instances is disabled. On some test the firewall has created some problems
155+
By default firewall on the compute instances is disabled (except for the nat instance).
116156

117157
### Software installed
118158

119159
In the simple-instance example and in the instance-pool example nginx will be installed by default.
120-
Nginx is used for testing the security list rules an the correct setup of the Load Balancer (instance-pool example).
160+
Nginx is used for testing the security list rules an the correct setup of the Load Balancer.
121161

122-
On the k3s-cluster example, k3s will be automatically installed on all the machines.
162+
On the k3s-cluster example, k3s will be automatically installed on all the machines. **NOTE** k3s-cluster setup has moved to [this](https://github.com/garutilorenzo/k3s-oci-cluster) repository.
123163

124164
### OS
125165

instance-pool/.terraform.lock.hcl renamed to examples/.terraform.lock.hcl

Lines changed: 13 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/README.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Examples
2+
3+
In this folder there are two examples:
4+
5+
* main.tf - Use a private subnet with a nat instance, all services are deployed on the pivate subnet. (Default example)
6+
* main.tf-public - Use a public subnet, all the services are deployed in the public subnet. (Disabled example)
7+
8+
If you want to use the public example, rename the *main.tf-public* in *main.tf*. Keep **ONLY ONE** *.tf file.
9+
10+
Now adjust all the *change-me* variables inside the main.tf file. Once you have setup your environment, we are ready to init terraform:
11+
12+
```
13+
Initializing modules...
14+
15+
Initializing the backend...
16+
17+
Initializing provider plugins...
18+
- Reusing previous version of hashicorp/oci from the dependency lock file
19+
- Reusing previous version of hashicorp/template from the dependency lock file
20+
- Using previously-installed hashicorp/oci v4.65.0
21+
- Using previously-installed hashicorp/template v2.2.0
22+
23+
Terraform has been successfully initialized!
24+
25+
You may now begin working with Terraform. Try running "terraform plan" to see
26+
any changes that are required for your infrastructure. All Terraform commands
27+
should now work.
28+
29+
If you ever set or change modules or backend configuration for Terraform,
30+
rerun this command to reinitialize your working directory. If you forget, other
31+
commands will detect it and remind you to do so if necessary.
32+
```
33+
34+
### Deploy
35+
36+
We are now ready to deploy our infrastructure. First we ask terraform to plan the execution with:
37+
38+
```
39+
terraform plan
40+
```
41+
42+
now we can deploy our resources with:
43+
44+
```
45+
terraform apply
46+
```
47+
48+
### Connect to private instances
49+
50+
We can connect to the private instances using the nat instance as Jump server:
51+
52+
```
53+
ssh -J bastion@<NAT_INSTANCE_PUBLIC_IP> ubuntu@<INSTANCE_PRIVATE_IP>
54+
```
55+
56+
### Start a project from scratch
57+
58+
If you want to create a new project from scratch you need three files:
59+
60+
* terraform.tfvars - More details in [Oracle provider setup](../README.md#oracle-provider-setup)
61+
* main.tf - download main.tf file or main.tf-public based on your needs. If you choose main.tf-public **remember** to rename the file in main.tf
62+
* provider.tf - download the file from this directory

0 commit comments

Comments
 (0)