Skip to content

Commit fc7d126

Browse files
authored
Merge pull request #34 from glarizza/gl/network_tests_randomness
Refactor integration tests to include random names
2 parents 1d7ff1e + 79a24cc commit fc7d126

File tree

33 files changed

+281
-226
lines changed

33 files changed

+281
-226
lines changed

Makefile

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -84,50 +84,60 @@ docker_run:
8484
docker run --rm -it \
8585
-e CLOUDSDK_AUTH_CREDENTIAL_FILE_OVERRIDE=${CREDENTIALS_PATH} \
8686
-e GOOGLE_APPLICATION_CREDENTIALS=${CREDENTIALS_PATH} \
87-
-e TF_VAR_project_id \
87+
-e PROJECT_ID \
88+
-e SERVICE_ACCOUNT_JSON \
89+
-e RANDOM_STRING_FOR_TESTING \
8890
-v $(CURDIR):/cft/workdir \
8991
${DOCKER_REPO_BASE_KITCHEN_TERRAFORM} \
90-
/bin/bash
92+
/bin/bash -c 'source test/ci_integration.sh && setup_environment && exec /bin/bash'
9193

9294
.PHONY: docker_create
9395
docker_create:
9496
docker run --rm -it \
9597
-e CLOUDSDK_AUTH_CREDENTIAL_FILE_OVERRIDE=${CREDENTIALS_PATH} \
9698
-e GOOGLE_APPLICATION_CREDENTIALS=${CREDENTIALS_PATH} \
97-
-e TF_VAR_project_id \
99+
-e PROJECT_ID \
100+
-e SERVICE_ACCOUNT_JSON \
101+
-e RANDOM_STRING_FOR_TESTING \
98102
-v $(CURDIR):/cft/workdir \
99103
${DOCKER_REPO_BASE_KITCHEN_TERRAFORM} \
100-
/bin/bash -c "kitchen create"
104+
/bin/bash -c "source test/ci_integration.sh && setup_environment && kitchen create"
101105

102106
.PHONY: docker_converge
103107
docker_converge:
104108
docker run --rm -it \
105109
-e CLOUDSDK_AUTH_CREDENTIAL_FILE_OVERRIDE=${CREDENTIALS_PATH} \
106110
-e GOOGLE_APPLICATION_CREDENTIALS=${CREDENTIALS_PATH} \
107-
-e TF_VAR_project_id \
111+
-e PROJECT_ID \
112+
-e SERVICE_ACCOUNT_JSON \
113+
-e RANDOM_STRING_FOR_TESTING \
108114
-v $(CURDIR):/cft/workdir \
109115
${DOCKER_REPO_BASE_KITCHEN_TERRAFORM} \
110-
/bin/bash -c "kitchen converge && kitchen converge"
116+
/bin/bash -c "source test/ci_integration.sh && setup_environment && kitchen converge && kitchen converge"
111117

112118
.PHONY: docker_verify
113119
docker_verify:
114120
docker run --rm -it \
115121
-e CLOUDSDK_AUTH_CREDENTIAL_FILE_OVERRIDE=${CREDENTIALS_PATH} \
116122
-e GOOGLE_APPLICATION_CREDENTIALS=${CREDENTIALS_PATH} \
117-
-e TF_VAR_project_id \
123+
-e PROJECT_ID \
124+
-e SERVICE_ACCOUNT_JSON \
125+
-e RANDOM_STRING_FOR_TESTING \
118126
-v $(CURDIR):/cft/workdir \
119127
${DOCKER_REPO_BASE_KITCHEN_TERRAFORM} \
120-
/bin/bash -c "kitchen verify"
128+
/bin/bash -c "source test/ci_integration.sh && setup_environment && kitchen verify"
121129

122130
.PHONY: docker_destroy
123131
docker_destroy:
124132
docker run --rm -it \
125133
-e CLOUDSDK_AUTH_CREDENTIAL_FILE_OVERRIDE=${CREDENTIALS_PATH} \
126134
-e GOOGLE_APPLICATION_CREDENTIALS=${CREDENTIALS_PATH} \
127-
-e TF_VAR_project_id \
135+
-e PROJECT_ID \
136+
-e SERVICE_ACCOUNT_JSON \
137+
-e RANDOM_STRING_FOR_TESTING \
128138
-v $(CURDIR):/cft/workdir \
129139
${DOCKER_REPO_BASE_KITCHEN_TERRAFORM} \
130-
/bin/bash -c "kitchen destroy"
140+
/bin/bash -c "source test/ci_integration.sh && setup_environment && kitchen destroy"
131141

132142
.PHONY: test_integration_docker
133143
test_integration_docker: docker_create docker_converge docker_verify docker_destroy

README.md

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -75,34 +75,33 @@ Then perform the following commands on the root folder:
7575

7676
[^]: (autogen_docs_start)
7777

78-
7978
## Inputs
8079

8180
| Name | Description | Type | Default | Required |
8281
|------|-------------|:----:|:-----:|:-----:|
83-
| 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 |
84-
| network_name | The name of the network being created | string | - | yes |
85-
| project_id | The ID of the project where this VPC will be created | string | - | yes |
82+
| 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 |
83+
| network\_name | The name of the network being created | string | n/a | yes |
84+
| project\_id | The ID of the project where this VPC will be created | string | n/a | yes |
8685
| routes | List of routes being created in this VPC | list | `<list>` | no |
87-
| routing_mode | The network routing mode (default 'GLOBAL') | string | `GLOBAL` | no |
88-
| secondary_ranges | Secondary ranges that will be used in some of the subnets | map | - | yes |
89-
| shared_vpc_host | Makes this project a Shared VPC host if 'true' (default 'false') | string | `false` | no |
90-
| subnets | The list of subnets being created | list | - | yes |
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 | n/a | yes |
88+
| shared\_vpc\_host | Makes this project a Shared VPC host if 'true' (default 'false') | string | `"false"` | no |
89+
| subnets | The list of subnets being created | list | n/a | yes |
9190

9291
## Outputs
9392

9493
| Name | Description |
9594
|------|-------------|
96-
| network_name | The name of the VPC being created |
97-
| network_self_link | The URI of the VPC being created |
95+
| network\_name | The name of the VPC being created |
96+
| network\_self\_link | The URI of the VPC being created |
9897
| routes | The routes associated with this VPC |
99-
| subnets_flow_logs | Whether the subnets will have VPC flow logs enabled |
100-
| subnets_ips | The IPs and CIDRs of the subnets being created |
101-
| subnets_names | The names of the subnets being created |
102-
| subnets_private_access | Whether the subnets will have access to Google API's without a public IP |
103-
| subnets_regions | The region where the subnets will be created |
104-
| subnets_secondary_ranges | The secondary ranges associated with these subnets |
105-
| subnets_self_links | The self-links of subnets being created |
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 |
106105

107106
[^]: (autogen_docs_end)
108107

examples/delete_default_gateway_routes/README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,25 @@ This VPC has a single subnet with no secondary ranges, and ensures the default i
66

77
[^]: (autogen_docs_start)
88

9-
109
## Inputs
1110

1211
| Name | Description | Type | Default | Required |
1312
|------|-------------|:----:|:-----:|:-----:|
14-
| project_id | The project ID to host the network in | string | - | yes |
13+
| network\_name | The name of the VPC network being created | string | n/a | yes |
14+
| project\_id | The project ID to host the network in | string | n/a | yes |
1515

1616
## Outputs
1717

1818
| Name | Description |
1919
|------|-------------|
20-
| network_name | The name of the VPC being created |
21-
| network_self_link | The URI of the VPC being created |
20+
| network\_name | The name of the VPC being created |
21+
| network\_self\_link | The URI of the VPC being created |
2222
| routes | The routes associated with this VPC |
23-
| subnets_flow_logs | Whether the subnets will have VPC flow logs enabled |
24-
| subnets_ips | The IP and cidrs of the subnets being created |
25-
| subnets_names | The names of the subnets being created |
26-
| subnets_private_access | Whether the subnets will have access to Google API's without a public IP |
27-
| subnets_regions | The region where subnets will be created |
28-
| subnets_secondary_ranges | The secondary ranges associated with these subnets |
23+
| subnets\_flow\_logs | Whether the subnets will have VPC flow logs enabled |
24+
| subnets\_ips | The IP and cidrs of the subnets being created |
25+
| subnets\_names | The names of the subnets being created |
26+
| subnets\_private\_access | Whether the subnets will have access to Google API's without a public IP |
27+
| subnets\_regions | The region where subnets will be created |
28+
| subnets\_secondary\_ranges | The secondary ranges associated with these subnets |
2929

3030
[^]: (autogen_docs_end)

examples/delete_default_gateway_routes/main.tf

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,24 @@
1515
*/
1616

1717
locals {
18-
network_name = "test-network-${random_string.random_suffix.result}"
19-
}
20-
21-
resource "random_string" "random_suffix" {
22-
length = 4
23-
upper = "false"
24-
special = "false"
18+
subnet_01 = "${var.network_name}-subnet-01"
2519
}
2620

2721
module "test-vpc-module" {
2822
source = "../../"
2923
project_id = "${var.project_id}"
30-
network_name = "${local.network_name}"
24+
network_name = "${var.network_name}"
3125
delete_default_internet_gateway_routes = "true"
3226

3327
subnets = [
3428
{
35-
subnet_name = "subnet-41"
29+
subnet_name = "${local.subnet_01}"
3630
subnet_ip = "10.20.30.0/24"
3731
subnet_region = "us-west1"
3832
},
3933
]
4034

4135
secondary_ranges = {
42-
subnet-41 = []
36+
"${local.subnet_01}" = []
4337
}
4438
}

examples/delete_default_gateway_routes/variables.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,7 @@
1717
variable "project_id" {
1818
description = "The project ID to host the network in"
1919
}
20+
21+
variable "network_name" {
22+
description = "The name of the VPC network being created"
23+
}

examples/multi_vpc/README.md

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,35 @@ This example configures a host network project with two separate networks.
44

55
[^]: (autogen_docs_start)
66

7-
87
## Inputs
98

109
| Name | Description | Type | Default | Required |
1110
|------|-------------|:----:|:-----:|:-----:|
12-
| project_id | The project ID to host the network in | string | - | yes |
11+
| network\_01\_name | The name of the first VPC network being created | string | n/a | yes |
12+
| network\_02\_name | The name of the second VPC network being created | string | n/a | yes |
13+
| project\_id | The project ID to host the network in | string | n/a | yes |
1314

1415
## Outputs
1516

1617
| Name | Description |
1718
|------|-------------|
18-
| network_01_name | The name of the VPC network-01 |
19-
| network_01_routes | The routes associated with network-01 |
20-
| network_01_self_link | The URI of the VPC network-01 |
21-
| network_01_subnets | The names of the subnets being created on network-01 |
22-
| network_01_subnets_flow_logs | Whether the subnets will have VPC flow logs enabled |
23-
| network_01_subnets_ips | The IP and cidrs of the subnets being created on network-01 |
24-
| network_01_subnets_private_access | Whether the subnets will have access to Google API's without a public IP on network-01 |
25-
| network_01_subnets_regions | The region where the subnets will be created on network-01 |
26-
| network_01_subnets_secondary_ranges | The secondary ranges associated with these subnets on network-01 |
27-
| network_02_name | The name of the VPC network-02 |
28-
| network_02_routes | The routes associated with network-02 |
29-
| network_02_self_link | The URI of the VPC network-02 |
30-
| network_02_subnets | The names of the subnets being created on network-02 |
31-
| network_02_subnets_flow_logs | Whether the subnets will have VPC flow logs enabled |
32-
| network_02_subnets_ips | The IP and cidrs of the subnets being created on network-02 |
33-
| network_02_subnets_private_access | Whether the subnets will have access to Google API's without a public IP on network-02 |
34-
| network_02_subnets_regions | The region where the subnets will be created on network-02 |
35-
| network_02_subnets_secondary_ranges | The secondary ranges associated with these subnets on network-02 |
19+
| network\_01\_name | The name of the VPC network-01 |
20+
| network\_01\_routes | The routes associated with network-01 |
21+
| network\_01\_self\_link | The URI of the VPC network-01 |
22+
| network\_01\_subnets | The names of the subnets being created on network-01 |
23+
| network\_01\_subnets\_flow\_logs | Whether the subnets will have VPC flow logs enabled |
24+
| network\_01\_subnets\_ips | The IP and cidrs of the subnets being created on network-01 |
25+
| network\_01\_subnets\_private\_access | Whether the subnets will have access to Google API's without a public IP on network-01 |
26+
| network\_01\_subnets\_regions | The region where the subnets will be created on network-01 |
27+
| network\_01\_subnets\_secondary\_ranges | The secondary ranges associated with these subnets on network-01 |
28+
| network\_02\_name | The name of the VPC network-02 |
29+
| network\_02\_routes | The routes associated with network-02 |
30+
| network\_02\_self\_link | The URI of the VPC network-02 |
31+
| network\_02\_subnets | The names of the subnets being created on network-02 |
32+
| network\_02\_subnets\_flow\_logs | Whether the subnets will have VPC flow logs enabled |
33+
| network\_02\_subnets\_ips | The IP and cidrs of the subnets being created on network-02 |
34+
| network\_02\_subnets\_private\_access | Whether the subnets will have access to Google API's without a public IP on network-02 |
35+
| network\_02\_subnets\_regions | The region where the subnets will be created on network-02 |
36+
| network\_02\_subnets\_secondary\_ranges | The secondary ranges associated with these subnets on network-02 |
3637

3738
[^]: (autogen_docs_end)

0 commit comments

Comments
 (0)