Skip to content

Commit 4eb6f87

Browse files
authored
fix: for breaking change introduced in #101 and causes destruction (#119)
* fix: for breaking change introduced in #101 and causes destruction and recreation of existing infrastructure Signed-off-by: Ali Mukadam <[email protected]> * fix: reverted to 3.5.3 position Signed-off-by: Ali Mukadam <[email protected]> * fix: removed redundant variables Signed-off-by: Ali Mukadam <[email protected]> * fix: removed commented line Signed-off-by: Ali Mukadam <[email protected]> --------- Signed-off-by: Ali Mukadam <[email protected]>
1 parent 1f6c697 commit 4eb6f87

File tree

10 files changed

+51
-32
lines changed

10 files changed

+51
-32
lines changed

examples/custom_route_rules/main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ terraform {
1616
# Resources
1717

1818
module "vcn" {
19-
19+
2020
source = "github.com/oracle-terraform-modules/terraform-oci-vcn"
2121
# to use the terraform registry version comment the previous line and uncomment the 2 lines below
2222
# source = "oracle-terraform-modules/vcn/oci"
@@ -26,7 +26,7 @@ module "vcn" {
2626
compartment_id = var.compartment_id
2727
label_prefix = var.label_prefix
2828
freeform_tags = var.freeform_tags
29-
defined_tags = var.defined_tags
29+
defined_tags = var.defined_tags
3030

3131
# vcn parameters
3232
create_internet_gateway = var.create_internet_gateway # boolean: true or false

examples/custom_route_rules/variables.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ variable "vcn_name" {
117117

118118
variable "attached_drg_id" {
119119
description = "the ID of DRG attached to the VCN"
120-
type = string
121-
default = null
120+
type = string
121+
default = null
122122
}
123123

124124
variable "internet_gateway_display_name" {

examples/drg/main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# Resources
99

1010
module "drg_hub" {
11-
11+
1212
source = "github.com/oracle-terraform-modules/terraform-oci-drg"
1313
# to use the terraform registry version comment the previous line and uncomment the 2 lines below
1414
# source = "oracle-terraform-modules/drg/oci"
@@ -33,7 +33,7 @@ module "drg_hub" {
3333
}
3434

3535
module "vcn_spokes" {
36-
36+
3737
source = "github.com/oracle-terraform-modules/terraform-oci-vcn"
3838
# to use the terraform registry version comment the previous line and uncomment the 2 lines below
3939
# source = "oracle-terraform-modules/vcn/oci"

examples/hub-spoke/main.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ module "vcn_hub" {
1616
compartment_id = var.compartment_id
1717
label_prefix = var.label_prefix
1818
freeform_tags = var.freeform_tags
19-
defined_tags = var.defined_tags
19+
defined_tags = var.defined_tags
2020

2121
# vcn parameters
2222
create_internet_gateway = var.create_internet_gateway # boolean: true or false
@@ -59,7 +59,7 @@ resource "oci_core_route_table" "VTR_spokes" {
5959

6060
module "vcn_spoke1" {
6161
# this module use the generic vcn module and configure it to act as a spoke in a hub-and-spoke topology
62-
62+
6363
source = "github.com/oracle-terraform-modules/terraform-oci-vcn"
6464
# to use the terraform registry version comment the previous line and uncomment the 2 lines below
6565
# source = "oracle-terraform-modules/vcn/oci"
@@ -91,7 +91,7 @@ module "vcn_spoke1" {
9191

9292
module "vcn_spoke2" {
9393
# this module use the generic vcn module and configure it to act as a spoke in a hub-and-spoke topology
94-
94+
9595
source = "github.com/oracle-terraform-modules/terraform-oci-vcn"
9696
# to use the terraform registry version comment the previous line and uncomment the 2 lines below
9797
# source = "oracle-terraform-modules/vcn/oci"
@@ -121,7 +121,7 @@ module "vcn_spoke2" {
121121

122122
module "vcn_spoke3" {
123123
# this module use the generic vcn module and configure it to act as a spoke in a hub-and-spoke topology
124-
124+
125125
source = "github.com/oracle-terraform-modules/terraform-oci-vcn"
126126
# to use the terraform registry version comment the previous line and uncomment the 2 lines below
127127
# source = "oracle-terraform-modules/vcn/oci"

examples/hub-spoke/variables.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ variable "vcn_name" {
116116

117117
variable "attached_drg_id" {
118118
description = "the ID of DRG attached to the VCN"
119-
type = string
120-
default = null
119+
type = string
120+
default = null
121121
}
122122

123123

examples/module_composition/main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# Resources
66

77
module "vcn" {
8-
8+
99
source = "github.com/oracle-terraform-modules/terraform-oci-vcn"
1010
# to use the terraform registry version comment the previous line and uncomment the 2 lines below
1111
# source = "oracle-terraform-modules/vcn/oci"
@@ -15,7 +15,7 @@ module "vcn" {
1515
compartment_id = var.compartment_id
1616
label_prefix = var.label_prefix
1717
freeform_tags = var.freeform_tags
18-
defined_tags = var.defined_tags
18+
defined_tags = var.defined_tags
1919

2020
# vcn parameters
2121
create_internet_gateway = var.create_internet_gateway # boolean: true or false

examples/module_composition/variables.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ variable "vcn_name" {
116116

117117
variable "attached_drg_id" {
118118
description = "the ID of DRG attached to the VCN"
119-
type = string
120-
default = null
119+
type = string
120+
default = null
121121
}
122122

123123

variables.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,13 +157,13 @@ variable "nat_gateway_route_rules" {
157157

158158
variable "attached_drg_id" {
159159
description = "the ID of DRG attached to the VCN"
160-
type = string
161-
default = null
160+
type = string
161+
default = null
162162
}
163163

164164
#subnets
165165
variable "subnets" {
166166
description = "Private or Public subnets in a VCN"
167167
type = any
168168
default = {}
169-
}
169+
}

vcn_defaultresources.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,6 @@ resource "oci_core_default_security_list" "restore_default" {
6262
lifecycle {
6363
ignore_changes = [egress_security_rules, ingress_security_rules, defined_tags]
6464
}
65-
65+
6666
count = var.lockdown_default_seclist == false ? 1 : 0
6767
}

vcn_gateways.tf

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ resource "oci_core_internet_gateway" "ig" {
1010
display_name = var.label_prefix == "none" ? var.internet_gateway_display_name : "${var.label_prefix}-${var.internet_gateway_display_name}"
1111

1212
freeform_tags = var.freeform_tags
13-
defined_tags = var.defined_tags
13+
defined_tags = var.defined_tags
1414

1515
vcn_id = oci_core_vcn.vcn.id
1616

@@ -26,7 +26,7 @@ resource "oci_core_route_table" "ig" {
2626
display_name = var.label_prefix == "none" ? "internet-route" : "${var.label_prefix}-internet-route"
2727

2828
freeform_tags = var.freeform_tags
29-
defined_tags = var.defined_tags
29+
defined_tags = var.defined_tags
3030

3131
route_rules {
3232
# * With this route table, Internet Gateway is always declared as the default gateway
@@ -50,12 +50,12 @@ resource "oci_core_route_table" "ig" {
5050
# * filter var.internet_gateway_route_rules for routes with "drg" as destination
5151
# * and steer traffic to the attached DRG if available
5252
for_each = var.internet_gateway_route_rules != null ? { for k, v in var.internet_gateway_route_rules : k => v
53-
if v.network_entity_id == "drg" && var.attached_drg_id != null} : {}
53+
if v.network_entity_id == "drg" && var.attached_drg_id != null } : {}
5454

5555
content {
5656
destination = route_rules.value.destination
5757
destination_type = route_rules.value.destination_type
58-
network_entity_id = var.attached_drg_id
58+
network_entity_id = var.attached_drg_id
5959
description = route_rules.value.description
6060
}
6161
}
@@ -115,7 +115,7 @@ resource "oci_core_service_gateway" "service_gateway" {
115115
display_name = var.label_prefix == "none" ? var.service_gateway_display_name : "${var.label_prefix}-${var.service_gateway_display_name}"
116116

117117
freeform_tags = var.freeform_tags
118-
defined_tags = var.defined_tags
118+
defined_tags = var.defined_tags
119119
services {
120120
service_id = lookup(data.oci_core_services.all_oci_services[0].services[0], "id")
121121
}
@@ -134,7 +134,7 @@ resource "oci_core_route_table" "service_gw" {
134134
display_name = var.label_prefix == "none" ? "service-gw-route" : "${var.label_prefix}-service-gw-route"
135135

136136
freeform_tags = var.freeform_tags
137-
defined_tags = var.defined_tags
137+
defined_tags = var.defined_tags
138138

139139
dynamic "route_rules" {
140140
# * If Service Gateway is created with the module, automatically creates a rule to handle traffic for "all services" through Service Gateway
@@ -165,7 +165,7 @@ resource "oci_core_nat_gateway" "nat_gateway" {
165165
display_name = var.label_prefix == "none" ? var.nat_gateway_display_name : "${var.label_prefix}-${var.nat_gateway_display_name}"
166166

167167
freeform_tags = var.freeform_tags
168-
defined_tags = var.defined_tags
168+
defined_tags = var.defined_tags
169169

170170
public_ip_id = var.nat_gateway_public_ip_id != "none" ? var.nat_gateway_public_ip_id : null
171171

@@ -178,12 +178,15 @@ resource "oci_core_nat_gateway" "nat_gateway" {
178178
count = var.create_nat_gateway == true ? 1 : 0
179179
}
180180

181+
# special fix due to bug introduced in #101 which causes destruction and recreation of subnets
182+
# for existing users
183+
181184
resource "oci_core_route_table" "nat" {
182185
compartment_id = var.compartment_id
183186
display_name = var.label_prefix == "none" ? "nat-route" : "${var.label_prefix}-nat-route"
184187

185188
freeform_tags = var.freeform_tags
186-
defined_tags = var.defined_tags
189+
defined_tags = var.defined_tags
187190

188191
route_rules {
189192
# * With this route table, NAT Gateway is always declared as the default gateway
@@ -193,11 +196,24 @@ resource "oci_core_route_table" "nat" {
193196
description = "Terraformed - Auto-generated at NAT Gateway creation: NAT Gateway as default gateway"
194197
}
195198

199+
# bring this block back to fix #101
200+
dynamic "route_rules" {
201+
# * If Service Gateway is created with the module, automatically creates a rule to handle traffic for "all services" through Service Gateway
202+
for_each = var.create_service_gateway == true ? [1] : []
203+
204+
content {
205+
destination = lookup(data.oci_core_services.all_oci_services[0].services[0], "cidr_block")
206+
destination_type = "SERVICE_CIDR_BLOCK"
207+
network_entity_id = oci_core_service_gateway.service_gateway[0].id
208+
description = "Terraformed - Auto-generated at Service Gateway creation: All Services in region to Service Gateway"
209+
}
210+
}
211+
196212
dynamic "route_rules" {
197213
# * filter var.nat_gateway_route_rules for routes with "drg" as destination
198214
# * and steer traffic to the attached DRG if available
199215
for_each = var.nat_gateway_route_rules != null ? { for k, v in var.nat_gateway_route_rules : k => v
200-
if v.network_entity_id == "drg" && var.attached_drg_id != null} : {}
216+
if v.network_entity_id == "drg" && var.attached_drg_id != null } : {}
201217

202218
content {
203219
destination = route_rules.value.destination
@@ -238,11 +254,14 @@ resource "oci_core_route_table" "nat" {
238254

239255
vcn_id = oci_core_vcn.vcn.id
240256

257+
# ignore changes to route rules to avoid recreation issues due to #101.
258+
# A fix may still be needed for when new custom route rules are added.
259+
241260
lifecycle {
242-
ignore_changes = [defined_tags, freeform_tags]
261+
ignore_changes = [defined_tags, freeform_tags, route_rules]
243262
}
244263

245-
count = var.create_nat_gateway == true ? 1 : 0
264+
count = var.create_nat_gateway ? 1 : 0
246265
}
247266

248267

@@ -257,7 +276,7 @@ resource "oci_core_local_peering_gateway" "lpg" {
257276
display_name = var.label_prefix == "none" ? each.key : "${var.label_prefix}-${each.key}"
258277

259278
freeform_tags = var.freeform_tags
260-
defined_tags = var.defined_tags
279+
defined_tags = var.defined_tags
261280

262281
vcn_id = oci_core_vcn.vcn.id
263282

0 commit comments

Comments
 (0)