Skip to content

Commit c1d786f

Browse files
feat: Switch default route deletion to use native method. (#185)
* switch to delete_default_routes_on_create * linter and generate docs * fix description * revert to original variable name
1 parent 7e5f5ab commit c1d786f

File tree

15 files changed

+30
-161
lines changed

15 files changed

+30
-161
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ Then perform the following commands on the root folder:
9595
| Name | Description | Type | Default | Required |
9696
|------|-------------|:----:|:-----:|:-----:|
9797
| auto\_create\_subnetworks | When set to true, the network is created in 'auto subnet mode' and it will create a subnet for each region automatically across the 10.128.0.0/9 address range. When set to false, the network is created in 'custom subnet mode' so the user can explicitly connect subnetwork resources. | bool | `"false"` | no |
98-
| delete\_default\_internet\_gateway\_routes | If set, ensure that all routes within the network specified whose names begin with 'default-route' and with a next hop of 'default-internet-gateway' are deleted | string | `"false"` | no |
98+
| delete\_default\_internet\_gateway\_routes | If set, ensure that all routes within the network specified whose names begin with 'default-route' and with a next hop of 'default-internet-gateway' are deleted | bool | `"false"` | no |
9999
| description | An optional description of this resource. The resource must be recreated to modify this field. | string | `""` | no |
100100
| network\_name | The name of the network being created | string | n/a | yes |
101101
| project\_id | The ID of the project where this VPC will be created | string | n/a | yes |

examples/delete_default_gateway_routes/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ module "test-vpc-module" {
3030
source = "../../"
3131
project_id = var.project_id
3232
network_name = var.network_name
33-
delete_default_internet_gateway_routes = "true"
33+
delete_default_internet_gateway_routes = true
3434

3535
subnets = [
3636
{

main.tf

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,14 @@
1818
VPC configuration
1919
*****************************************/
2020
module "vpc" {
21-
source = "./modules/vpc"
22-
network_name = var.network_name
23-
auto_create_subnetworks = var.auto_create_subnetworks
24-
routing_mode = var.routing_mode
25-
project_id = var.project_id
26-
description = var.description
27-
shared_vpc_host = var.shared_vpc_host
21+
source = "./modules/vpc"
22+
network_name = var.network_name
23+
auto_create_subnetworks = var.auto_create_subnetworks
24+
routing_mode = var.routing_mode
25+
project_id = var.project_id
26+
description = var.description
27+
shared_vpc_host = var.shared_vpc_host
28+
delete_default_internet_gateway_routes = var.delete_default_internet_gateway_routes
2829
}
2930

3031
/******************************************
@@ -42,10 +43,9 @@ module "subnets" {
4243
Routes
4344
*****************************************/
4445
module "routes" {
45-
source = "./modules/routes"
46-
project_id = var.project_id
47-
network_name = module.vpc.network_name
48-
routes = var.routes
49-
delete_default_internet_gateway_routes = var.delete_default_internet_gateway_routes
50-
module_depends_on = [module.subnets.subnets]
46+
source = "./modules/routes"
47+
project_id = var.project_id
48+
network_name = module.vpc.network_name
49+
routes = var.routes
50+
module_depends_on = [module.subnets.subnets]
5151
}

modules/routes-beta/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ module "vpc" {
5757

5858
| Name | Description | Type | Default | Required |
5959
|------|-------------|:----:|:-----:|:-----:|
60-
| delete\_default\_internet\_gateway\_routes | If set, ensure that all routes within the network specified whose names begin with 'default-route' and with a next hop of 'default-internet-gateway' are deleted | string | `"false"` | no |
6160
| module\_depends\_on | List of modules or resources this module depends on. | list | `<list>` | no |
6261
| network\_name | The name of the network where routes will be created | string | n/a | yes |
6362
| project\_id | The ID of the project where the routes will be created | string | n/a | yes |

modules/routes-beta/main.tf

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,3 @@ resource "google_compute_route" "route" {
3838

3939
depends_on = [var.module_depends_on]
4040
}
41-
42-
resource "null_resource" "delete_default_internet_gateway_routes" {
43-
count = var.delete_default_internet_gateway_routes ? 1 : 0
44-
45-
provisioner "local-exec" {
46-
command = "${path.module}/scripts/delete-default-gateway-routes.sh ${var.project_id} ${var.network_name}"
47-
}
48-
49-
triggers = {
50-
number_of_routes = length(var.routes)
51-
}
52-
53-
depends_on = [
54-
google_compute_route.route,
55-
]
56-
}

modules/routes-beta/scripts/delete-default-gateway-routes.sh

Lines changed: 0 additions & 48 deletions
This file was deleted.

modules/routes-beta/variables.tf

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,6 @@ variable "routes_count" {
3434
default = 0
3535
}
3636

37-
variable "delete_default_internet_gateway_routes" {
38-
description = "If set, ensure that all routes within the network specified whose names begin with 'default-route' and with a next hop of 'default-internet-gateway' are deleted"
39-
default = "false"
40-
}
41-
4237
variable "module_depends_on" {
4338
description = "List of modules or resources this module depends on."
4439
type = list

modules/routes/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ module "vpc" {
4646

4747
| Name | Description | Type | Default | Required |
4848
|------|-------------|:----:|:-----:|:-----:|
49-
| delete\_default\_internet\_gateway\_routes | If set, ensure that all routes within the network specified whose names begin with 'default-route' and with a next hop of 'default-internet-gateway' are deleted | string | `"false"` | no |
5049
| module\_depends\_on | List of modules or resources this module depends on. | list | `<list>` | no |
5150
| network\_name | The name of the network where routes will be created | string | n/a | yes |
5251
| project\_id | The ID of the project where the routes will be created | string | n/a | yes |

modules/routes/main.tf

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,3 @@ resource "google_compute_route" "route" {
4343

4444
depends_on = [var.module_depends_on]
4545
}
46-
47-
resource "null_resource" "delete_default_internet_gateway_routes" {
48-
count = var.delete_default_internet_gateway_routes ? 1 : 0
49-
50-
provisioner "local-exec" {
51-
command = "${path.module}/scripts/delete-default-gateway-routes.sh ${var.project_id} ${var.network_name}"
52-
}
53-
54-
triggers = {
55-
number_of_routes = length(var.routes)
56-
}
57-
58-
depends_on = [
59-
google_compute_route.route,
60-
]
61-
}

modules/routes/scripts/delete-default-gateway-routes.sh

Lines changed: 0 additions & 48 deletions
This file was deleted.

0 commit comments

Comments
 (0)