Skip to content

Commit 3324f68

Browse files
authored
Merge branch 'master' into bugfix/firewall-allow-internal
2 parents 7929363 + ac32d81 commit 3324f68

File tree

57 files changed

+1664
-140
lines changed

Some content is hidden

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

57 files changed

+1664
-140
lines changed

.kitchen.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,21 @@ suites:
6464
color: true
6565
systems:
6666
- name: local
67+
attrs_outputs:
68+
customized_inspec_attribute: output_network_name
69+
customized_inspec_attribute: output_network_self_link
70+
customized_inspec_attribute: output_subnets_ips
71+
customized_inspec_attribute: output_routes
72+
customized_inspec_attribute: output_subnets_flow_logs
73+
customized_inspec_attribute: output_subnets_names
74+
customized_inspec_attribute: output_subnets_private_access
75+
customized_inspec_attribute: output_subnets_regions
76+
customized_inspec_attribute: output_subnets_secondary_ranges
77+
customized_inspec_attribute: output_project_id
6778
backend: local
6879
controls:
6980
- gcloud
81+
- inspec_attributes
7082
- name: "multi_vpc"
7183
driver:
7284
name: "terraform"
@@ -107,9 +119,21 @@ suites:
107119
controls:
108120
- gcp
109121
- name: local
122+
attrs_outputs:
123+
customized_inspec_attribute: output_network_name
124+
customized_inspec_attribute: output_network_self_link
125+
customized_inspec_attribute: output_subnets_ips
126+
customized_inspec_attribute: output_routes
127+
customized_inspec_attribute: output_subnets_flow_logs
128+
customized_inspec_attribute: output_subnets_names
129+
customized_inspec_attribute: output_subnets_private_access
130+
customized_inspec_attribute: output_subnets_regions
131+
customized_inspec_attribute: output_subnets_secondary_ranges
132+
customized_inspec_attribute: output_project_id
110133
backend: local
111134
controls:
112135
- gcloud
136+
- inspec_attributes
113137
- name: "submodule_network_peering"
114138
driver:
115139
name: "terraform"

CHANGELOG.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,18 @@ and this project adheres to [Semantic Versioning][semver-site].
77

88
## [Unreleased]
99

10+
## [2.0.0] - 2019-12-09
11+
v2.0.0 is a backwards-incompatible release. Please see the [upgrading guide](./docs/upgrading_to_v2.0.md).
12+
13+
### Added
14+
15+
- Split main module up into vpc, subnets, and routes submodules. [#103]
16+
17+
### Fixed
18+
19+
- Fixes subnet recreation when a subnet is updated. [#73]
20+
21+
1022
## [1.5.0] - 2019-11-06
1123

1224
### Added
@@ -152,7 +164,8 @@ and this project adheres to [Semantic Versioning][semver-site].
152164
- Subnets within the VPC
153165
- Secondary ranges for the subnets (if applicable)
154166

155-
[Unreleased]: https://github.com/terraform-google-modules/terraform-google-network/compare/v1.5.0...HEAD
167+
[Unreleased]: https://github.com/terraform-google-modules/terraform-google-network/compare/v2.0.0...HEAD
168+
[2.0.0]: https://github.com/terraform-google-modules/terraform-google-network/compare/v1.5.0...v2.0.0
156169
[1.5.0]: https://github.com/terraform-google-modules/terraform-google-network/compare/v1.4.3...v1.5.0
157170
[1.4.3]: https://github.com/terraform-google-modules/terraform-google-network/compare/v1.4.2...v1.4.3
158171
[1.4.2]: https://github.com/terraform-google-modules/terraform-google-network/compare/v1.4.1...v1.4.2

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# Make will use bash instead of sh
1616
SHELL := /usr/bin/env bash
1717

18-
DOCKER_TAG_VERSION_DEVELOPER_TOOLS := 0.5.0
18+
DOCKER_TAG_VERSION_DEVELOPER_TOOLS := 0.6.0
1919
DOCKER_IMAGE_DEVELOPER_TOOLS := cft/developer-tools
2020
REGISTRY_URL := gcr.io/cloud-foundation-cicd
2121

README.md

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ It supports creating:
88
- Subnets within the VPC
99
- Secondary ranges for the subnets (if applicable)
1010

11+
Sub modules are provided for creating individual vpc, subnets, and routes. See the modules directory for the various sub modules usage.
12+
1113
## Compatibility
1214

1315
This module is meant for use with Terraform 0.12. If you haven't [upgraded](https://www.terraform.io/upgrade-guides/0-12.html) and need a Terraform 0.11.x-compatible version of this module, the last released version intended for Terraform 0.11.x is [0.8.0](https://registry.terraform.io/modules/terraform-google-modules/network/google/0.8.0).
@@ -18,7 +20,7 @@ You can go to the examples folder, however the usage of the module could be like
1820
```hcl
1921
module "vpc" {
2022
source = "terraform-google-modules/network/google"
21-
version = "~> 1.0.0"
23+
version = "~> 2.0.0"
2224
2325
project_id = "<PROJECT ID>"
2426
network_name = "example-vpc"
@@ -38,6 +40,15 @@ module "vpc" {
3840
subnet_flow_logs = "true"
3941
description = "This subnet has a description"
4042
},
43+
{
44+
subnet_name = "subnet-03"
45+
subnet_ip = "10.10.30.0/24"
46+
subnet_region = "us-west1"
47+
subnet_flow_logs = "true"
48+
subnet_flow_logs_interval = "INTERVAL_10_MIN"
49+
subnet_flow_logs_sampling = 0.7
50+
subnet_flow_logs_metadata = "INCLUDE_ALL_METADATA"
51+
}
4152
]
4253
4354
secondary_ranges = {
@@ -92,7 +103,7 @@ Then perform the following commands on the root folder:
92103
| routes | List of routes being created in this VPC | list(map(string)) | `<list>` | no |
93104
| routing\_mode | The network routing mode (default 'GLOBAL') | string | `"GLOBAL"` | no |
94105
| secondary\_ranges | Secondary ranges that will be used in some of the subnets | object | `<map>` | no |
95-
| shared\_vpc\_host | Makes this project a Shared VPC host if 'true' (default 'false') | string | `"false"` | no |
106+
| shared\_vpc\_host | Makes this project a Shared VPC host if 'true' (default 'false') | bool | `"false"` | no |
96107
| subnets | The list of subnets being created | list(map(string)) | n/a | yes |
97108

98109
## Outputs
@@ -101,19 +112,20 @@ Then perform the following commands on the root folder:
101112
|------|-------------|
102113
| network\_name | The name of the VPC being created |
103114
| network\_self\_link | The URI of the VPC being created |
104-
| routes | The routes associated with this VPC |
115+
| project\_id | VPC project id |
116+
| route\_names | The route names associated with this VPC |
105117
| subnets\_flow\_logs | Whether the subnets will have VPC flow logs enabled |
106118
| subnets\_ips | The IPs and CIDRs of the subnets being created |
107119
| subnets\_names | The names of the subnets being created |
108120
| subnets\_private\_access | Whether the subnets will have access to Google API's without a public IP |
109121
| subnets\_regions | The region where the subnets will be created |
110122
| subnets\_secondary\_ranges | The secondary ranges associated with these subnets |
111123
| subnets\_self\_links | The self-links of subnets being created |
112-
| svpc\_host\_project\_id | Shared VPC host project id. |
113124

114125
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
115126

116127
### Subnet Inputs
128+
117129
The subnets list contains maps, where each object represents a subnet. Each map has the following inputs (please see examples folder for additional references):
118130

119131
| Name | Description | Type | Default | Required |
@@ -125,7 +137,8 @@ The subnets list contains maps, where each object represents a subnet. Each map
125137
| subnet\_flow\_logs | Whether the subnet will record and send flow log data to logging | string | `"false"` | no |
126138

127139
### Route Inputs
128-
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):
140+
141+
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):
129142

130143
| Name | Description | Type | Default | Required |
131144
|------|-------------|:----:|:-----:|:-----:|
@@ -143,7 +156,7 @@ The routes list contains maps, where each object represents a route. For the nex
143156
## Requirements
144157
### Installed Software
145158
- [Terraform](https://www.terraform.io/downloads.html) ~> 0.12.0
146-
- [Terraform Provider for GCP][terraform-provider-google] ~> 2.10.0
159+
- [Terraform Provider for GCP][terraform-provider-google] ~> 2.19.0
147160
- [gcloud](https://cloud.google.com/sdk/gcloud/) >243.0.0
148161

149162
### Configure a Service Account

build/int.cloudbuild.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@ tags:
3838
- 'integration'
3939
substitutions:
4040
_DOCKER_IMAGE_DEVELOPER_TOOLS: 'cft/developer-tools'
41-
_DOCKER_TAG_VERSION_DEVELOPER_TOOLS: '0.5.0'
41+
_DOCKER_TAG_VERSION_DEVELOPER_TOOLS: '0.6.0'

build/lint.cloudbuild.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ tags:
2121
- 'lint'
2222
substitutions:
2323
_DOCKER_IMAGE_DEVELOPER_TOOLS: 'cft/developer-tools'
24-
_DOCKER_TAG_VERSION_DEVELOPER_TOOLS: '0.5.0'
24+
_DOCKER_TAG_VERSION_DEVELOPER_TOOLS: '0.6.0'

docs/upgrading_to_v2.0.md

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
# Upgrading to v2.x
2+
3+
The v2.x release of _google-network_ is a backwards incompatible
4+
release.
5+
6+
Because v2.x changed how the subnet resource is iterated on, resources in Terraform state need to be migrated in order to avoid the resources from getting destroyed and recreated.
7+
8+
## Migration Instructions
9+
10+
First, upgrade to the new version of this module.
11+
12+
```diff
13+
module "kubernetes_engine_private_cluster" {
14+
source = "terraform-google-modules/network/google"
15+
- version = "~> 1.5"
16+
+ version = "~> 2.0"
17+
18+
# ...
19+
}
20+
```
21+
22+
If you run `terraform plan` at this point, Terraform will inform you that it will attempt to delete and recreate your existing subnets. This is almost certainly not the behavior you want.
23+
24+
You will need to migrate your state, either [manually](#manual-migration-steps) or [automatically](#migration-script).
25+
26+
### Migration Script
27+
28+
1. Download the script:
29+
30+
```sh
31+
curl -O https://raw.githubusercontent.com/terraform-google-modules/terraform-google-network/master/helpers/migrate.py
32+
chmod +x migrate.py
33+
```
34+
35+
2. Back up your Terraform state:
36+
37+
```sh
38+
terraform state pull >> state.bak
39+
```
40+
41+
2. Run the script to output the migration commands:
42+
43+
```sh
44+
$ ./migrate.py --dryrun
45+
terraform state mv 'module.example.module.test-vpc-module-02.google_compute_network.network[0]' 'module.example.module.test-vpc-module-02.module.vpc.google_compute_network.network'
46+
terraform state mv 'module.example.module.test-vpc-module-02.google_compute_subnetwork.subnetwork' 'module.example.module.test-vpc-module-02.module.subnets.google_compute_subnetwork.subnetwork'
47+
terraform state mv 'module.example.module.test-vpc-module-02.module.subnets.google_compute_subnetwork.subnetwork[0]' 'module.example.module.test-vpc-module-02.module.subnets.google_compute_subnetwork.subnetwork["us-west1/multi-vpc-a1-02-subnet-01"]'
48+
terraform state mv 'module.example.module.test-vpc-module-02.module.subnets.google_compute_subnetwork.subnetwork[1]' 'module.example.module.test-vpc-module-02.module.subnets.google_compute_subnetwork.subnetwork["us-west1/multi-vpc-a1-02-subnet-02"]'
49+
terraform state mv 'module.example.module.test-vpc-module-02.google_compute_route.route' 'module.example.module.test-vpc-module-02.module.routes.google_compute_route.route'
50+
terraform state mv 'module.example.module.test-vpc-module-02.module.routes.google_compute_route.route[0]' 'module.example.module.test-vpc-module-02.module.routes.google_compute_route.route["multi-vpc-a1-02-egress-inet"]'
51+
terraform state mv 'module.example.module.test-vpc-module-02.module.routes.google_compute_route.route[1]' 'module.example.module.test-vpc-module-02.module.routes.google_compute_route.route["multi-vpc-a1-02-testapp-proxy"]'
52+
53+
```
54+
55+
3. Execute the migration script:
56+
57+
```sh
58+
$ ./migrate.py
59+
---- Migrating the following modules:
60+
-- module.example.module.test-vpc-module-02
61+
---- Commands to run:
62+
Move "module.example.module.test-vpc-module-02.google_compute_network.network[0]" to "module.example.module.test-vpc-module-02.module.vpc.google_compute_network.network"
63+
Successfully moved 1 object(s).
64+
Move "module.example.module.test-vpc-module-02.google_compute_subnetwork.subnetwork" to "module.example.module.test-vpc-module-02.module.subnets.google_compute_subnetwork.subnetwork"
65+
Successfully moved 1 object(s).
66+
Move "module.example.module.test-vpc-module-02.module.subnets.google_compute_subnetwork.subnetwork[0]" to "module.example.module.test-vpc-module-02.module.subnets.google_compute_subnetwork.subnetwork[\"us-west1/multi-vpc-a1-02-subnet-01\"]"
67+
Successfully moved 1 object(s).
68+
Move "module.example.module.test-vpc-module-02.module.subnets.google_compute_subnetwork.subnetwork[1]" to "module.example.module.test-vpc-module-02.module.subnets.google_compute_subnetwork.subnetwork[\"us-west1/multi-vpc-a1-02-subnet-02\"]"
69+
Successfully moved 1 object(s).
70+
Move "module.example.module.test-vpc-module-02.google_compute_route.route" to "module.example.module.test-vpc-module-02.module.routes.google_compute_route.route"
71+
Successfully moved 1 object(s).
72+
Move "module.example.module.test-vpc-module-02.module.routes.google_compute_route.route[0]" to "module.example.module.test-vpc-module-02.module.routes.google_compute_route.route[\"multi-vpc-a1-02-egress-inet\"]"
73+
Successfully moved 1 object(s).
74+
Move "module.example.module.test-vpc-module-02.module.routes.google_compute_route.route[1]" to "module.example.module.test-vpc-module-02.module.routes.google_compute_route.route[\"multi-vpc-a1-02-testapp-proxy\"]"
75+
Successfully moved 1 object(s).
76+
77+
```
78+
79+
4. Run `terraform plan` to confirm no changes are expected.
80+
81+
### Manual Migration Steps
82+
83+
In this example here are the commands used migrate the vpc and subnets created by the `simple_project` in the examples directory. _please note the need to escape the quotes on the new resource_. You may also use the migration script.
84+
85+
- `terraform state mv module.example.module.test-vpc-module.google_compute_network.network module.example.module.test-vpc-module.module.vpc.google_compute_subnetwork.network`
86+
87+
- `terraform state mv module.example.module.test-vpc-module.google_compute_subnetwork.subnetwork module.example.module.test-vpc-module.module.subnets.google_compute_subnetwork.subnetwork`
88+
89+
- `terraform state mv module.example.module.test-vpc-module.module.subnets.google_compute_subnetwork.subnetwork[0] module.example.module.test-vpc-module.module.subnets.google_compute_subnetwork.subnetwork[\"us-west1/simple-project-timh-subnet-01\"]`
90+
91+
- `terraform state mv module.example.module.test-vpc-module.module.subnets.google_compute_subnetwork.subnetwork[1] module.example.module.test-vpc-module.module.subnets.google_compute_subnetwork.subnetwork[\"us-west1/simple-project-timh-subnet-02\"]`
92+
93+
*You'll notice that because of a terraform [issue](https://github.com/hashicorp/terraform/issues/22301), we need to move the whole resource collection first before renaming to the `for_each` keys*
94+
95+
`terraform plan` should now return a no-op and show no new changes.
96+
97+
```Shell
98+
$ terraform plan
99+
Refreshing Terraform state in-memory prior to plan...
100+
The refreshed state will be used to calculate this plan, but will not be
101+
persisted to local or remote state storage.
102+
103+
module.example.module.test-vpc-module.google_compute_network.network: Refreshing state... [id=simple-project-timh]
104+
module.example.module.test-vpc-module.google_compute_subnetwork.subnetwork["us-west1/simple-project-timh-subnet-02"]: Refreshing state... [id=us-west1/simple-project-timh-subnet-02]
105+
module.example.module.test-vpc-module.google_compute_subnetwork.subnetwork["us-west1/simple-project-timh-subnet-01"]: Refreshing state... [id=us-west1/simple-project-timh-subnet-01]
106+
107+
------------------------------------------------------------------------
108+
109+
No changes. Infrastructure is up-to-date.
110+
111+
This means that Terraform did not detect any differences between your
112+
configuration and real physical resources that exist. As a result, no
113+
actions need to be performed.
114+
```
115+
116+
### Known Issues
117+
118+
If your previous state only contains a **single** subnet or route then `terraform mv` will throw an error similar to the following during migration:
119+
120+
```
121+
Error: Invalid target address
122+
123+
Cannot move to
124+
module.example.module.test-vpc-module-01.module.routes.google_compute_route.route["multi-vpc-a1-01-egress-inet"]:
125+
module.example.module.test-vpc-module-01.module.routes.google_compute_route.route
126+
does not exist in the current state.
127+
```
128+
129+
This is due to a terraform mv [issue](https://github.com/hashicorp/terraform/issues/22301)
130+
131+
The workaround is to either
132+
133+
1. Create a temporary subnet or route prior to migration
134+
2. Manually updating the state file. Update the `index_key` of the appropriate user and push the to the remote state if necessary.

examples/delete_default_gateway_routes/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ This VPC has a single subnet with no secondary ranges, and ensures the default i
1818
|------|-------------|
1919
| network\_name | The name of the VPC being created |
2020
| network\_self\_link | The URI of the VPC being created |
21-
| routes | The routes associated with this VPC |
21+
| route\_names | The routes associated with this VPC |
2222
| subnets\_flow\_logs | Whether the subnets will have VPC flow logs enabled |
2323
| subnets\_ips | The IP and cidrs of the subnets being created |
2424
| subnets\_names | The names of the subnets being created |

examples/delete_default_gateway_routes/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616

1717
provider "google" {
18-
version = "~> 2.10.0"
18+
version = "~> 2.19.0"
1919
}
2020

2121
provider "null" {

examples/delete_default_gateway_routes/outputs.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ output "subnets_secondary_ranges" {
5454
description = "The secondary ranges associated with these subnets"
5555
}
5656

57-
output "routes" {
58-
value = module.test-vpc-module.routes
57+
output "route_names" {
58+
value = module.test-vpc-module.route_names
5959
description = "The routes associated with this VPC"
6060
}

0 commit comments

Comments
 (0)