Skip to content

Commit dc26b52

Browse files
authored
Merge pull request #3 from junior/API_Gateway_n_FN_subnet_example
Api gateway n fn subnet example
2 parents ea9cb60 + dc9ce61 commit dc26b52

File tree

18 files changed

+354
-24
lines changed

18 files changed

+354
-24
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ There are multiple examples included in the [examples](https://github.com/oracle
2626

2727
```hcl
2828
module "oci-networking" {
29-
source = "github.com/oracle-quickstart/terraform-oci-networking?ref=0.1.1"
29+
source = "github.com/oracle-quickstart/terraform-oci-networking?ref=0.1.2"
3030
3131
# Oracle Cloud Infrastructure Tenancy and Compartment OCID
3232
tenancy_ocid = var.tenancy_ocid
@@ -61,7 +61,7 @@ module "oci-networking" {
6161

6262
```hcl
6363
module "vcn" {
64-
source = "github.com/oracle-quickstart/terraform-oci-networking//modules/vcn?ref=0.1.1"
64+
source = "github.com/oracle-quickstart/terraform-oci-networking//modules/vcn?ref=0.1.2"
6565
6666
# Oracle Cloud Infrastructure Tenancy and Compartment OCID
6767
compartment_ocid = var.compartment_ocid
@@ -81,7 +81,7 @@ module "vcn" {
8181
8282
module "subnets" {
8383
for_each = { for map in local.subnets : map.subnet_name => map }
84-
source = "github.com/oracle-quickstart/terraform-oci-networking//modules/subnet?ref=0.1.1"
84+
source = "github.com/oracle-quickstart/terraform-oci-networking//modules/subnet?ref=0.1.2"
8585
8686
# Oracle Cloud Infrastructure Tenancy and Compartment OCID
8787
compartment_ocid = var.compartment_ocid

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.1.1
1+
0.1.2

examples/5g-networking/defaults.tf

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,17 @@ locals {
3232
vcn_cidr_blocks = split(",", var.vcn_cidr_blocks)
3333
network_cidrs = {
3434
VCN-MAIN-CIDR = local.vcn_cidr_blocks[0] # e.g.: "10.20.0.0/16" = 65536 usable IPs
35-
SUBNET-5GC-OAM-CIDR = cidrsubnet(local.vcn_cidr_blocks[0], 9, 128) # e.g.: "10.75.64.0/25" = 128 usable IPs
36-
SUBNET-5GC-SIGNALLING-CIDR = cidrsubnet(local.vcn_cidr_blocks[0], 9, 129) # e.g.: "10.75.64.128/25" = 128 usable IPs
37-
SUBNET-5G-RAN-CIDR = cidrsubnet(local.vcn_cidr_blocks[0], 11, 520) # e.g.: "10.75.65.0/27" = 32 usable IPs
38-
SUBNET-LEGAL-INTERCEPT-CIDR = cidrsubnet(local.vcn_cidr_blocks[0], 11, 521) # e.g.: "10.75.65.32/27" = 32 usable IPs
39-
SUBNET-5G-EPC-CIDR = cidrsubnet(local.vcn_cidr_blocks[0], 11, 522) # e.g.: "10.75.65.64/27"
4035
SUBNET-VCN-NATIVE-POD-NETWORKING-REGIONAL-CIDR = cidrsubnet(local.vcn_cidr_blocks[0], 1, 1) # e.g.: "10.75.128.0/17" = 32766 usable IPs (10.20.128.0 - 10.20.255.255)
4136
SUBNET-BASTION-REGIONAL-CIDR = cidrsubnet(local.vcn_cidr_blocks[0], 12, 32) # e.g.: "10.75.2.0/28" = 15 usable IPs (10.20.2.0 - 10.20.2.15)
4237
PODS-CIDR = "10.244.0.0/16"
4338
KUBERNETES-SERVICE-CIDR = "10.96.0.0/16"
4439
ALL-CIDR = "0.0.0.0/0"
4540
}
41+
network_5G_cidrs = {
42+
SUBNET-5GC-OAM-CIDR = cidrsubnet(local.vcn_cidr_blocks[0], 9, 128) # e.g.: "10.75.64.0/25" = 128 usable IPs
43+
SUBNET-5GC-SIGNALLING-CIDR = cidrsubnet(local.vcn_cidr_blocks[0], 9, 129) # e.g.: "10.75.64.128/25" = 128 usable IPs
44+
SUBNET-5G-RAN-CIDR = cidrsubnet(local.vcn_cidr_blocks[0], 11, 520) # e.g.: "10.75.65.0/27" = 32 usable IPs
45+
SUBNET-LEGAL-INTERCEPT-CIDR = cidrsubnet(local.vcn_cidr_blocks[0], 11, 521) # e.g.: "10.75.65.32/27" = 32 usable IPs
46+
SUBNET-5G-EPC-CIDR = cidrsubnet(local.vcn_cidr_blocks[0], 11, 522) # e.g.: "10.75.65.64/27" = 32 usable IPs
47+
}
4648
}

examples/5g-networking/gateways.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Module: Gateways
33
################################################################################
44
module "gateways" {
5-
source = "github.com/oracle-quickstart/terraform-oci-networking//modules/gateways?ref=0.1.1"
5+
source = "github.com/oracle-quickstart/terraform-oci-networking//modules/gateways?ref=0.1.2"
66

77
# Oracle Cloud Infrastructure Tenancy and Compartment OCID
88
compartment_ocid = local.vcn_compartment_ocid

examples/5g-networking/route_tables.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
################################################################################
55
module "route_tables" {
66
for_each = { for map in local.route_tables : map.route_table_name => map }
7-
source = "github.com/oracle-quickstart/terraform-oci-networking//modules/route_table?ref=0.1.1"
7+
source = "github.com/oracle-quickstart/terraform-oci-networking//modules/route_table?ref=0.1.2"
88

99
# Oracle Cloud Infrastructure Tenancy and Compartment OCID
1010
compartment_ocid = local.vcn_compartment_ocid

examples/5g-networking/security_lists.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
################################################################################
44
module "security_lists" {
55
for_each = { for map in local.security_lists : map.security_list_name => map }
6-
source = "github.com/oracle-quickstart/terraform-oci-networking//modules/security_list?ref=0.1.1"
6+
source = "github.com/oracle-quickstart/terraform-oci-networking//modules/security_list?ref=0.1.2"
77

88
# Oracle Cloud Infrastructure Tenancy and Compartment OCID
99
compartment_ocid = local.vcn_compartment_ocid

examples/5g-networking/subnets.tf

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
################################################################################
44
module "subnets" {
55
for_each = { for map in local.subnets : map.subnet_name => map }
6-
source = "github.com/oracle-quickstart/terraform-oci-networking//modules/subnet?ref=0.1.1"
6+
source = "github.com/oracle-quickstart/terraform-oci-networking//modules/subnet?ref=0.1.2"
77

88
# Oracle Cloud Infrastructure Tenancy and Compartment OCID
99
compartment_ocid = local.vcn_compartment_ocid
@@ -30,7 +30,7 @@ locals {
3030
subnets = [
3131
{
3232
subnet_name = "5GC_OAM_subnet"
33-
cidr_block = lookup(local.network_cidrs, "SUBNET-5GC-OAM-CIDR")
33+
cidr_block = lookup(local.network_5G_cidrs, "SUBNET-5GC-OAM-CIDR")
3434
display_name = "5GC OAM subnet (${local.deploy_id})"
3535
dns_label = "sn5gcoam${local.deploy_id}"
3636
prohibit_public_ip_on_vnic = true
@@ -42,7 +42,7 @@ locals {
4242
},
4343
{
4444
subnet_name = "5GC_Signalling_subnet"
45-
cidr_block = lookup(local.network_cidrs, "SUBNET-5GC-SIGNALLING-CIDR")
45+
cidr_block = lookup(local.network_5G_cidrs, "SUBNET-5GC-SIGNALLING-CIDR")
4646
display_name = "5GC Signalling (SBI) subnet (${local.deploy_id})"
4747
dns_label = "sn5gcsig${local.deploy_id}"
4848
prohibit_public_ip_on_vnic = true
@@ -54,7 +54,7 @@ locals {
5454
},
5555
{
5656
subnet_name = "5G_RAN_subnet"
57-
cidr_block = lookup(local.network_cidrs, "SUBNET-5G-RAN-CIDR")
57+
cidr_block = lookup(local.network_5G_cidrs, "SUBNET-5G-RAN-CIDR")
5858
display_name = "5G RAN subnet (${local.deploy_id})"
5959
dns_label = "sn5gran${local.deploy_id}"
6060
prohibit_public_ip_on_vnic = true
@@ -66,7 +66,7 @@ locals {
6666
},
6767
{
6868
subnet_name = "Legal_Intercept_subnet"
69-
cidr_block = lookup(local.network_cidrs, "SUBNET-LEGAL-INTERCEPT-CIDR")
69+
cidr_block = lookup(local.network_5G_cidrs, "SUBNET-LEGAL-INTERCEPT-CIDR")
7070
display_name = "Legal Intercept subnet (${local.deploy_id})"
7171
dns_label = "snlegalin${local.deploy_id}"
7272
prohibit_public_ip_on_vnic = true
@@ -78,7 +78,7 @@ locals {
7878
},
7979
{
8080
subnet_name = "5G_EPC_subnet"
81-
cidr_block = lookup(local.network_cidrs, "SUBNET-5G-EPC-CIDR")
81+
cidr_block = lookup(local.network_5G_cidrs, "SUBNET-5G-EPC-CIDR")
8282
display_name = "5G EPC subnet (${local.deploy_id})"
8383
dns_label = "sn5gcepc${local.deploy_id}"
8484
prohibit_public_ip_on_vnic = true

examples/5g-networking/vcn.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Module: Virtual Cloud Network (VCN)
44
################################################################################
55
module "vcn" {
6-
source = "github.com/oracle-quickstart/terraform-oci-networking//modules/vcn?ref=0.1.1"
6+
source = "github.com/oracle-quickstart/terraform-oci-networking//modules/vcn?ref=0.1.2"
77

88
# Oracle Cloud Infrastructure Tenancy and Compartment OCID
99
compartment_ocid = local.vcn_compartment_ocid
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
2+
# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
3+
#
4+
5+
# File Version: 0.1.0
6+
7+
# Locals
8+
locals {
9+
deploy_id = random_string.deploy_id.result
10+
deploy_tags = { "DeploymentID" = local.deploy_id, "AppName" = local.app_name, "Quickstart" = "terraform-oci-networking", "QuickstartExample" = "apigw-fn-extra-subnet-existing-vcn" }
11+
oci_tag_values = {
12+
"freeformTags" = merge(var.tag_values.freeformTags, local.deploy_tags),
13+
"definedTags" = var.tag_values.definedTags
14+
}
15+
app_name = var.app_name
16+
app_name_normalized = substr(replace(lower(local.app_name), " ", "-"), 0, 6)
17+
app_name_for_dns = substr(lower(replace(local.app_name, "/\\W|_|\\s/", "")), 0, 6)
18+
}
19+
20+
resource "random_string" "deploy_id" {
21+
length = 4
22+
special = false
23+
}
Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
module "vcn" {
2+
source = "github.com/oracle-quickstart/terraform-oci-networking//modules/vcn?ref=0.1.2"
3+
4+
# Oracle Cloud Infrastructure Tenancy and Compartment OCID
5+
compartment_ocid = var.compartment_ocid
6+
7+
# Deployment Tags + Freeform Tags + Defined Tags
8+
vcn_tags = local.oci_tag_values
9+
10+
# Virtual Cloud Network (VCN) arguments
11+
create_new_vcn = false
12+
existent_vcn_ocid = var.existent_vcn_ocid
13+
}
14+
15+
module "subnets" {
16+
for_each = { for map in local.subnets : map.subnet_name => map }
17+
source = "github.com/oracle-quickstart/terraform-oci-networking//modules/subnet?ref=0.1.2"
18+
19+
# Oracle Cloud Infrastructure Tenancy and Compartment OCID
20+
compartment_ocid = var.compartment_ocid
21+
vcn_id = module.vcn.vcn_id
22+
23+
# Deployment Tags + Freeform Tags + Defined Tags
24+
subnet_tags = local.oci_tag_values
25+
26+
# Subnet arguments
27+
create_subnet = true
28+
subnet_name = each.value.subnet_name
29+
cidr_block = each.value.cidr_block
30+
display_name = each.value.display_name # If null, is autogenerated
31+
dns_label = each.value.dns_label # If null, is autogenerated
32+
prohibit_public_ip_on_vnic = each.value.prohibit_public_ip_on_vnic
33+
prohibit_internet_ingress = each.value.prohibit_internet_ingress
34+
route_table_id = each.value.route_table_id # If null, the VCN's default route table is used
35+
dhcp_options_id = each.value.dhcp_options_id # If null, the VCN's default set of DHCP options is used
36+
security_list_ids = each.value.security_list_ids # If null, the VCN's default security list is used
37+
ipv6cidr_block = each.value.ipv6cidr_block # If null, no IPv6 CIDR block is assigned
38+
}
39+
locals {
40+
subnets = [
41+
{
42+
subnet_name = "api_gw_fn_subnet"
43+
cidr_block = lookup(local.network_cidrs, "APIGW-FN-REGIONAL-SUBNET-CIDR")
44+
display_name = "API Gateway and Fn subnet (${local.deploy_id})"
45+
dns_label = "apigwfn${local.deploy_id}"
46+
prohibit_public_ip_on_vnic = false
47+
prohibit_internet_ingress = false
48+
route_table_id = module.route_tables["apigw_fn_public"].route_table_id # TODO: implement data.oci_core_route_tables to get existent
49+
dhcp_options_id = module.vcn.default_dhcp_options_id
50+
security_list_ids = [module.security_lists["apigw_fn_security_list"].security_list_id]
51+
ipv6cidr_block = null
52+
}
53+
]
54+
}
55+
56+
module "route_tables" {
57+
for_each = { for map in local.route_tables : map.route_table_name => map }
58+
source = "github.com/oracle-quickstart/terraform-oci-networking//modules/route_table?ref=0.1.2"
59+
60+
# Oracle Cloud Infrastructure Tenancy and Compartment OCID
61+
compartment_ocid = local.vcn_compartment_ocid
62+
vcn_id = module.vcn.vcn_id
63+
64+
# Deployment Tags + Freeform Tags + Defined Tags
65+
route_table_tags = local.oci_tag_values
66+
67+
# Route Table attributes
68+
create_route_table = true
69+
route_table_name = each.value.route_table_name
70+
display_name = each.value.display_name
71+
route_rules = each.value.route_rules
72+
}
73+
locals {
74+
route_tables = [{
75+
route_table_name = "apigw_fn_public"
76+
display_name = "API Gateway and Fn Gatw Route Table (${local.deploy_id})"
77+
route_rules = [
78+
{
79+
description = "Traffic to/from internet"
80+
destination = lookup(local.network_cidrs, "ALL-CIDR")
81+
destination_type = "CIDR_BLOCK"
82+
network_entity_id = (var.existent_internet_gateway_ocid == "") ? module.gateways.internet_gateway_id : var.existent_internet_gateway_ocid
83+
}]
84+
}]
85+
}
86+
87+
module "gateways" {
88+
source = "github.com/oracle-quickstart/terraform-oci-networking//modules/gateways?ref=0.1.2"
89+
90+
# Oracle Cloud Infrastructure Tenancy and Compartment OCID
91+
compartment_ocid = local.vcn_compartment_ocid
92+
vcn_id = module.vcn.vcn_id
93+
94+
# Deployment Tags + Freeform Tags + Defined Tags
95+
gateways_tags = local.oci_tag_values
96+
97+
# Internet Gateway
98+
create_internet_gateway = (var.existent_internet_gateway_ocid == "") ? true : false
99+
internet_gateway_display_name = "Internet Gateway (${local.deploy_id})"
100+
internet_gateway_enabled = true
101+
}
102+
103+
module "security_lists" {
104+
for_each = { for map in local.security_lists : map.security_list_name => map }
105+
source = "github.com/oracle-quickstart/terraform-oci-networking//modules/security_list?ref=0.1.2"
106+
107+
# Oracle Cloud Infrastructure Tenancy and Compartment OCID
108+
compartment_ocid = local.vcn_compartment_ocid
109+
vcn_id = module.vcn.vcn_id
110+
111+
# Deployment Tags + Freeform Tags + Defined Tags
112+
security_list_tags = local.oci_tag_values
113+
114+
# Security List attributes
115+
create_security_list = true
116+
security_list_name = each.value.security_list_name
117+
display_name = each.value.display_name
118+
egress_security_rules = each.value.egress_security_rules
119+
ingress_security_rules = each.value.ingress_security_rules
120+
}
121+
locals {
122+
security_lists = [
123+
{
124+
security_list_name = "apigw_fn_security_list"
125+
display_name = "API Gateway and Fn Security List (${local.deploy_id})"
126+
egress_security_rules = [
127+
{
128+
description = "Allow API Gateway to forward requests to Functions via service conduit"
129+
destination = lookup(data.oci_core_services.all_services_network.services[0], "cidr_block")
130+
destination_type = "SERVICE_CIDR_BLOCK"
131+
protocol = local.security_list_ports.all_protocols
132+
stateless = false
133+
tcp_options = { max = -1, min = -1, source_port_range = null }
134+
udp_options = { max = -1, min = -1, source_port_range = null }
135+
icmp_options = null
136+
}]
137+
ingress_security_rules = [
138+
{
139+
description = "Allow API Gateway to receive requests"
140+
source = lookup(local.network_cidrs, "ALL-CIDR")
141+
source_type = "CIDR_BLOCK"
142+
protocol = local.security_list_ports.tcp_protocol_number
143+
stateless = false
144+
tcp_options = { max = local.security_list_ports.https_port_number, min = local.security_list_ports.https_port_number, source_port_range = null }
145+
udp_options = { max = -1, min = -1, source_port_range = null }
146+
icmp_options = null
147+
}]
148+
}
149+
]
150+
security_list_ports = {
151+
http_port_number = 80
152+
https_port_number = 443
153+
k8s_api_endpoint_port_number = 6443
154+
k8s_worker_to_control_plane_port_number = 12250
155+
ssh_port_number = 22
156+
tcp_protocol_number = "6"
157+
icmp_protocol_number = "1"
158+
all_protocols = "all"
159+
}
160+
}
161+
162+
data "oci_core_services" "all_services_network" {
163+
filter {
164+
name = "name"
165+
values = ["All .* Services In Oracle Services Network"]
166+
regex = true
167+
}
168+
}
169+
170+
locals {
171+
# vcn_cidr_blocks = split(",", var.vcn_cidr_blocks)
172+
vcn_compartment_ocid = var.compartment_ocid
173+
pre_vcn_cidr_blocks = split(",", var.vcn_cidr_blocks)
174+
vcn_cidr_blocks = contains(module.vcn.cidr_blocks, local.pre_vcn_cidr_blocks[0]) ? distinct(concat([local.pre_vcn_cidr_blocks[0]],module.vcn.cidr_blocks)) : module.vcn.cidr_blocks
175+
network_cidrs = {
176+
APIGW-FN-REGIONAL-SUBNET-CIDR = cidrsubnet(local.vcn_cidr_blocks[0], 8, 30) # e.g.: "10.20.30.0/24" = 254 usable IPs (10.20.30.0 - 10.20.30.255)
177+
ALL-CIDR = "0.0.0.0/0"
178+
}
179+
}

0 commit comments

Comments
 (0)