Skip to content

Commit c9fd6d9

Browse files
committed
Migrate integration tests to Test Kitchen
This commit eliminates the existing BATS integration tests and instead introduces integration tests with Test Kitchen using the kitchen-terraform and inspec-gcp plugins. The changes made to the examples were to ensure that all scenarios could be run in parallel, to correct syntax errors, and to use locals to make testing easier.
1 parent 257d6af commit c9fd6d9

File tree

45 files changed

+752
-693
lines changed

Some content is hidden

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

45 files changed

+752
-693
lines changed

.kitchen.yml

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,59 @@ platforms:
2424
- name: local
2525

2626
suites:
27-
- name: "simple_example"
27+
- name: "simple_project"
2828
driver:
2929
name: "terraform"
3030
command_timeout: 1800
31-
root_module_directory: test/fixtures/simple_example/
31+
root_module_directory: test/fixtures/simple_project/
3232
verifier:
3333
name: terraform
34-
color: false
34+
color: true
3535
systems:
36-
- name: simple_example
36+
- name: inspec-gcp
37+
backend: gcp
38+
controls:
39+
- gcp
40+
- name: local
3741
backend: local
3842
controls:
3943
- gcloud
40-
- name: simple_example
44+
- name: "simple_project_with_regional_network"
45+
driver:
46+
name: "terraform"
47+
command_timeout: 1800
48+
root_module_directory: test/fixtures/simple_project_with_regional_network/
49+
verifier:
50+
name: terraform
51+
color: true
52+
systems:
53+
- name: inspec-gcp
4154
backend: gcp
42-
shell: true
4355
controls:
4456
- gcp
45-
provisioner:
57+
- name: "secondary_ranges"
58+
driver:
59+
name: "terraform"
60+
command_timeout: 1800
61+
root_module_directory: test/fixtures/secondary_ranges/
62+
verifier:
4663
name: terraform
64+
color: true
65+
systems:
66+
- name: local
67+
backend: local
68+
controls:
69+
- gcloud
70+
- name: "multi_vpc"
71+
driver:
72+
name: "terraform"
73+
command_timeout: 1800
74+
root_module_directory: test/fixtures/multi_vpc/
75+
verifier:
76+
name: terraform
77+
color: true
78+
systems:
79+
- name: local
80+
backend: local
81+
controls:
82+
- gcloud

README.md

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,29 @@ Then perform the following commands on the root folder:
8181
| Name | Description | Type | Default | Required |
8282
|------|-------------|:----:|:-----:|:-----:|
8383
| network_name | The name of the network being created | string | - | yes |
84-
| routing_mode | The network routing mode. Can be either 'REGIONAL' or 'GLOBAL' | string | GLOBAL | no |
8584
| project_id | The ID of the project where this VPC will be created | string | - | yes |
85+
| routes | List of routes being created in this VPC | list | `<list>` | no |
86+
| routing_mode | The network routing mode (default 'GLOBAL') | string | `GLOBAL` | no |
87+
| secondary_ranges | Secondary ranges that will be used in some of the subnets | map | - | yes |
8688
| shared_vpc_host | Makes this project a Shared VPC host if 'true' (default 'false') | string | `false` | no |
8789
| subnets | The list of subnets being created | list | - | yes |
88-
| secondary_ranges | Secondary ranges that will be used in some of the subnets | map | - | yes |
89-
| routes | The list of routes being created | list | - | no |
90+
91+
## Outputs
92+
93+
| Name | Description |
94+
|------|-------------|
95+
| network_name | The name of the VPC being created |
96+
| network_self_link | The URI of the VPC being created |
97+
| routes | The routes associated with this VPC |
98+
| subnets_flow_logs | Whether the subnets will have VPC flow logs enabled |
99+
| subnets_ips | The IPs and CIDRs of the subnets being created |
100+
| subnets_names | The names of the subnets being created |
101+
| subnets_private_access | Whether the subnets will have access to Google API's without a public IP |
102+
| subnets_regions | The region where the subnets will be created |
103+
| subnets_secondary_ranges | The secondary ranges associated with these subnets |
104+
| subnets_self_links | The self-links of subnets being created |
105+
106+
[^]: (autogen_docs_end)
90107

91108
### Subnet Inputs
92109
The subnets list contains maps, where each object represents a subnet. Each map has the following inputs (please see examples folder for additional references):
@@ -115,23 +132,6 @@ The routes list contains maps, where each object represents a route. For the nex
115132
| next_hop_vpn_tunnel | URL to a VpnTunnel that should handle matching packets | string | - | yes |
116133
| 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 |
117134

118-
## Outputs
119-
120-
| Name | Description |
121-
|------|-------------|
122-
| network_name | The name of the VPC being created |
123-
| network_self_link | The URI of the VPC being created |
124-
| subnets_ips | The IPs and CIDRs of the subnets being created |
125-
| subnets_self_links | The `self_link`s of the subnets being created |
126-
| subnets_names | The names of the subnets being created |
127-
| subnets_private_access | Whether the subnets will have access to Google API's without a public IP |
128-
| subnets_flow_logs | Whether the subnets will have VPC flow logs enabled |
129-
| subnets_regions | The region where the subnets will be created |
130-
| subnets_secondary_ranges | The secondary ranges associated with these subnets |
131-
| routes | The routes associated with this VPC |
132-
133-
[^]: (autogen_docs_end)
134-
135135
## Requirements
136136
### Terraform plugins
137137
- [Terraform](https://www.terraform.io/downloads.html) 0.10.x

codelabs/simple/main.tf

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/**
2+
* Copyright 2018 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+
117
resource "random_id" "network_id" {
218
byte_length = 8
319
}

examples/multi_vpc/README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,25 @@ This example configures a host network project with two separate networks.
1515

1616
| Name | Description |
1717
|------|-------------|
18-
| network_01_name | vpc 1 |
18+
| network_01_name | The name of the VPC network-01 |
19+
| network_01_route_data | The route data for network 01 that was passed into the network module |
20+
| network_01_routes | The routes associated with network-01 |
1921
| network_01_self_link | The URI of the VPC network-01 |
2022
| network_01_subnets | The names of the subnets being created on network-01 |
2123
| network_01_subnets_flow_logs | Whether the subnets will have VPC flow logs enabled |
2224
| network_01_subnets_ips | The IP and cidrs of the subnets being created on network-01 |
2325
| network_01_subnets_private_access | Whether the subnets will have access to Google API's without a public IP on network-01 |
2426
| network_01_subnets_regions | The region where the subnets will be created on network-01 |
2527
| network_01_subnets_secondary_ranges | The secondary ranges associated with these subnets on network-01 |
26-
| network_01_routes | The routes associated with network-01 |
27-
| network_02_name | vpc 2 |
28+
| network_02_name | The name of the VPC network-02 |
29+
| network_02_route_data | The route data for network 02 that was passed into the network module |
30+
| network_02_routes | The routes associated with network-02 |
2831
| network_02_self_link | The URI of the VPC network-02 |
2932
| network_02_subnets | The names of the subnets being created on network-02 |
3033
| network_02_subnets_flow_logs | Whether the subnets will have VPC flow logs enabled |
3134
| network_02_subnets_ips | The IP and cidrs of the subnets being created on network-02 |
3235
| network_02_subnets_private_access | Whether the subnets will have access to Google API's without a public IP on network-02 |
3336
| network_02_subnets_regions | The region where the subnets will be created on network-02 |
3437
| network_02_subnets_secondary_ranges | The secondary ranges associated with these subnets on network-02 |
35-
| network_02_routes | The routes associated with network-02 |
3638

37-
[^]: (autogen_docs_end)
39+
[^]: (autogen_docs_end)

examples/multi_vpc/main.tf

Lines changed: 62 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,72 @@
1414
* limitations under the License.
1515
*/
1616

17+
locals {
18+
network_01_name = "test-network-301"
19+
network_02_name = "test-network-302"
20+
21+
network_01_routes = [
22+
{
23+
name = "${local.network_01_name}-egress-inet"
24+
description = "route through IGW to access internet"
25+
destination_range = "0.0.0.0/0"
26+
tags = "egress-inet"
27+
next_hop_internet = "true"
28+
},
29+
]
30+
31+
network_02_routes = [
32+
{
33+
name = "${local.network_02_name}-egress-inet"
34+
description = "route through IGW to access internet"
35+
destination_range = "0.0.0.0/0"
36+
tags = "egress-inet"
37+
next_hop_internet = "true"
38+
},
39+
{
40+
name = "${local.network_02_name}-testapp-proxy"
41+
description = "route through proxy to reach app"
42+
destination_range = "10.50.10.0/24"
43+
tags = "app-proxy"
44+
next_hop_ip = "10.10.40.10"
45+
},
46+
]
47+
}
48+
49+
resource "random_string" "random_suffix_01" {
50+
length = 4
51+
upper = "false"
52+
special = "false"
53+
}
54+
55+
resource "random_string" "random_suffix_02" {
56+
length = 4
57+
upper = "false"
58+
special = "false"
59+
}
60+
1761
module "test-vpc-module-01" {
1862
source = "../../"
1963
project_id = "${var.project_id}"
20-
network_name = "test-network-01"
64+
network_name = "test-network-${random_string.random_suffix_01.result}"
2165

2266
subnets = [
2367
{
24-
subnet_name = "test-network-01-subnet-01"
68+
subnet_name = "${local.network_01_name}-subnet-01"
2569
subnet_ip = "10.10.10.0/24"
2670
subnet_region = "us-west1"
2771
subnet_private_access = "false"
2872
subnet_flow_logs = "true"
2973
},
3074
{
31-
subnet_name = "test-network-01-subnet-02"
75+
subnet_name = "${local.network_01_name}-subnet-02"
3276
subnet_ip = "10.10.20.0/24"
3377
subnet_region = "us-west1"
3478
subnet_private_access = "false"
3579
subnet_flow_logs = "true"
3680
},
3781
{
38-
subnet_name = "test-network-01-subnet-03"
82+
subnet_name = "${local.network_01_name}-subnet-03"
3983
subnet_ip = "10.10.30.0/24"
4084
subnet_region = "us-west1"
4185
subnet_private_access = "false"
@@ -44,53 +88,45 @@ module "test-vpc-module-01" {
4488
]
4589

4690
secondary_ranges = {
47-
test-network-01-subnet-01 = [
91+
"${local.network_01_name}-subnet-01" = [
4892
{
49-
range_name = "test-network-01-subnet-01-01"
93+
range_name = "${local.network_01_name}-subnet-01-01"
5094
ip_cidr_range = "192.168.64.0/24"
5195
},
5296
{
53-
range_name = "test-network-01-subnet-01-02"
97+
range_name = "${local.network_01_name}-subnet-01-02"
5498
ip_cidr_range = "192.168.65.0/24"
5599
},
56100
]
57101

58-
test-network-01-subnet-02 = [
102+
"${local.network_01_name}-subnet-02" = [
59103
{
60-
range_name = "test-network-01-subnet-02-01"
104+
range_name = "${local.network_01_name}-subnet-02-01"
61105
ip_cidr_range = "192.168.74.0/24"
62106
},
63107
]
64108

65-
test-network-01-subnet-03 = []
109+
"${local.network_01_name}-subnet-03" = []
66110
}
67111

68-
routes = [
69-
{
70-
name = "egress-inet"
71-
description = "route through IGW to access internet"
72-
dest_range = "0.0.0.0/0"
73-
tags = "egress-inet"
74-
next_hop_gateway = "true"
75-
},
76-
]
112+
routes = "${local.network_01_routes}"
77113
}
78114

79115
module "test-vpc-module-02" {
80116
source = "../../"
81117
project_id = "${var.project_id}"
82-
network_name = "test-network-02"
118+
network_name = "test-network-${random_string.random_suffix_02.result}"
83119

84120
subnets = [
85121
{
86-
subnet_name = "test-network-02-subnet-01"
122+
subnet_name = "${local.network_02_name}-subnet-01"
87123
subnet_ip = "10.10.40.0/24"
88124
subnet_region = "us-west1"
89125
subnet_private_access = "false"
90126
subnet_flow_logs = "true"
91127
},
92128
{
93-
subnet_name = "test-network-02-subnet-02"
129+
subnet_name = "${local.network_02_name}-subnet-02"
94130
subnet_ip = "10.10.50.0/24"
95131
subnet_region = "us-west1"
96132
subnet_private_access = "false"
@@ -99,30 +135,15 @@ module "test-vpc-module-02" {
99135
]
100136

101137
secondary_ranges = {
102-
test-network-02-subnet-01 = [
138+
"${local.network_02_name}-subnet-01" = [
103139
{
104-
range_name = "est-network-02-subnet-02-01"
140+
range_name = "${local.network_02_name}-subnet-02-01"
105141
ip_cidr_range = "192.168.75.0/24"
106142
},
107143
]
108144

109-
test-network-02-subnet-02 = []
145+
"${local.network_02_name}-subnet-02" = []
110146
}
111147

112-
routes = [
113-
{
114-
name = "egress-inet"
115-
description = "route through IGW to access internet"
116-
destination_range = "0.0.0.0/0"
117-
tags = "egress-inet"
118-
next_hop_gateway = "true"
119-
},
120-
{
121-
name = "app-proxy"
122-
description = "route through proxy to reach app"
123-
destination_range = "10.50.10.0/24"
124-
tags = "app-proxy"
125-
next_hop_ip = "10.10.40.10"
126-
},
127-
]
148+
routes = "${local.network_02_routes}"
128149
}

examples/multi_vpc/outputs.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ output "network_01_routes" {
6060
description = "The routes associated with network-01"
6161
}
6262

63+
output "network_01_route_data" {
64+
value = "${local.network_01_routes}"
65+
description = "The route data for network 01 that was passed into the network module"
66+
}
67+
6368
# vpc 2
6469
output "network_02_name" {
6570
value = "${module.test-vpc-module-02.network_name}"
@@ -105,3 +110,8 @@ output "network_02_routes" {
105110
value = "${module.test-vpc-module-02.routes}"
106111
description = "The routes associated with network-02"
107112
}
113+
114+
output "network_02_route_data" {
115+
value = "${local.network_02_routes}"
116+
description = "The route data for network 02 that was passed into the network module"
117+
}

0 commit comments

Comments
 (0)