Skip to content

Commit e273b5e

Browse files
authored
Merge pull request #96 from averbuks/averbuks-95
Fixed issue with depending on outputs introduced in 1.4.1
2 parents 73a1d4b + 11a39c5 commit e273b5e

File tree

7 files changed

+112
-156
lines changed

7 files changed

+112
-156
lines changed

CHANGELOG.md

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

88
## [Unreleased]
99

10+
## [1.4.3] - 2019-10-31
11+
12+
### Fixed
13+
14+
- Fixed issue with depending on outputs introduced in 1.4.1. [#95]
15+
1016
## [1.4.2] - 2019-10-30
1117

1218
### Fixed
@@ -140,7 +146,8 @@ and this project adheres to [Semantic Versioning][semver-site].
140146
- Subnets within the VPC
141147
- Secondary ranges for the subnets (if applicable)
142148

143-
[Unreleased]: https://github.com/terraform-google-modules/terraform-google-network/compare/v1.4.2...HEAD
149+
[Unreleased]: https://github.com/terraform-google-modules/terraform-google-network/compare/v1.4.3...HEAD
150+
[1.4.3]: https://github.com/terraform-google-modules/terraform-google-network/compare/v1.4.2...v1.4.3
144151
[1.4.2]: https://github.com/terraform-google-modules/terraform-google-network/compare/v1.4.1...v1.4.2
145152
[1.4.1]: https://github.com/terraform-google-modules/terraform-google-network/compare/v1.4.0...v1.4.1
146153
[1.4.0]: https://github.com/terraform-google-modules/terraform-google-network/compare/v1.3.0...v1.4.0
@@ -157,6 +164,7 @@ and this project adheres to [Semantic Versioning][semver-site].
157164
[0.2.0]: https://github.com/terraform-google-modules/terraform-google-network/compare/v0.1.0...v0.2.0
158165
[0.1.0]: https://github.com/terraform-google-modules/terraform-google-network/releases/tag/v0.1.0
159166

167+
[#95]: https://github.com/terraform-google-modules/terraform-google-network/issues/95
160168
[#94]: https://github.com/terraform-google-modules/terraform-google-network/pull/94
161169
[#92]: https://github.com/terraform-google-modules/terraform-google-network/issues/92
162170
[#88]: https://github.com/terraform-google-modules/terraform-google-network/issues/88

CONTRIBUTING.md

Lines changed: 82 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -1,137 +1,99 @@
1-
## File structure
2-
The project has the following folders and files:
1+
# Contributing
32

4-
- /: root folder
5-
- /examples: examples for using this module
6-
- /test: Folders with files for testing the module (see Testing section on this file)
7-
- /main.tf: main file for this module, contains all the resources to create
8-
- /variables.tf: all the variables for the module
9-
- /output.tf: the outputs of the module
10-
- /README.md: this file
3+
This document provides guidelines for contributing to the module.
114

12-
## Testing and documentation generation
5+
## Dependencies
136

14-
### Requirements
15-
- [docker](https://docker.com/)
7+
The following dependencies must be installed on the development system:
168

17-
### Integration testing
18-
##### Terraform integration tests
9+
- [Docker Engine][docker-engine]
10+
- [Google Cloud SDK][google-cloud-sdk]
11+
- [make]
1912

20-
The module's integration tests are designed to be run within a Docker
21-
container containing all the dependencies required for testing. The
22-
`docker_test_integration` make target wraps this behavior but requires the
23-
following configuration to execute properly:
13+
## Generating Documentation for Inputs and Outputs
2414

25-
- Configure a service account with the roles documented above and export the JSON key to the `SERVICE_ACCOUNT_JSON` environment variable
15+
The Inputs and Outputs tables in the READMEs of the root module,
16+
submodules, and example modules are automatically generated based on
17+
the `variables` and `outputs` of the respective modules. These tables
18+
must be refreshed if the module interfaces are changed.
2619

27-
export SERVICE_ACCOUNT_JSON=$(< /path/to/credentials.json)
20+
### Execution
2821

29-
- Create `test/fixtures/shared/terraform.tfvars` and populate with the required Terraform input variables (see `test/fixtures/shared/terraform.tfvars.sample` for more information)
22+
Run `make generate_docs` to generate new Inputs and Outputs tables.
3023

31-
Once those steps have been completed run `make docker_test_integration` from
32-
the root of the repository to execute the tests within the `project_id`
33-
provided. Infrastructure from `test/fixtures/*` will be provisioned,
34-
integration tests from `test/integration/*` will be executed, and the
35-
infrastructure will be deprovisioned to complete the process.
24+
## Integration Testing
3625

37-
### Autogeneration of documentation from .tf files
38-
Run
39-
```
40-
make generate_docs
41-
```
26+
Integration tests are used to verify the behaviour of the root module,
27+
submodules, and example modules. Additions, changes, and fixes should
28+
be accompanied with tests.
29+
30+
The integration tests are run using [Kitchen][kitchen],
31+
[Kitchen-Terraform][kitchen-terraform], and [InSpec][inspec]. These
32+
tools are packaged within a Docker image for convenience.
4233

43-
### Lint testing
34+
The general strategy for these tests is to verify the behaviour of the
35+
[example modules](./examples/), thus ensuring that the root module,
36+
submodules, and example modules are all functionally correct.
4437

45-
Lint testing is also performed within a Docker container containing all the
46-
dependencies required for lint tests. Execute those tests by running `make
47-
docker_test_lint` from the root of the repository.
38+
### Test Environment
39+
The easiest way to test the module is in an isolated test project. The setup for such a project is defined in [test/setup](./test/setup/) directory.
4840

49-
Successful output looks similar to the following:
41+
To use this setup, you need a service account with Project Creator access on a folder. Export the Service Account credentials to your environment like so:
42+
43+
```
44+
export SERVICE_ACCOUNT_JSON=$(< credentials.json)
45+
```
5046

47+
You will also need to set a few environment variables:
5148
```
52-
Checking for trailing whitespace
53-
Checking for missing newline at end of file
54-
Running shellcheck
55-
Checking file headers
56-
Running flake8
57-
Running terraform fmt
58-
terraform fmt -diff -check=true -write=false .
59-
terraform fmt -diff -check=true -write=false ./codelabs/simple
60-
terraform fmt -diff -check=true -write=false ./examples/delete_default_gateway_routes
61-
terraform fmt -diff -check=true -write=false ./examples/multi_vpc
62-
terraform fmt -diff -check=true -write=false ./examples/secondary_ranges
63-
terraform fmt -diff -check=true -write=false ./examples/simple_project
64-
terraform fmt -diff -check=true -write=false ./examples/simple_project_with_regional_network
65-
terraform fmt -diff -check=true -write=false ./examples/submodule_firewall
66-
terraform fmt -diff -check=true -write=false ./examples/submodule_svpc_access
67-
terraform fmt -diff -check=true -write=false ./modules/fabric-net-firewall
68-
terraform fmt -diff -check=true -write=false ./modules/fabric-net-svpc-access
69-
terraform fmt -diff -check=true -write=false ./test/fixtures/all_examples
70-
terraform fmt -diff -check=true -write=false ./test/fixtures/delete_default_gateway_routes
71-
terraform fmt -diff -check=true -write=false ./test/fixtures/multi_vpc
72-
terraform fmt -diff -check=true -write=false ./test/fixtures/secondary_ranges
73-
terraform fmt -diff -check=true -write=false ./test/fixtures/shared
74-
terraform fmt -diff -check=true -write=false ./test/fixtures/simple_project
75-
terraform fmt -diff -check=true -write=false ./test/fixtures/simple_project_with_regional_network
76-
terraform fmt -diff -check=true -write=false ./test/fixtures/simulated_ci_environment
77-
terraform fmt -diff -check=true -write=false ./test/fixtures/submodule_firewall
78-
Running terraform validate
79-
terraform_validate .
80-
Success! The configuration is valid.
81-
82-
terraform_validate ./codelabs/simple
83-
Success! The configuration is valid.
84-
85-
terraform_validate ./examples/delete_default_gateway_routes
86-
Success! The configuration is valid.
87-
88-
terraform_validate ./examples/multi_vpc
89-
Success! The configuration is valid.
90-
91-
terraform_validate ./examples/secondary_ranges
92-
Success! The configuration is valid.
93-
94-
terraform_validate ./examples/simple_project
95-
Success! The configuration is valid.
96-
97-
terraform_validate ./examples/simple_project_with_regional_network
98-
Success! The configuration is valid.
99-
100-
terraform_validate ./examples/submodule_firewall
101-
Success! The configuration is valid.
102-
103-
terraform_validate ./examples/submodule_svpc_access
104-
Success! The configuration is valid.
105-
106-
terraform_validate ./modules/fabric-net-firewall
107-
Success! The configuration is valid.
108-
109-
terraform_validate ./modules/fabric-net-svpc-access
110-
Success! The configuration is valid.
111-
112-
terraform_validate ./test/fixtures/all_examples
113-
Success! The configuration is valid.
114-
115-
terraform_validate ./test/fixtures/delete_default_gateway_routes
116-
Success! The configuration is valid.
117-
118-
terraform_validate ./test/fixtures/multi_vpc
119-
Success! The configuration is valid.
120-
121-
terraform_validate ./test/fixtures/secondary_ranges
122-
Success! The configuration is valid.
123-
124-
terraform_validate ./test/fixtures/simple_project
125-
Success! The configuration is valid.
126-
127-
terraform_validate ./test/fixtures/simple_project_with_regional_network
128-
Success! The configuration is valid.
129-
130-
terraform_validate ./test/fixtures/simulated_ci_environment
131-
Success! The configuration is valid.
132-
133-
terraform_validate ./test/fixtures/submodule_firewall
134-
Success! The configuration is valid.
49+
export TF_VAR_org_id="your_org_id"
50+
export TF_VAR_folder_id="your_folder_id"
51+
export TF_VAR_billing_account="your_billing_account_id"
13552
```
13653

137-
[terraform-provider-google]: https://github.com/terraform-providers/terraform-provider-google
54+
With these settings in place, you can prepare a test project using Docker:
55+
```
56+
make docker_test_prepare
57+
```
58+
59+
### Noninteractive Execution
60+
61+
Run `make docker_test_integration` to test all of the example modules
62+
noninteractively, using the prepared test project.
63+
64+
### Interactive Execution
65+
66+
1. Run `make docker_run` to start the testing Docker container in
67+
interactive mode.
68+
69+
1. Run `kitchen_do create <EXAMPLE_NAME>` to initialize the working
70+
directory for an example module.
71+
72+
1. Run `kitchen_do converge <EXAMPLE_NAME>` to apply the example module.
73+
74+
1. Run `kitchen_do verify <EXAMPLE_NAME>` to test the example module.
75+
76+
1. Run `kitchen_do destroy <EXAMPLE_NAME>` to destroy the example module
77+
state.
78+
79+
## Linting and Formatting
80+
81+
Many of the files in the repository can be linted or formatted to
82+
maintain a standard of quality.
83+
84+
### Execution
85+
86+
Run `make docker_test_lint`.
87+
88+
[docker-engine]: https://www.docker.com/products/docker-engine
89+
[flake8]: http://flake8.pycqa.org/en/latest/
90+
[gofmt]: https://golang.org/cmd/gofmt/
91+
[google-cloud-sdk]: https://cloud.google.com/sdk/install
92+
[hadolint]: https://github.com/hadolint/hadolint
93+
[inspec]: https://inspec.io/
94+
[kitchen-terraform]: https://github.com/newcontext-oss/kitchen-terraform
95+
[kitchen]: https://kitchen.ci/
96+
[make]: https://en.wikipedia.org/wiki/Make_(software)
97+
[shellcheck]: https://www.shellcheck.net/
98+
[terraform-docs]: https://github.com/segmentio/terraform-docs
99+
[terraform]: https://terraform.io/

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,3 +160,8 @@ If you are going to manage a Shared VPC, you must have either:
160160
In order to operate with the Service Account you must activate the following API on the project where the Service Account was created:
161161

162162
- Compute Engine API - compute.googleapis.com
163+
164+
## Contributing
165+
166+
Refer to the [contribution guidelines](./CONTRIBUTING.md) for
167+
information on contributing to this module.

main.tf

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

17+
locals {
18+
network_self_link = var.create_network ? google_compute_network.network[0].self_link : data.google_compute_network.network[0].self_link
19+
network_name = var.create_network ? google_compute_network.network[0].name : data.google_compute_network.network[0].name
20+
}
21+
1722
/******************************************
1823
VPC configuration
1924
*****************************************/
@@ -27,17 +32,17 @@ resource "google_compute_network" "network" {
2732
}
2833

2934
data "google_compute_network" "network" {
30-
name = var.network_name
31-
project = var.project_id
32-
depends_on = [google_compute_network.network]
35+
count = var.create_network ? 0 : 1
36+
name = var.network_name
37+
project = var.project_id
3338
}
3439

3540
/******************************************
3641
Shared VPC
3742
*****************************************/
3843
resource "google_compute_shared_vpc_host_project" "shared_vpc_host" {
3944
count = var.shared_vpc_host == "true" ? 1 : 0
40-
project = data.google_compute_network.network.project
45+
project = var.project_id
4146
}
4247

4348
/******************************************
@@ -51,7 +56,7 @@ resource "google_compute_subnetwork" "subnetwork" {
5156
region = var.subnets[count.index]["subnet_region"]
5257
private_ip_google_access = lookup(var.subnets[count.index], "subnet_private_access", "false")
5358
enable_flow_logs = lookup(var.subnets[count.index], "subnet_flow_logs", "false")
54-
network = data.google_compute_network.network.name
59+
network = local.network_self_link
5560
project = var.project_id
5661
secondary_ip_range = [for i in range(length(contains(keys(var.secondary_ranges), var.subnets[count.index]["subnet_name"]) == true ? var.secondary_ranges[var.subnets[count.index]["subnet_name"]] : [])) : var.secondary_ranges[var.subnets[count.index]["subnet_name"]][i]]
5762
description = lookup(var.subnets[count.index], "description", null)
@@ -71,8 +76,8 @@ data "google_compute_subnetwork" "created_subnets" {
7176
resource "google_compute_route" "route" {
7277
count = length(var.routes)
7378
project = var.project_id
74-
network = data.google_compute_network.network.name
75-
name = lookup(var.routes[count.index], "name", format("%s-%s-%d", lower(var.network_name), "route", count.index))
79+
network = local.network_name
80+
name = lookup(var.routes[count.index], "name", format("%s-%s-%d", lower(local.network_name), "route", count.index))
7681
description = lookup(var.routes[count.index], "description", "")
7782
tags = compact(split(",", lookup(var.routes[count.index], "tags", "")))
7883
dest_range = lookup(var.routes[count.index], "destination_range", "")
@@ -92,7 +97,7 @@ resource "null_resource" "delete_default_internet_gateway_routes" {
9297
count = var.delete_default_internet_gateway_routes ? 1 : 0
9398

9499
provisioner "local-exec" {
95-
command = "${path.module}/scripts/delete-default-gateway-routes.sh ${var.project_id} ${var.network_name}"
100+
command = "${path.module}/scripts/delete-default-gateway-routes.sh ${var.project_id} ${local.network_name}"
96101
}
97102

98103
triggers = {

outputs.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515
*/
1616

1717
output "network_name" {
18-
value = var.create_network ? google_compute_network.network[0].name : data.google_compute_network.network.name
18+
value = local.network_name
1919
description = "The name of the VPC being created"
2020
}
2121

2222
output "network_self_link" {
23-
value = var.create_network ? google_compute_network.network[0].self_link : data.google_compute_network.network.self_link
23+
value = local.network_self_link
2424
description = "The URI of the VPC being created"
2525
}
2626

test/setup/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
module "project" {
1818
source = "terraform-google-modules/project-factory/google"
19-
version = "~> 3.0"
19+
version = "~> 4.0"
2020

2121
name = "ci-network"
2222
random_project_id = "true"

test/setup/make_source.sh

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

0 commit comments

Comments
 (0)