Skip to content

Commit bdb1602

Browse files
committed
terraform deployment
1 parent 4b1d734 commit bdb1602

File tree

5 files changed

+148
-0
lines changed

5 files changed

+148
-0
lines changed

terraform/.terraform.lock.hcl

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

terraform/main.tf

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
resource "oci_core_vcn" "vcn" {
2+
compartment_id = var.compartment_ocid
3+
cidr_block = "10.0.0.0/16"
4+
dns_label = "dns"
5+
}
6+
7+
# --- Security rule to allow SSH ---
8+
resource "oci_core_security_list" "ssh" {
9+
compartment_id = var.compartment_ocid
10+
vcn_id = oci_core_vcn.vcn.id
11+
display_name = "ssh-allow"
12+
13+
# egress_security_rules {
14+
# protocol = 6
15+
# destination_type = "CIDR_BLOCK"
16+
# destination = "0.0.0.0/0"
17+
# description = "access to container registries via HTTPS"
18+
# tcp_options {
19+
# min = 443
20+
# max = 443
21+
# }
22+
# }
23+
egress_security_rules {
24+
protocol = "all"
25+
destination = "0.0.0.0/0"
26+
}
27+
28+
ingress_security_rules {
29+
protocol = "6" # TCP
30+
source = "0.0.0.0/0"
31+
tcp_options {
32+
min = 22
33+
max = 22
34+
}
35+
}
36+
}
37+
38+
resource "oci_core_subnet" "subnet" {
39+
cidr_block = "10.0.0.0/24"
40+
compartment_id = var.compartment_ocid
41+
vcn_id = oci_core_vcn.vcn.id
42+
security_list_ids = [
43+
oci_core_security_list.ssh.id
44+
]
45+
route_table_id = oci_core_route_table.rt.id
46+
}
47+
48+
resource "oci_core_internet_gateway" "igw" {
49+
compartment_id = var.compartment_ocid
50+
vcn_id = oci_core_vcn.vcn.id
51+
enabled = true
52+
}
53+
54+
resource "oci_core_route_table" "rt" {
55+
compartment_id = var.compartment_ocid
56+
vcn_id = oci_core_vcn.vcn.id
57+
58+
route_rules {
59+
network_entity_id = oci_core_internet_gateway.igw.id
60+
destination = "0.0.0.0/0"
61+
}
62+
}
63+
64+
data "oci_identity_availability_domains" "local_ads" {
65+
compartment_id = var.compartment_ocid
66+
}
67+
68+
# --- Container Instance ---
69+
resource "oci_container_instances_container_instance" "container_instance" {
70+
compartment_id = var.compartment_ocid
71+
availability_domain = data.oci_identity_availability_domains.local_ads.availability_domains[0].name
72+
display_name = "tf-connections-ssh"
73+
container_restart_policy = "ALWAYS"
74+
shape = "CI.Standard.A1.Flex"
75+
76+
shape_config {
77+
ocpus = 1
78+
memory_in_gbs = 1
79+
}
80+
81+
vnics {
82+
subnet_id = oci_core_subnet.subnet.id
83+
is_public_ip_assigned = true
84+
}
85+
86+
containers {
87+
image_url = "lahmanja/connections-ssh"
88+
display_name = "connections-ssh"
89+
command = ["/connections-ssh", "--port", "22"]
90+
91+
health_checks {
92+
health_check_type = "TCP"
93+
port = 22
94+
}
95+
}
96+
}

terraform/outputs.tf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#output "public_ip" {
2+
# value = oci_container_instances_container_instance.container_instance.
3+
#}

terraform/provider.tf

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
terraform {
2+
backend "oci" {
3+
key = "terraform.tfstate"
4+
}
5+
6+
required_providers {
7+
oci = {
8+
source = "oracle/oci"
9+
version = "~> 7"
10+
}
11+
}
12+
}
13+
14+
provider "oci" {
15+
tenancy_ocid = var.tenancy_ocid
16+
user_ocid = var.user_ocid
17+
fingerprint = var.fingerprint
18+
region = var.region
19+
}

terraform/variables.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
variable "tenancy_ocid" {}
2+
variable "compartment_ocid" {}
3+
variable "user_ocid" {}
4+
variable "fingerprint" {}
5+
variable "region" {}

0 commit comments

Comments
 (0)