Skip to content

Commit

Permalink
feat: Switch default route deletion to use native method. (#185)
Browse files Browse the repository at this point in the history
* switch to delete_default_routes_on_create

* linter and generate docs

* fix description

* revert to original variable name
  • Loading branch information
ChandranshuRao14 authored May 27, 2020
1 parent 7e5f5ab commit c1d786f
Show file tree
Hide file tree
Showing 15 changed files with 30 additions and 161 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ Then perform the following commands on the root folder:
| Name | Description | Type | Default | Required |
|------|-------------|:----:|:-----:|:-----:|
| 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 |
| 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 |
| 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 |
| description | An optional description of this resource. The resource must be recreated to modify this field. | string | `""` | no |
| network\_name | The name of the network being created | string | n/a | yes |
| project\_id | The ID of the project where this VPC will be created | string | n/a | yes |
Expand Down
2 changes: 1 addition & 1 deletion examples/delete_default_gateway_routes/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ module "test-vpc-module" {
source = "../../"
project_id = var.project_id
network_name = var.network_name
delete_default_internet_gateway_routes = "true"
delete_default_internet_gateway_routes = true

subnets = [
{
Expand Down
26 changes: 13 additions & 13 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@
VPC configuration
*****************************************/
module "vpc" {
source = "./modules/vpc"
network_name = var.network_name
auto_create_subnetworks = var.auto_create_subnetworks
routing_mode = var.routing_mode
project_id = var.project_id
description = var.description
shared_vpc_host = var.shared_vpc_host
source = "./modules/vpc"
network_name = var.network_name
auto_create_subnetworks = var.auto_create_subnetworks
routing_mode = var.routing_mode
project_id = var.project_id
description = var.description
shared_vpc_host = var.shared_vpc_host
delete_default_internet_gateway_routes = var.delete_default_internet_gateway_routes
}

/******************************************
Expand All @@ -42,10 +43,9 @@ module "subnets" {
Routes
*****************************************/
module "routes" {
source = "./modules/routes"
project_id = var.project_id
network_name = module.vpc.network_name
routes = var.routes
delete_default_internet_gateway_routes = var.delete_default_internet_gateway_routes
module_depends_on = [module.subnets.subnets]
source = "./modules/routes"
project_id = var.project_id
network_name = module.vpc.network_name
routes = var.routes
module_depends_on = [module.subnets.subnets]
}
1 change: 0 additions & 1 deletion modules/routes-beta/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ module "vpc" {

| Name | Description | Type | Default | Required |
|------|-------------|:----:|:-----:|:-----:|
| 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 |
| module\_depends\_on | List of modules or resources this module depends on. | list | `<list>` | no |
| network\_name | The name of the network where routes will be created | string | n/a | yes |
| project\_id | The ID of the project where the routes will be created | string | n/a | yes |
Expand Down
16 changes: 0 additions & 16 deletions modules/routes-beta/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,3 @@ resource "google_compute_route" "route" {

depends_on = [var.module_depends_on]
}

resource "null_resource" "delete_default_internet_gateway_routes" {
count = var.delete_default_internet_gateway_routes ? 1 : 0

provisioner "local-exec" {
command = "${path.module}/scripts/delete-default-gateway-routes.sh ${var.project_id} ${var.network_name}"
}

triggers = {
number_of_routes = length(var.routes)
}

depends_on = [
google_compute_route.route,
]
}
48 changes: 0 additions & 48 deletions modules/routes-beta/scripts/delete-default-gateway-routes.sh

This file was deleted.

5 changes: 0 additions & 5 deletions modules/routes-beta/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@ variable "routes_count" {
default = 0
}

variable "delete_default_internet_gateway_routes" {
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"
default = "false"
}

variable "module_depends_on" {
description = "List of modules or resources this module depends on."
type = list
Expand Down
1 change: 0 additions & 1 deletion modules/routes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ module "vpc" {

| Name | Description | Type | Default | Required |
|------|-------------|:----:|:-----:|:-----:|
| 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 |
| module\_depends\_on | List of modules or resources this module depends on. | list | `<list>` | no |
| network\_name | The name of the network where routes will be created | string | n/a | yes |
| project\_id | The ID of the project where the routes will be created | string | n/a | yes |
Expand Down
16 changes: 0 additions & 16 deletions modules/routes/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,3 @@ resource "google_compute_route" "route" {

depends_on = [var.module_depends_on]
}

resource "null_resource" "delete_default_internet_gateway_routes" {
count = var.delete_default_internet_gateway_routes ? 1 : 0

provisioner "local-exec" {
command = "${path.module}/scripts/delete-default-gateway-routes.sh ${var.project_id} ${var.network_name}"
}

triggers = {
number_of_routes = length(var.routes)
}

depends_on = [
google_compute_route.route,
]
}
48 changes: 0 additions & 48 deletions modules/routes/scripts/delete-default-gateway-routes.sh

This file was deleted.

5 changes: 0 additions & 5 deletions modules/routes/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@ variable "routes" {
default = []
}

variable "delete_default_internet_gateway_routes" {
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"
default = "false"
}

variable "module_depends_on" {
description = "List of modules or resources this module depends on."
type = list
Expand Down
1 change: 1 addition & 0 deletions modules/vpc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ module "vpc" {
| Name | Description | Type | Default | Required |
|------|-------------|:----:|:-----:|:-----:|
| 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 |
| 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 |
| description | An optional description of this resource. The resource must be recreated to modify this field. | string | `""` | no |
| network\_name | The name of the network being created | string | n/a | yes |
| project\_id | The ID of the project where this VPC will be created | string | n/a | yes |
Expand Down
11 changes: 6 additions & 5 deletions modules/vpc/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@
VPC configuration
*****************************************/
resource "google_compute_network" "network" {
name = var.network_name
auto_create_subnetworks = var.auto_create_subnetworks
routing_mode = var.routing_mode
project = var.project_id
description = var.description
name = var.network_name
auto_create_subnetworks = var.auto_create_subnetworks
routing_mode = var.routing_mode
project = var.project_id
description = var.description
delete_default_routes_on_create = var.delete_default_internet_gateway_routes
}

/******************************************
Expand Down
6 changes: 6 additions & 0 deletions modules/vpc/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,9 @@ variable "auto_create_subnetworks" {
description = "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."
default = false
}

variable "delete_default_internet_gateway_routes" {
type = bool
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"
default = false
}
3 changes: 2 additions & 1 deletion variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ variable "routes" {
}

variable "delete_default_internet_gateway_routes" {
type = bool
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"
default = "false"
default = false
}


Expand Down

0 comments on commit c1d786f

Please sign in to comment.