Skip to content

Commit adcf807

Browse files
authored
feat(TF>1.3)!: Min terraform version 1.3. Changed variables type object with optional parameters (#79)
1 parent d941648 commit adcf807

File tree

35 files changed

+1416
-302
lines changed

35 files changed

+1416
-302
lines changed

README.md

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
1-
# [terraform-google-cloud-router](https://registry.terraform.io/modules/terraform-google-modules/cloud-router/google)
1+
# [Cloud Router Terraform Module](https://registry.terraform.io/modules/terraform-google-modules/cloud-router/google)
22

3-
This module handles opinionated Google Cloud Platform routing.
3+
This module handles opinionated Google Cloud Platform [cloud router](https://cloud.google.com/network-connectivity/docs/router/concepts/overview). Optionally it can also create [cloud nat](https://cloud.google.com/nat/docs/overview)
4+
5+
## Compatibility
6+
7+
This module is meant for use with Terraform 1.3+ and tested using Terraform 1.3+. If you find incompatibilities using Terraform >=1.3, please open an issue.
8+
9+
## Version
10+
11+
Upgrade guides:
12+
13+
- [5.X -> 6.0.](/docs/upgrading_to_v6.0.md)
414

515
## Usage
616

@@ -9,27 +19,33 @@ Basic usage of this module is as follows:
919
```hcl
1020
module "cloud_router" {
1121
source = "terraform-google-modules/cloud-router/google"
12-
version = "~> 5.1"
22+
version = "~> 6.0"
1323
1424
name = "example-router"
15-
project = "<PROJECT ID>"
1625
region = "us-central1"
26+
27+
bgp = {
28+
# The ASN (16550, 64512 - 65534, 4200000000 - 4294967294) can be any private ASN
29+
# not already used as a peer ASN in the same region and network or 16550 for Partner Interconnect.
30+
asn = "65001"
31+
}
32+
33+
project = "<PROJECT ID>"
1734
network = "default"
1835
}
1936
```
2037

21-
Functional examples are included in the
22-
[examples](./examples/) directory.
38+
Functional examples are included in the [examples](./examples/) directory. By default logging will be enabled for `Cloud NAT` with `filter` set to `All`. You can disable cloud nat logging by setting parameters in `nats.log_config`
2339

2440
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
2541
## Inputs
2642

2743
| Name | Description | Type | Default | Required |
2844
|------|-------------|------|---------|:--------:|
29-
| bgp | BGP information specific to this router. | `any` | `null` | no |
45+
| bgp | BGP information specific to this router. | <pre>object({<br> asn = string<br> advertise_mode = optional(string, "CUSTOM")<br> advertised_groups = optional(list(string))<br> advertised_ip_ranges = optional(list(object({<br> range = string<br> description = optional(string)<br> })), [])<br> keepalive_interval = optional(number)<br> })</pre> | `null` | no |
3046
| description | An optional description of this resource | `string` | `null` | no |
3147
| name | Name of the router | `string` | n/a | yes |
32-
| nats | NATs to deploy on this router. | `any` | `[]` | no |
48+
| nats | NATs to deploy on this router. | <pre>list(object({<br> name = string<br> nat_ip_allocate_option = optional(string)<br> source_subnetwork_ip_ranges_to_nat = optional(string)<br> nat_ips = optional(list(string), [])<br> min_ports_per_vm = optional(number)<br> max_ports_per_vm = optional(number)<br> udp_idle_timeout_sec = optional(number)<br> icmp_idle_timeout_sec = optional(number)<br> tcp_established_idle_timeout_sec = optional(number)<br> tcp_transitory_idle_timeout_sec = optional(number)<br> tcp_time_wait_timeout_sec = optional(number)<br> enable_endpoint_independent_mapping = optional(bool)<br> enable_dynamic_port_allocation = optional(bool)<br><br> log_config = optional(object({<br> enable = optional(bool, true)<br> filter = optional(string, "ALL")<br> }), {})<br><br> subnetworks = optional(list(object({<br> name = string<br> source_ip_ranges_to_nat = string<br> secondary_ip_range_names = optional(string)<br> })), [])<br><br> }))</pre> | `[]` | no |
3349
| network | A reference to the network to which this router belongs | `string` | n/a | yes |
3450
| project | The project ID to deploy to | `string` | n/a | yes |
3551
| region | Region where the router resides | `string` | n/a | yes |
@@ -38,10 +54,15 @@ Functional examples are included in the
3854

3955
| Name | Description |
4056
|------|-------------|
41-
| router | The created router |
57+
| nat | Created NATs |
58+
| router | Created Router |
4259

4360
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
4461

62+
63+
## nats
64+
65+
4566
## Requirements
4667

4768
These sections describe requirements for using this module.
@@ -50,8 +71,8 @@ These sections describe requirements for using this module.
5071

5172
The following dependencies must be available:
5273

53-
- [Terraform][terraform] v0.12 and above
54-
- [Terraform Provider for GCP][terraform-provider-gcp] plugin v2.0
74+
- [Terraform][terraform] v1.3 and above
75+
- [Terraform Provider for GCP][terraform-provider-gcp] plugin v4.51 and above
5576

5677
### Service Account
5778

build/int.cloudbuild.yaml

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,47 @@ steps:
1919
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && module-swapper']
2020
- id: prepare
2121
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
22-
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && prepare_environment']
22+
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && prepare_environment && sleep 120']
2323
env:
2424
- 'TF_VAR_org_id=$_ORG_ID'
2525
- 'TF_VAR_folder_id=$_FOLDER_ID'
2626
- 'TF_VAR_billing_account=$_BILLING_ACCOUNT'
27-
- id: create
27+
- id: init-all
28+
waitFor:
29+
- prepare
2830
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
29-
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do create']
30-
- id: converge
31+
args: ['/bin/bash', '-c', 'cft test run all --stage init --verbose']
32+
- id: simple-example-apply
33+
waitFor:
34+
- init-all
3135
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
32-
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do converge']
33-
- id: verify
36+
args: ['/bin/bash', '-c', 'cft test run TestSimpleExample --stage apply --verbose']
37+
- id: simple-example-verify
38+
waitFor:
39+
- simple-example-apply
3440
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
35-
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do verify']
36-
- id: destroy
41+
args: ['/bin/bash', '-c', 'cft test run TestSimpleExample --stage verify --verbose']
42+
- id: simple-example-teardown
43+
waitFor:
44+
- simple-example-verify
3745
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
38-
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do destroy']
46+
args: ['/bin/bash', '-c', 'cft test run TestSimpleExample --stage teardown --verbose']
47+
48+
- id: nat-apply
49+
waitFor:
50+
- simple-example-teardown
51+
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
52+
args: ['/bin/bash', '-c', 'cft test run TestNat --stage apply --verbose']
53+
- id: nat-verify
54+
waitFor:
55+
- nat-apply
56+
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
57+
args: ['/bin/bash', '-c', 'cft test run TestNat --stage verify --verbose']
58+
- id: nat-teardown
59+
waitFor:
60+
- nat-verify
61+
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
62+
args: ['/bin/bash', '-c', 'cft test run TestNat --stage teardown --verbose']
3963
tags:
4064
- 'ci'
4165
- 'integration'

docs/upgrading_to_v6.0.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Upgrading to v6.0
2+
3+
The v6.0 release contains backwards-incompatible changes.
4+
5+
### [Terraform](https://www.terraform.io/downloads.html) >= 1.3.0 is required Since [optional attributes](https://developer.hashicorp.com/terraform/language/expressions/type-constraints#optional-object-type-attributes) is a version 1.3 feature, the configuration will fail if the pinned version is < 1.3.

examples/nat/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@ inside of a project.
88

99
| Name | Description | Type | Default | Required |
1010
|------|-------------|------|---------|:--------:|
11-
| project\_id | The project ID to host the Cloud Router in | `any` | n/a | yes |
11+
| project\_id | The GCP project ID | `string` | n/a | yes |
1212

1313
## Outputs
1414

1515
| Name | Description |
1616
|------|-------------|
17+
| project\_id | Project ID of the router |
1718
| router\_name | The name of the created router |
1819
| router\_region | The region of the created router |
1920

examples/nat/main.tf

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,24 @@
1414
* limitations under the License.
1515
*/
1616

17+
module "vpc" {
18+
source = "terraform-google-modules/network/google"
19+
version = "~> 7.0"
20+
21+
project_id = var.project_id
22+
network_name = "test-network"
23+
routing_mode = "GLOBAL"
24+
subnets = []
25+
}
26+
27+
1728
# [START cloudnat_simple_create]
1829
module "cloud_router" {
1930
source = "terraform-google-modules/cloud-router/google"
2031
version = "~> 5.0"
21-
project = var.project_id # Replace this with your project ID in quotes
2232
name = "my-cloud-router"
23-
network = "default"
33+
project = var.project_id
34+
network = module.vpc.network_name
2435
region = "us-central1"
2536

2637
nats = [{

examples/nat/outputs.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,8 @@ output "router_region" {
2323
value = module.cloud_router.router.region
2424
description = "The region of the created router"
2525
}
26+
27+
output "project_id" {
28+
value = module.cloud_router.router.project
29+
description = "Project ID of the router"
30+
}

examples/nat/variables.tf

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2019 Google LLC
2+
* Copyright 2020 Google LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -14,6 +14,8 @@
1414
* limitations under the License.
1515
*/
1616

17+
1718
variable "project_id" {
18-
description = "The project ID to host the Cloud Router in"
19+
type = string
20+
description = "The GCP project ID"
1921
}

examples/nat/versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ terraform {
2121
version = "~> 4.0"
2222
}
2323
}
24-
required_version = ">= 0.13"
24+
required_version = ">= 1.3"
2525
}

examples/simple/variables.tf

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

examples/simple/README.md renamed to examples/simple_example/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ This example configures a single simple Cloud Router inside of a project.
77

88
| Name | Description | Type | Default | Required |
99
|------|-------------|------|---------|:--------:|
10-
| network | A reference to the network to which this router belongs | `string` | n/a | yes |
11-
| project | The GCP project ID | `string` | n/a | yes |
10+
| project\_id | The GCP project ID | `string` | n/a | yes |
1211

1312
## Outputs
1413

1514
| Name | Description |
1615
|------|-------------|
16+
| project\_id | Project ID of the router |
17+
| router | Project ID of the router |
1718
| router\_name | The name of the created router |
1819
| router\_region | The region of the created router |
1920

0 commit comments

Comments
 (0)