Last active
June 14, 2021 17:18
-
-
Save Binsabbar/530915b68d1aef366d82b0d62e0e339c to your computer and use it in GitHub Desktop.
Part 1: Simple Infrastructure in Oracle Cloud
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tenancy_ocid="" | |
user_ocid="" | |
fingerprint="" | |
private_key_path="~/.oci/oci_id_rsa.pem" | |
region="" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Host machine-1 | |
Hostname PUBLIC_IP_HERE | |
User ubuntu | |
IdentityFile ~/.ssh/id_rsa | |
Host machine-2 | |
Hostname PRIVATE_IP_HERE | |
User ubuntu | |
IdentityFile ~/.ssh/id_rsa | |
ProxyJump machine-1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
terraform { | |
required_providers { | |
oci = { | |
source = "hashicorp/oci" | |
version = "~> 4.16.0" | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module "network" { | |
source = "github.com/Binsabbar/oracle-cloud-terraform//modules/network?ref=v1.0" | |
name = "mynetwork" | |
compartment_id = var.tenancy_ocid | |
cidr_block = "192.168.0.0/16" | |
allowed_ingress_ports = [] # we do not want to allow any ingress ports using security list, we will network security group for that | |
private_subnets = { | |
"private1" = { | |
cidr_block = "192.168.1.0/24" | |
security_list_ids = [] | |
optionals = {} | |
} | |
} | |
public_subnets = { | |
"public1" = { | |
cidr_block = "192.168.2.0/24" | |
security_list_ids = [] | |
optionals = {} | |
} | |
} | |
} | |
data "oci_identity_availability_domain" "ad" { | |
compartment_id = var.tenancy_ocid | |
ad_number = 1 | |
} | |
data "oci_identity_fault_domains" "fd" { | |
availability_domain = data.oci_identity_availability_domain.ad.name | |
compartment_id = var.tenancy_ocid | |
} | |
module "common" { | |
source = "github.com/Binsabbar/oracle-cloud-terraform//modules/common-config?ref=v1.0" | |
} | |
module "instances" { | |
source = "github.com/Binsabbar/oracle-cloud-terraform//modules/instances?ref=v1.0" | |
instances = { | |
"machine-1" = { | |
availability_domain_name = data.oci_identity_availability_domain.ad.name | |
fault_domain_name = data.oci_identity_fault_domains.fd.fault_domains[0].name | |
compartment_id = var.tenancy_ocid | |
volume_size = 50 | |
state = module.common.instance_config.instance_state.RUNNING | |
autherized_keys = "PUT_YOUR_SSH_PUB_RSA_KEY_HERE" | |
config = { | |
shape = module.common.instance_config.shapes.micro | |
image_id = module.common.instance_config.images_ids.ubuntu_20 | |
network_sgs_ids = [module.nsg.networks_sg.machine-1-rules] | |
subnet = module.network.public_subnets.public1 | |
} | |
} | |
"machine-2" = { | |
availability_domain_name = data.oci_identity_availability_domain.ad.name | |
fault_domain_name = data.oci_identity_fault_domains.fd.fault_domains[0].name | |
compartment_id = var.tenancy_ocid | |
volume_size = 50 | |
state = module.common.instance_config.instance_state.RUNNING | |
autherized_keys = "PUT_YOUR_SSH_PUB_RSA_KEY_HERE" | |
config = { | |
shape = module.common.instance_config.shapes.micro | |
image_id = module.common.instance_config.images_ids.ubuntu_20 | |
network_sgs_ids = [module.nsg.networks_sg.machine-2-rules] | |
subnet = module.network.public_subnets.public1 | |
} | |
} | |
} | |
} | |
module "nsg" { | |
source = "github.com/Binsabbar/oracle-cloud-terraform//modules/network-sg?ref=v1.0" | |
vcn_id = module.network.vcn.id | |
compartment_id = var.tenancy_ocid | |
network_security_groups = { | |
"machine-1-rules" = { | |
"ssh-from-my-ip" = { | |
direction = "INGRESS" | |
protocol = "tcp" | |
port = 22 | |
ips = ["YOUR_IP_HERE"] | |
} | |
} | |
"machine-2-rules" = { | |
"ssh-from-public1-subnet" = { | |
direction = "INGRESS" | |
protocol = "tcp" | |
port = 22 | |
ips = [module.network.public_subnets.public1.cidr_block] | |
} | |
} | |
} | |
} | |
output "machine-1-ip" { | |
value = module.instances.instances.machine-1.public_ip | |
} | |
output "machine-2-private-ip" { | |
value = module.instances.instances.machine-2.private_ip | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
provider "oci" { | |
tenancy_ocid = var.tenancy_ocid | |
user_ocid = var.user_ocid | |
fingerprint = var.fingerprint | |
private_key_path = var.private_key_path | |
region = var.region | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
variable "tenancy_ocid" { type = string } | |
variable "user_ocid" { type = string } | |
variable "fingerprint" { type = string } | |
variable "private_key_path" { type = string } | |
variable "region" { type = string } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment