Skip to content

Commit

Permalink
Add fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitaliy Natarov authored and Vitaliy Natarov committed Jan 27, 2025
1 parent a6ff76a commit 2499802
Show file tree
Hide file tree
Showing 16 changed files with 950 additions and 99 deletions.
140 changes: 118 additions & 22 deletions oracle_cloud/examples/core_vcn/README.md

Large diffs are not rendered by default.

42 changes: 29 additions & 13 deletions oracle_cloud/examples/core_vcn/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,42 @@ provider "oci" {
user_ocid = var.provider_oci_user_ocid
}

locals {
compartment_id = "ocid1.tenancy.oc1..aaaaaaaaepggbbn72sgkuxbmx2ifwpjuy2dx5kzhsveteiagrbwasjahdrxa"
}

module "core_vcn" {
source = "../../modules/core_vcn"

enable_core_vcn = true
core_vcn_compartment_id = local.compartment_id
core_vcn_display_name = "main-vcn-1"
compartment_id = "ocid1.tenancy.oc1..aaaaaaaaepggbbn72sgkuxbmx2ifwpjuy2dx5kzhsveteiagrbwasjahdrxa"

# VCN:
enable_core_vcn = true
core_vcn_display_name = "main-vcn-1"

# DHCP:
enable_core_dhcp_options = true
core_dhcp_options_compartment_id = local.compartment_id
core_vcn_cidr_blocks = ["10.0.0.0/16"]
enable_core_dhcp_options = true
core_vcn_cidr_blocks = ["10.0.0.0/16"]
core_dhcp_options_options = [
{
type = "DomainNameServer"
server_type = "VcnLocalPlusInternet"
}
type = "DomainNameServer"
server_type = "VcnLocalPlusInternet"
search_domain_names = ["main-vcn-1.oraclevcn.com"]
},
]

//core_subnet_privates_display_name = "private"
core_subnet_privates_cidr_blocks = ["10.0.0.0/24", "10.0.1.0/24"]
//core_subnet_publics_display_name = "public"
core_subnet_publics_cidr_blocks = ["10.0.10.0/24", "10.0.11.0/24"]

# RT
core_route_table_publics_display_name = "public-rt"
core_route_table_privates_display_name = "private-rt"

# internet gateway
enable_core_internet_gateway = true
core_internet_gateway_display_name = "my-igtw"
core_internet_gateway_enabled = true

# nat gateway
enable_core_nat_gateway = true
core_nat_gateway_display_name = "my-natgtw"
core_nat_gateway_block_traffic = null
}
2 changes: 1 addition & 1 deletion oracle_cloud/modules/core_vcn/dhcp_options.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ resource "oci_core_dhcp_options" "core_dhcp_options" {
count = var.enable_core_dhcp_options ? 1 : 0

# Required
compartment_id = var.core_dhcp_options_compartment_id
compartment_id = var.compartment_id

dynamic "options" {
iterator = options
Expand Down
2 changes: 1 addition & 1 deletion oracle_cloud/modules/core_vcn/internet_gateway.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ resource "oci_core_internet_gateway" "core_internet_gateway" {
count = var.enable_core_internet_gateway ? 1 : 0

# Required
compartment_id = var.core_internet_gateway_compartment_id
compartment_id = var.compartment_id
vcn_id = var.core_internet_gateway_vcn_id != "" && !var.enable_core_vcn ? var.core_internet_gateway_vcn_id : (var.enable_core_vcn ? element(oci_core_vcn.core_vcn.*.id, 0) : null)

# Optional
Expand Down
2 changes: 1 addition & 1 deletion oracle_cloud/modules/core_vcn/local_peering_gateway.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ resource "oci_core_local_peering_gateway" "core_local_peering_gateway" {
count = var.enable_core_local_peering_gateway ? 1 : 0

# Required
compartment_id = var.core_local_peering_gateway_compartment_id
compartment_id = var.compartment_id
vcn_id = var.core_local_peering_gateway_vcn_id != "" && !var.enable_core_vcn ? var.core_local_peering_gateway_vcn_id : (var.enable_core_vcn ? element(oci_core_vcn.core_vcn.*.id, 0) : null)

# Optional
Expand Down
2 changes: 1 addition & 1 deletion oracle_cloud/modules/core_vcn/nat_gateway.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ resource "oci_core_nat_gateway" "core_nat_gateway" {
count = var.enable_core_nat_gateway ? 1 : 0

# Required
compartment_id = var.core_nat_gateway_compartment_id
compartment_id = var.compartment_id
vcn_id = var.core_nat_gateway_vcn_id != "" && !var.enable_core_vcn ? var.core_nat_gateway_vcn_id : (var.enable_core_vcn ? element(oci_core_vcn.core_vcn.*.id, 0) : null)

# Optional
Expand Down
286 changes: 286 additions & 0 deletions oracle_cloud/modules/core_vcn/outputs.tf

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion oracle_cloud/modules/core_vcn/public_ip.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ resource "oci_core_public_ip" "core_public_ip" {
count = var.enable_core_public_ip ? 1 : 0

# Required
compartment_id = var.core_public_ip_compartment_id
compartment_id = var.compartment_id
lifetime = var.core_public_ip_lifetime

# Optional
Expand Down
2 changes: 1 addition & 1 deletion oracle_cloud/modules/core_vcn/public_ip_pool.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ resource "oci_core_public_ip_pool" "core_public_ip_pool" {
count = var.enable_core_public_ip_pool ? 1 : 0

# Required
compartment_id = var.core_public_ip_pool_compartment_id
compartment_id = var.compartment_id

# Optional
display_name = var.core_public_ip_pool_display_name != "" ? var.core_public_ip_pool_display_name : "${lower(var.name)}-public-ip-${lower(var.environment)}-${count.index + 1}"
Expand Down
110 changes: 104 additions & 6 deletions oracle_cloud/modules/core_vcn/route_table.tf
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
#-----------------------------------------------------------
# core route table
# core route table (default)
#-----------------------------------------------------------
resource "oci_core_route_table" "core_route_table" {
count = var.enable_core_route_table ? 1 : 0

# Required
compartment_id = var.core_route_table_compartment_id
compartment_id = var.compartment_id
vcn_id = var.core_route_table_vcn_id != "" && !var.enable_core_vcn ? var.core_route_table_vcn_id : (var.enable_core_vcn ? element(oci_core_vcn.core_vcn.*.id, 0) : null)

#Optional
# Optional
display_name = var.core_route_table_display_name != "" ? var.core_route_table_display_name : "${lower(var.name)}-route-table-${lower(var.environment)}"

dynamic "route_rules" {
iterator = route_rules
for_each = var.core_route_table_route_rules

content {
# Required
network_entity_id = lookup(route_rules.value, "network_entity_id", null) #oci_core_internet_gateway.core_internet_gateway.id
network_entity_id = lookup(route_rules.value, "network_entity_id", null)

# Optional
cidr_block = lookup(route_rules.value, "cidr_block", null)
description = lookup(route_rules.value, "description", null)
destination = lookup(route_rules.value, "destination", null)
destination_type = lookup(route_rules.value, "destination_type", null)
Expand Down Expand Up @@ -51,5 +49,105 @@ resource "oci_core_route_table" "core_route_table" {
ignore_changes = []
}

depends_on = []
}

#-----------------------------------------------------------
# core route table (public subnets)
#-----------------------------------------------------------
resource "oci_core_route_table" "core_route_table_publics" {
count = var.enable_core_nat_gateway && length(var.core_subnet_publics_cidr_blocks) > 0 ? 1 : 0

# Required
compartment_id = var.compartment_id
vcn_id = var.core_route_table_publics_vcn_id != "" && !var.enable_core_vcn ? var.core_route_table_publics_vcn_id : (var.enable_core_vcn ? element(oci_core_vcn.core_vcn.*.id, 0) : null)

# Optional
display_name = var.core_route_table_publics_display_name != "" ? var.core_route_table_publics_display_name : "${lower(var.name)}-route-table-public-${lower(var.environment)}"

route_rules {
# Required
network_entity_id = element(oci_core_nat_gateway.core_nat_gateway.*.id, 0)

# Optional
description = "nat-gtw"
destination = "0.0.0.0/0"
destination_type = "CIDR_BLOCK"
}

defined_tags = var.core_route_table_publics_defined_tags
freeform_tags = merge(
{
"Name" = var.core_route_table_publics_display_name != "" ? var.core_route_table_publics_display_name : "${lower(var.name)}-route-table-public-${lower(var.environment)}"
},
var.tags
)

dynamic "timeouts" {
iterator = timeouts
for_each = length(keys(var.core_route_table_publics_timeouts)) > 0 ? [var.core_route_table_publics_timeouts] : []

content {
create = lookup(timeouts.value, "create", null)
update = lookup(timeouts.value, "update", null)
delete = lookup(timeouts.value, "delete", null)
}
}

lifecycle {
create_before_destroy = true
ignore_changes = []
}

depends_on = []
}

#-----------------------------------------------------------
# core route table (private subnets)
#-----------------------------------------------------------
resource "oci_core_route_table" "core_route_table_privates" {
count = var.enable_core_internet_gateway && length(var.core_subnet_privates_cidr_blocks) > 0 ? 1 : 0

# Required
compartment_id = var.compartment_id
vcn_id = var.core_route_table_privates_vcn_id != "" && !var.enable_core_vcn ? var.core_route_table_privates_vcn_id : (var.enable_core_vcn ? element(oci_core_vcn.core_vcn.*.id, 0) : null)

# Optional
display_name = var.core_route_table_privates_display_name != "" ? var.core_route_table_privates_display_name : "${lower(var.name)}-route-table-private-${lower(var.environment)}"

route_rules {
# Required
network_entity_id = element(oci_core_internet_gateway.core_internet_gateway.*.id, 0)

# Optional
description = "i-gtw"
destination = "0.0.0.0/0"
destination_type = "CIDR_BLOCK"
}

defined_tags = var.core_route_table_privates_defined_tags
freeform_tags = merge(
{
"Name" = var.core_route_table_privates_display_name != "" ? var.core_route_table_privates_display_name : "${lower(var.name)}-route-table-private-${lower(var.environment)}"
},
var.tags
)

dynamic "timeouts" {
iterator = timeouts
for_each = length(keys(var.core_route_table_privates_timeouts)) > 0 ? [var.core_route_table_privates_timeouts] : []

content {
create = lookup(timeouts.value, "create", null)
update = lookup(timeouts.value, "update", null)
delete = lookup(timeouts.value, "delete", null)
}
}

lifecycle {
create_before_destroy = true
ignore_changes = []
}

depends_on = []
}
41 changes: 39 additions & 2 deletions oracle_cloud/modules/core_vcn/route_table_attachment.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#-----------------------------------------------------------
# core route table attachment
# core route table attachment (default)
#-----------------------------------------------------------
resource "oci_core_route_table_attachment" "core_route_table_attachment" {
# TODO: Add multile subnets (publics + privates)
count = var.enable_core_route_table_attachment ? 1 : 0

# Required
Expand All @@ -14,4 +15,40 @@ resource "oci_core_route_table_attachment" "core_route_table_attachment" {
}

depends_on = []
}
}

#-----------------------------------------------------------
# core route table attachment (publics)
#-----------------------------------------------------------
resource "oci_core_route_table_attachment" "core_route_table_attachment_publics" {
count = var.enable_core_nat_gateway && length(var.core_subnet_publics_cidr_blocks) > 0 ? length(var.core_subnet_publics_cidr_blocks) : 0

# Required
subnet_id = element(oci_core_subnet.core_subnet_publics.*.id, count.index)
route_table_id = element(oci_core_route_table.core_route_table_publics.*.id, 0)

lifecycle {
create_before_destroy = true
ignore_changes = []
}

depends_on = []
}

#-----------------------------------------------------------
# core route table attachment (privates)
#-----------------------------------------------------------
resource "oci_core_route_table_attachment" "core_route_table_attachment_privates" {
count = var.enable_core_nat_gateway && length(var.core_subnet_privates_cidr_blocks) > 0 ? length(var.core_subnet_privates_cidr_blocks) : 0

# Required
subnet_id = element(oci_core_subnet.core_subnet_privates.*.id, count.index)
route_table_id = element(oci_core_route_table.core_route_table_privates.*.id, 0)

lifecycle {
create_before_destroy = true
ignore_changes = []
}

depends_on = []
}
2 changes: 1 addition & 1 deletion oracle_cloud/modules/core_vcn/service_gateway.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ resource "oci_core_service_gateway" "core_service_gateway" {
count = var.enable_core_service_gateway ? 1 : 0

# Required
compartment_id = var.core_service_gateway_compartment_id
compartment_id = var.compartment_id

dynamic "services" {
iterator = services
Expand Down
Loading

0 comments on commit 2499802

Please sign in to comment.