Skip to content

Commit febc50e

Browse files
authored
feat adopt new DRG module (#546)
* WIP - feat adopt new DRG module * use new standalone DRG module
1 parent 44a5f47 commit febc50e

File tree

5 files changed

+58
-7
lines changed

5 files changed

+58
-7
lines changed

locals.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,6 @@ locals {
99
vcn_id = var.create_vcn == true ? module.vcn[0].vcn_id : coalesce(var.vcn_id, data.oci_core_vcns.vcns[0].virtual_networks[0].id)
1010
ig_route_id = var.create_vcn == true ? module.vcn[0].ig_route_id : coalesce(var.ig_route_table_id, data.oci_core_route_tables.ig[0].route_tables[0].id)
1111
nat_route_id = var.create_vcn == true ? module.vcn[0].nat_route_id : coalesce(var.nat_route_table_id, data.oci_core_route_tables.nat[0].route_tables[0].id)
12+
13+
validate_drg_input = var.create_drg && (var.drg_id != null) ? tobool("[ERROR]: create_drg variable can not be true if drg_id is provided.]") : true
1214
}

main.tf

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
module "vcn" {
55
source = "oracle-terraform-modules/vcn/oci"
6-
version = "3.4.0"
6+
version = "3.5.0"
77

88
# general oci parameters
99
compartment_id = var.compartment_id
@@ -14,7 +14,7 @@ module "vcn" {
1414
create_nat_gateway = var.worker_type == "private" || var.create_operator == true || (var.load_balancers == "internal" || var.load_balancers == "both") ? true : false
1515
create_service_gateway = true
1616
nat_gateway_public_ip_id = var.nat_gateway_public_ip_id
17-
create_drg = var.create_drg
17+
attached_drg_id = var.drg_id != null ? var.drg_id : (var.create_drg ? module.drg[0].drg_id : null)
1818

1919
# lpgs
2020
local_peering_gateways = var.local_peering_gateways
@@ -33,6 +33,29 @@ module "vcn" {
3333
count = var.create_vcn == true ? 1 : 0
3434
}
3535

36+
module "drg" {
37+
38+
source = "oracle-terraform-modules/drg/oci"
39+
version = "1.0.3"
40+
41+
# general oci parameters
42+
compartment_id = var.compartment_id
43+
label_prefix = var.label_prefix
44+
45+
# drg parameters
46+
drg_display_name = var.drg_display_name
47+
drg_vcn_attachments = { for k, v in module.vcn : k => {
48+
# gets the vcn_id values dynamically from the vcn module
49+
vcn_id : v.vcn_id
50+
vcn_transit_routing_rt_id : null
51+
drg_route_table_id : null
52+
}
53+
}
54+
# var.drg_id can either contain an existing DRG ID or be null.
55+
drg_id = var.drg_id
56+
57+
count = var.create_drg || var.drg_id != null ? 1 : 0
58+
}
3659

3760
module "bastion" {
3861
source = "oracle-terraform-modules/bastion/oci"

outputs.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ output "vcn_id" {
4343
value = local.vcn_id
4444
}
4545

46+
output "drg_id" {
47+
description = "ID of DRG. use this DRG id to add additional resources"
48+
value = var.create_drg || var.drg_id != null ? module.drg[0].drg_id : null
49+
}
50+
4651
# convenient output
4752

4853
output "bastion_public_ip" {

terraform.tfvars.example

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,31 @@ ssh_private_key_path = "~/.ssh/id_rsa"
3434
# ssh_public_key_path = "~/.ssh/id_rsa.pub"
3535

3636
# networking
37-
create_drg = false
38-
drg_display_name = "drg"
39-
40-
internet_gateway_route_rules = []
37+
create_drg = false
38+
drg_display_name = "drg"
39+
drg_id = null
40+
41+
internet_gateway_route_rules = [
42+
# {
43+
# destination = "192.168.0.0/16" # Route Rule Destination CIDR
44+
# destination_type = "CIDR_BLOCK" # only CIDR_BLOCK is supported at the moment
45+
# network_entity_id = "drg" # for internet_gateway_route_rules input variable, you can use special strings "drg", "internet_gateway" or pass a valid OCID using string or any Named Values
46+
# description = "Terraformed - User added Routing Rule: To drg provided to this module. drg_id, if available, is automatically retrieved with keyword drg"
47+
# },
48+
]
4149

4250
local_peering_gateways = {}
4351

4452
lockdown_default_seclist = true
4553

46-
nat_gateway_route_rules = []
54+
nat_gateway_route_rules = [
55+
# {
56+
# destination = "192.168.0.0/16" # Route Rule Destination CIDR
57+
# destination_type = "CIDR_BLOCK" # only CIDR_BLOCK is supported at the moment
58+
# network_entity_id = "drg" # for nat_gateway_route_rules input variable, you can use special strings "drg", "nat_gateway" or pass a valid OCID using string or any Named Values
59+
# description = "Terraformed - User added Routing Rule: To drg provided to this module. drg_id, if available, is automatically retrieved with keyword drg"
60+
# },
61+
]
4762

4863
nat_gateway_public_ip_id = "none"
4964

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,12 @@ variable "drg_display_name" {
147147
default = "drg"
148148
}
149149

150+
variable "drg_id"{
151+
description = "ID of an external created Dynamic Routing Gateway to be attached to the VCN"
152+
type = string
153+
default = null
154+
}
155+
150156
variable "internet_gateway_route_rules" {
151157
description = "(Updatable) List of routing rules to add to Internet Gateway Route Table"
152158
type = list(map(string))

0 commit comments

Comments
 (0)