|
| 1 | +resource "oci_core_virtual_network" "vcn" { |
| 2 | + cidr_block = "10.1.0.0/16" |
| 3 | + compartment_id = "${var.compartment_ocid}" |
| 4 | + display_name = "TFExampleVCNDBSystem" |
| 5 | + dns_label = "tfexvcndbsys" |
| 6 | +} |
| 7 | + |
| 8 | +resource "oci_core_subnet" "subnet" { |
| 9 | + availability_domain = "${lookup(data.oci_identity_availability_domains.ADs.availability_domains[var.availability_domain - 1],"name")}" |
| 10 | + cidr_block = "10.1.20.0/24" |
| 11 | + display_name = "TFExampleSubnetDBSystem" |
| 12 | + dns_label = "tfexsubdbsys" |
| 13 | + security_list_ids = ["${oci_core_security_list.ExampleSecurityList.id}"] |
| 14 | + compartment_id = "${var.compartment_ocid}" |
| 15 | + vcn_id = "${oci_core_virtual_network.vcn.id}" |
| 16 | + route_table_id = "${oci_core_route_table.route_table.id}" |
| 17 | + dhcp_options_id = "${oci_core_virtual_network.vcn.default_dhcp_options_id}" |
| 18 | +} |
| 19 | + |
| 20 | +resource "oci_core_subnet" "subnet_backup" { |
| 21 | + availability_domain = "${lookup(data.oci_identity_availability_domains.ADs.availability_domains[var.availability_domain - 1],"name")}" |
| 22 | + cidr_block = "10.1.1.0/24" |
| 23 | + display_name = "TFExampleSubnetDBSystemBackup" |
| 24 | + dns_label = "tfexsubdbsysbp" |
| 25 | + security_list_ids = ["${oci_core_security_list.ExampleSecurityList.id}"] |
| 26 | + compartment_id = "${var.compartment_ocid}" |
| 27 | + vcn_id = "${oci_core_virtual_network.vcn.id}" |
| 28 | + route_table_id = "${oci_core_route_table.route_table_backup.id}" |
| 29 | + dhcp_options_id = "${oci_core_virtual_network.vcn.default_dhcp_options_id}" |
| 30 | +} |
| 31 | + |
| 32 | +resource "oci_core_internet_gateway" "internet_gateway" { |
| 33 | + compartment_id = "${var.compartment_ocid}" |
| 34 | + display_name = "TFExampleIGDBSystem" |
| 35 | + vcn_id = "${oci_core_virtual_network.vcn.id}" |
| 36 | +} |
| 37 | + |
| 38 | +resource "oci_core_route_table" "route_table" { |
| 39 | + compartment_id = "${var.compartment_ocid}" |
| 40 | + vcn_id = "${oci_core_virtual_network.vcn.id}" |
| 41 | + display_name = "TFExampleRouteTableDBSystem" |
| 42 | + |
| 43 | + route_rules { |
| 44 | + destination = "0.0.0.0/0" |
| 45 | + destination_type = "CIDR_BLOCK" |
| 46 | + network_entity_id = "${oci_core_internet_gateway.internet_gateway.id}" |
| 47 | + } |
| 48 | +} |
| 49 | + |
| 50 | +resource "oci_core_route_table" "route_table_backup" { |
| 51 | + compartment_id = "${var.compartment_ocid}" |
| 52 | + vcn_id = "${oci_core_virtual_network.vcn.id}" |
| 53 | + display_name = "TFExampleRouteTableDBSystemBackup" |
| 54 | + |
| 55 | + route_rules { |
| 56 | + destination = "0.0.0.0/0" |
| 57 | + destination_type = "CIDR_BLOCK" |
| 58 | + network_entity_id = "${oci_core_internet_gateway.internet_gateway.id}" |
| 59 | + } |
| 60 | +} |
| 61 | + |
| 62 | +resource "oci_core_security_list" "ExampleSecurityList" { |
| 63 | + compartment_id = "${var.compartment_ocid}" |
| 64 | + vcn_id = "${oci_core_virtual_network.vcn.id}" |
| 65 | + display_name = "TFExampleSecurityList" |
| 66 | + |
| 67 | + // allow outbound tcp traffic on all ports |
| 68 | + egress_security_rules { |
| 69 | + destination = "0.0.0.0/0" |
| 70 | + protocol = "6" |
| 71 | + } |
| 72 | + |
| 73 | + // allow outbound udp traffic on a port range |
| 74 | + egress_security_rules { |
| 75 | + destination = "0.0.0.0/0" |
| 76 | + protocol = "17" // udp |
| 77 | + stateless = true |
| 78 | + } |
| 79 | + |
| 80 | + egress_security_rules { |
| 81 | + destination = "0.0.0.0/0" |
| 82 | + protocol = "1" |
| 83 | + stateless = true |
| 84 | + } |
| 85 | + |
| 86 | + // allow inbound ssh traffic from a specific port |
| 87 | + ingress_security_rules { |
| 88 | + protocol = "6" // tcp |
| 89 | + source = "0.0.0.0/0" |
| 90 | + stateless = false |
| 91 | + } |
| 92 | + |
| 93 | + // allow inbound icmp traffic of a specific type |
| 94 | + ingress_security_rules { |
| 95 | + protocol = 1 |
| 96 | + source = "0.0.0.0/0" |
| 97 | + stateless = true |
| 98 | + } |
| 99 | +} |
0 commit comments