-
Notifications
You must be signed in to change notification settings - Fork 0
/
oke-network.tf
126 lines (107 loc) · 6.94 KB
/
oke-network.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
## Copyright (c) 2021, Oracle and/or its affiliates.
## All rights reserved. The Universal Permissive License (UPL), Version 1.0 as shown at http://oss.oracle.com/licenses/upl
resource "oci_core_virtual_network" "oke_vcn" {
cidr_block = lookup(var.network_cidrs, "VCN-CIDR")
compartment_id = local.oke_compartment_id
display_name = "OKE ${var.app_name} VCN - ${random_string.deploy_id.result}"
dns_label = "oke${random_string.deploy_id.result}"
count = var.create_new_oke_cluster ? 1 : 0
defined_tags = { "${oci_identity_tag_namespace.ArchitectureCenterTagNamespace.name}.${oci_identity_tag.ArchitectureCenterTag.name}" = var.release }
}
resource "oci_core_subnet" "oke_k8s_endpoint_subnet" {
cidr_block = lookup(var.network_cidrs, "ENDPOINT-SUBNET-REGIONAL-CIDR")
compartment_id = local.oke_compartment_id
display_name = "oke-k8s-endpoint-subnet-${local.app_name_normalized}-${random_string.deploy_id.result}"
dns_label = "okek8sn${random_string.deploy_id.result}"
vcn_id = oci_core_virtual_network.oke_vcn[0].id
prohibit_public_ip_on_vnic = (var.cluster_endpoint_visibility == "Private") ? true : false
route_table_id = (var.cluster_endpoint_visibility == "Private") ? oci_core_route_table.oke_private_route_table[0].id : oci_core_route_table.oke_public_route_table[0].id
dhcp_options_id = oci_core_virtual_network.oke_vcn[0].default_dhcp_options_id
security_list_ids = [oci_core_security_list.oke_endpoint_security_list[0].id]
count = var.create_new_oke_cluster ? 1 : 0
defined_tags = { "${oci_identity_tag_namespace.ArchitectureCenterTagNamespace.name}.${oci_identity_tag.ArchitectureCenterTag.name}" = var.release }
}
resource "oci_core_subnet" "oke_nodes_subnet" {
cidr_block = lookup(var.network_cidrs, "SUBNET-REGIONAL-CIDR")
compartment_id = local.oke_compartment_id
display_name = "oke-nodes-subnet-${local.app_name_normalized}-${random_string.deploy_id.result}"
dns_label = "okenodesn${random_string.deploy_id.result}"
vcn_id = oci_core_virtual_network.oke_vcn[0].id
prohibit_public_ip_on_vnic = (var.cluster_workers_visibility == "Private") ? true : false
route_table_id = (var.cluster_workers_visibility == "Private") ? oci_core_route_table.oke_private_route_table[0].id : oci_core_route_table.oke_public_route_table[0].id
dhcp_options_id = oci_core_virtual_network.oke_vcn[0].default_dhcp_options_id
security_list_ids = [oci_core_security_list.oke_nodes_security_list[0].id]
count = var.create_new_oke_cluster ? 1 : 0
defined_tags = { "${oci_identity_tag_namespace.ArchitectureCenterTagNamespace.name}.${oci_identity_tag.ArchitectureCenterTag.name}" = var.release }
}
resource "oci_core_subnet" "oke_lb_subnet" {
cidr_block = lookup(var.network_cidrs, "LB-SUBNET-REGIONAL-CIDR")
compartment_id = local.oke_compartment_id
display_name = "oke-lb-subnet-${local.app_name_normalized}-${random_string.deploy_id.result}"
dns_label = "okelbsn${random_string.deploy_id.result}"
vcn_id = oci_core_virtual_network.oke_vcn[0].id
prohibit_public_ip_on_vnic = false
route_table_id = oci_core_route_table.oke_public_route_table[0].id
dhcp_options_id = oci_core_virtual_network.oke_vcn[0].default_dhcp_options_id
security_list_ids = [oci_core_security_list.oke_lb_security_list[0].id]
count = var.create_new_oke_cluster ? 1 : 0
defined_tags = { "${oci_identity_tag_namespace.ArchitectureCenterTagNamespace.name}.${oci_identity_tag.ArchitectureCenterTag.name}" = var.release }
}
resource "oci_core_route_table" "oke_private_route_table" {
compartment_id = local.oke_compartment_id
vcn_id = oci_core_virtual_network.oke_vcn[0].id
display_name = "oke-private-route-table-${local.app_name_normalized}-${random_string.deploy_id.result}"
route_rules {
description = "Traffic to the internet"
destination = lookup(var.network_cidrs, "ALL-CIDR")
destination_type = "CIDR_BLOCK"
network_entity_id = oci_core_nat_gateway.oke_nat_gateway[0].id
}
route_rules {
description = "Traffic to OCI services"
destination = lookup(data.oci_core_services.all_services.services[0], "cidr_block")
destination_type = "SERVICE_CIDR_BLOCK"
network_entity_id = oci_core_service_gateway.oke_service_gateway[0].id
}
count = var.create_new_oke_cluster ? 1 : 0
defined_tags = { "${oci_identity_tag_namespace.ArchitectureCenterTagNamespace.name}.${oci_identity_tag.ArchitectureCenterTag.name}" = var.release }
}
resource "oci_core_route_table" "oke_public_route_table" {
compartment_id = local.oke_compartment_id
vcn_id = oci_core_virtual_network.oke_vcn[0].id
display_name = "oke-public-route-table-${local.app_name_normalized}-${random_string.deploy_id.result}"
route_rules {
description = "Traffic to/from internet"
destination = lookup(var.network_cidrs, "ALL-CIDR")
destination_type = "CIDR_BLOCK"
network_entity_id = oci_core_internet_gateway.oke_internet_gateway[0].id
}
count = var.create_new_oke_cluster ? 1 : 0
defined_tags = { "${oci_identity_tag_namespace.ArchitectureCenterTagNamespace.name}.${oci_identity_tag.ArchitectureCenterTag.name}" = var.release }
}
resource "oci_core_nat_gateway" "oke_nat_gateway" {
block_traffic = "false"
compartment_id = local.oke_compartment_id
display_name = "oke-nat-gateway-${local.app_name_normalized}-${random_string.deploy_id.result}"
vcn_id = oci_core_virtual_network.oke_vcn[0].id
count = var.create_new_oke_cluster ? 1 : 0
defined_tags = { "${oci_identity_tag_namespace.ArchitectureCenterTagNamespace.name}.${oci_identity_tag.ArchitectureCenterTag.name}" = var.release }
}
resource "oci_core_internet_gateway" "oke_internet_gateway" {
compartment_id = local.oke_compartment_id
display_name = "oke-internet-gateway-${local.app_name_normalized}-${random_string.deploy_id.result}"
enabled = true
vcn_id = oci_core_virtual_network.oke_vcn[0].id
count = var.create_new_oke_cluster ? 1 : 0
defined_tags = { "${oci_identity_tag_namespace.ArchitectureCenterTagNamespace.name}.${oci_identity_tag.ArchitectureCenterTag.name}" = var.release }
}
resource "oci_core_service_gateway" "oke_service_gateway" {
compartment_id = local.oke_compartment_id
display_name = "oke-service-gateway-${local.app_name_normalized}-${random_string.deploy_id.result}"
vcn_id = oci_core_virtual_network.oke_vcn[0].id
services {
service_id = lookup(data.oci_core_services.all_services.services[0], "id")
}
count = var.create_new_oke_cluster ? 1 : 0
defined_tags = { "${oci_identity_tag_namespace.ArchitectureCenterTagNamespace.name}.${oci_identity_tag.ArchitectureCenterTag.name}" = var.release }
}