Skip to content

Commit 6c94a6f

Browse files
authored
feat: Add beta provider support for routes and subnets (#124)
Fixes #68
1 parent 6899580 commit 6c94a6f

File tree

33 files changed

+1380
-30
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

33 files changed

+1380
-30
lines changed

.kitchen.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,3 +147,16 @@ suites:
147147
backend: local
148148
controls:
149149
- gcloud
150+
- name: "ilb_routing"
151+
driver:
152+
name: "terraform"
153+
command_timeout: 1800
154+
root_module_directory: test/fixtures/ilb_routing/
155+
verifier:
156+
name: terraform
157+
color: true
158+
systems:
159+
- name: local
160+
backend: local
161+
controls:
162+
- gcloud

examples/ilb_routing/README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# ILB routing example
2+
3+
This example configures a single VPC inside of a project.
4+
5+
This VPC has three subnets and a forwarding rule. Please note, that this is simply example resource usage, this module
6+
wouldn't work as is.
7+
8+
More information:
9+
- https://cloud.google.com/load-balancing/docs/internal/setting-up-ilb-next-hop
10+
- https://cloud.google.com/load-balancing/docs/l7-internal/proxy-only-subnets
11+
12+
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
13+
## Inputs
14+
15+
| Name | Description | Type | Default | Required |
16+
|------|-------------|:----:|:-----:|:-----:|
17+
| network\_name | The name of the VPC network being created | string | n/a | yes |
18+
| project\_id | The project ID to host the network in | string | n/a | yes |
19+
20+
## Outputs
21+
22+
| Name | Description |
23+
|------|-------------|
24+
| forwarding\_rule | Forwarding rule link |
25+
| network\_name | The name of the VPC being created |
26+
| network\_self\_link | The URI of the VPC being created |
27+
| project\_id | VPC project id |
28+
| route\_names | The routes associated with this VPC |
29+
| subnets\_ips | The IP and cidrs of the subnets being created |
30+
| subnets\_names | The names of the subnets being created |
31+
| subnets\_regions | The region where subnets will be created |
32+
33+
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

examples/ilb_routing/main.tf

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
/**
2+
* Copyright 2019 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
provider "google" {
18+
version = "~> 2.19.0"
19+
}
20+
21+
provider "google-beta" {
22+
version = "~> 2.19.0"
23+
}
24+
25+
provider "null" {
26+
version = "~> 2.1"
27+
}
28+
29+
module "vpc" {
30+
source = "../../modules/vpc"
31+
network_name = var.network_name
32+
project_id = var.project_id
33+
}
34+
35+
module "subnets" {
36+
source = "../../modules/subnets-beta"
37+
project_id = var.project_id
38+
network_name = module.vpc.network_name
39+
40+
subnets = [
41+
{
42+
subnet_name = "${var.network_name}-subnet"
43+
subnet_ip = "10.10.10.0/24"
44+
subnet_region = "us-west1"
45+
},
46+
{
47+
subnet_name = "${var.network_name}-subnet-01"
48+
subnet_ip = "10.20.10.0/24"
49+
subnet_region = "us-west1"
50+
purpose = "INTERNAL_HTTPS_LOAD_BALANCER"
51+
role = "ACTIVE"
52+
}
53+
]
54+
}
55+
56+
module "subnets-backup" {
57+
source = "../../modules/subnets-beta"
58+
project_id = var.project_id
59+
network_name = module.vpc.network_name
60+
61+
subnets = [
62+
{
63+
subnet_name = "${var.network_name}-subnet-02"
64+
subnet_ip = "10.20.20.0/24"
65+
subnet_region = "us-west1"
66+
purpose = "INTERNAL_HTTPS_LOAD_BALANCER"
67+
role = "BACKUP"
68+
}
69+
]
70+
71+
module_depends_on = [module.subnets.subnets]
72+
}
73+
74+
resource "google_compute_health_check" "this" {
75+
project = var.project_id
76+
name = "${var.network_name}-test"
77+
check_interval_sec = 1
78+
timeout_sec = 1
79+
80+
tcp_health_check {
81+
port = "80"
82+
}
83+
}
84+
85+
resource "google_compute_region_backend_service" "this" {
86+
project = var.project_id
87+
name = "${var.network_name}-test"
88+
region = "us-west1"
89+
health_checks = [google_compute_health_check.this.self_link]
90+
}
91+
92+
resource "google_compute_forwarding_rule" "this" {
93+
project = var.project_id
94+
name = "${var.network_name}-fw-role"
95+
96+
network = module.vpc.network_name
97+
subnetwork = module.subnets.subnets["us-west1/${var.network_name}-subnet"].name
98+
backend_service = google_compute_region_backend_service.this.self_link
99+
region = "us-west1"
100+
load_balancing_scheme = "INTERNAL"
101+
all_ports = true
102+
}
103+
104+
module "routes" {
105+
source = "../../modules/routes-beta"
106+
project_id = var.project_id
107+
network_name = module.vpc.network_name
108+
routes_count = 2
109+
110+
routes = [
111+
{
112+
name = "${var.network_name}-egress-inet"
113+
description = "route through IGW to access internet"
114+
destination_range = "0.0.0.0/0"
115+
tags = "egress-inet"
116+
next_hop_internet = "true"
117+
},
118+
{
119+
name = "${var.network_name}-ilb"
120+
description = "route through ilb"
121+
destination_range = "10.10.20.0/24"
122+
next_hop_ilb = google_compute_forwarding_rule.this.self_link
123+
},
124+
]
125+
126+
module_depends_on = [module.subnets.subnets, module.subnets-backup.subnets]
127+
}

examples/ilb_routing/outputs.tf

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/**
2+
* Copyright 2019 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
output "network_name" {
18+
value = module.vpc.network_name
19+
description = "The name of the VPC being created"
20+
}
21+
22+
output "network_self_link" {
23+
value = module.vpc.network_self_link
24+
description = "The URI of the VPC being created"
25+
}
26+
27+
output "project_id" {
28+
value = module.vpc.project_id
29+
description = "VPC project id"
30+
}
31+
32+
output "subnets_names" {
33+
value = [for network in concat(module.subnets.subnets, module.subnets-backup.subnets) : network.name]
34+
description = "The names of the subnets being created"
35+
}
36+
37+
output "subnets_ips" {
38+
value = [for network in concat(module.subnets.subnets, module.subnets-backup.subnets) : network.ip_cidr_range]
39+
description = "The IP and cidrs of the subnets being created"
40+
}
41+
42+
output "subnets_regions" {
43+
value = [for network in concat(module.subnets.subnets, module.subnets-backup.subnets) : network.region]
44+
description = "The region where subnets will be created"
45+
}
46+
47+
output "route_names" {
48+
value = [for route in module.routes.routes : route.name]
49+
description = "The routes associated with this VPC"
50+
}
51+
52+
output "forwarding_rule" {
53+
value = google_compute_forwarding_rule.this.self_link
54+
description = "Forwarding rule link"
55+
}

examples/ilb_routing/variables.tf

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* Copyright 2019 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
variable "project_id" {
18+
description = "The project ID to host the network in"
19+
}
20+
21+
variable "network_name" {
22+
description = "The name of the VPC network being created"
23+
}

examples/ilb_routing/versions.tf

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* Copyright 2019 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
terraform {
18+
required_version = "~> 0.12.6"
19+
}

modules/routes-beta/README.md

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# Terraform Network Beta Module
2+
3+
This submodule is part of the the `terraform-google-network` module. It creates the individual vpc routes and optionally deletes the default internet gateway routes.
4+
5+
It supports creating:
6+
7+
- Routes within vpc network.
8+
- Optionally deletes the default internet gateway routes.
9+
10+
It also uses google beta provider to support the following resource fields:
11+
12+
- google_compute_route.next_hop_ilb
13+
14+
## Usage
15+
16+
Basic usage of this submodule is as follows:
17+
18+
```hcl
19+
module "vpc" {
20+
source = "terraform-google-modules/network/google//modules/routes-beta"
21+
version = "~> 2.0.0"
22+
23+
project_id = "<PROJECT ID>"
24+
network_name = "example-vpc"
25+
26+
delete_default_internet_gateway_routes = false
27+
28+
routes = [
29+
{
30+
name = "egress-internet"
31+
description = "route through IGW to access internet"
32+
destination_range = "0.0.0.0/0"
33+
tags = "egress-inet"
34+
next_hop_internet = "true"
35+
},
36+
{
37+
name = "app-proxy"
38+
description = "route through proxy to reach app"
39+
destination_range = "10.50.10.0/24"
40+
tags = "app-proxy"
41+
next_hop_instance = "app-proxy-instance"
42+
next_hop_instance_zone = "us-west1-a"
43+
},
44+
{
45+
name = "test-proxy"
46+
description = "route through idp to reach app"
47+
destination_range = "10.50.10.0/24"
48+
tags = "app-proxy"
49+
next_hop_ilb = var.ilb_link
50+
},
51+
]
52+
}
53+
```
54+
55+
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
56+
## Inputs
57+
58+
| Name | Description | Type | Default | Required |
59+
|------|-------------|:----:|:-----:|:-----:|
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 |
61+
| module\_depends\_on | List of modules or resources this module depends on. | list | `<list>` | no |
62+
| network\_name | The name of the network where routes will be created | string | n/a | yes |
63+
| project\_id | The ID of the project where the routes will be created | string | n/a | yes |
64+
| routes | List of routes being created in this VPC | list(map(string)) | `<list>` | no |
65+
| routes\_count | Amount of routes being created in this VPC | number | `"0"` | no |
66+
67+
## Outputs
68+
69+
| Name | Description |
70+
|------|-------------|
71+
| routes | The created routes resources |
72+
73+
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
74+
75+
76+
### Routes Input
77+
78+
The routes list contains maps, where each object represents a route. For the next_hop_* inputs, only one is possible to be used in each route. Having two next_hop_* inputs will produce an error. Each map has the following inputs (please see examples folder for additional references):
79+
80+
| Name | Description | Type | Default | Required |
81+
|------|-------------|:----:|:-----:|:-----:|
82+
| name | The name of the route being created | string | - | no |
83+
| description | The description of the route being created | string | - | no |
84+
| tags | The network tags assigned to this route. This is a list in string format. Eg. "tag-01,tag-02"| string | - | yes |
85+
| destination\_range | The destination range of outgoing packets that this route applies to. Only IPv4 is supported | string | - | yes
86+
| next\_hop\_internet | Whether the next hop to this route will the default internet gateway. Use "true" to enable this as next hop | string | `"false"` | yes |
87+
| next\_hop\_ip | Network IP address of an instance that should handle matching packets | string | - | yes |
88+
| next\_hop\_instance | URL or name of an instance that should handle matching packets. If just name is specified "next\_hop\_instance\_zone" is required | string | - | yes |
89+
| next\_hop\_instance\_zone | The zone of the instance specified in next\_hop\_instance. Only required if next\_hop\_instance is specified as a name | string | - | no |
90+
| next\_hop\_vpn\_tunnel | URL to a VpnTunnel that should handle matching packets | string | - | yes |
91+
| priority | The priority of this route. Priority is used to break ties in cases where there is more than one matching route of equal prefix length. In the case of two routes with equal prefix length, the one with the lowest-numbered priority value wins | string | `"1000"` | yes |

0 commit comments

Comments
 (0)