|
| 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 | +} |
0 commit comments