Skip to content

Commit ac190c7

Browse files
authored
Merge pull request #1 from terraform-google-modules/morgante/initial-release
Initial release
2 parents 9ae4c15 + d95033e commit ac190c7

32 files changed

+1636
-3
lines changed

.gitignore

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# OSX leaves these everywhere on SMB shares
2+
._*
3+
4+
# OSX trash
5+
.DS_Store
6+
*.pyc*
7+
8+
# Emacs save files
9+
*~
10+
\#*\#
11+
.\#*
12+
13+
# Vim-related files
14+
[._]*.s[a-w][a-z]
15+
[._]s[a-w][a-z]
16+
*.un~
17+
Session.vim
18+
.netrwhist
19+
20+
### https://raw.github.com/github/gitignore/90f149de451a5433aebd94d02d11b0e28843a1af/Terraform.gitignore
21+
22+
# Local .terraform directories
23+
**/.terraform/*
24+
25+
# .tfstate files
26+
*.tfstate
27+
*.tfstate.*
28+
29+
# Crash log files
30+
crash.log
31+
32+
# Ignore any .tfvars files that are generated automatically for each Terraform run. Most
33+
# .tfvars files are managed as part of configuration and so should be included in
34+
# version control.
35+
#
36+
# example.tfvars

LICENSE

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
Apache License
23
Version 2.0, January 2004
34
http://www.apache.org/licenses/
@@ -198,4 +199,4 @@
198199
distributed under the License is distributed on an "AS IS" BASIS,
199200
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200201
See the License for the specific language governing permissions and
201-
limitations under the License.
202+
limitations under the License.

Makefile

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Copyright 2018 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# Make will use bash instead of sh
16+
SHELL := /usr/bin/env bash
17+
18+
# All is the first target in the file so it will get picked up when you just run 'make' on its own
19+
all: check_shell check_python check_golang check_terraform check_docker check_base_files test_check_headers check_headers check_trailing_whitespace
20+
21+
# The .PHONY directive tells make that this isn't a real target and so
22+
# the presence of a file named 'check_shell' won't cause this target to stop
23+
# working
24+
.PHONY: check_shell
25+
check_shell:
26+
@source test/make.sh && check_shell
27+
28+
.PHONY: check_python
29+
check_python:
30+
@source test/make.sh && check_python
31+
32+
.PHONY: check_golang
33+
check_golang:
34+
@source test/make.sh && golang
35+
36+
.PHONY: check_terraform
37+
check_terraform:
38+
@source test/make.sh && check_terraform
39+
40+
.PHONY: check_docker
41+
check_docker:
42+
@source test/make.sh && docker
43+
44+
.PHONY: check_base_files
45+
check_base_files:
46+
@source test/make.sh && basefiles
47+
48+
.PHONY: check_shebangs
49+
check_shebangs:
50+
@source test/make.sh && check_bash
51+
52+
.PHONY: check_trailing_whitespace
53+
check_trailing_whitespace:
54+
@source test/make.sh && check_trailing_whitespace
55+
56+
.PHONY: test_check_headers
57+
test_check_headers:
58+
@echo "Testing the validity of the header check"
59+
@python test/test_verify_boilerplate.py
60+
61+
.PHONY: check_headers
62+
check_headers:
63+
@echo "Checking file headers"
64+
@python test/verify_boilerplate.py
65+

README.md

Lines changed: 144 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,144 @@
1-
# terraform-google-network
2-
A Cloud Foundation Toolkit Module: Opinionated Google Cloud Platform project creation and configuration with Shared VPC, IAM, APIs, etc.
1+
# Terraform Network Module
2+
3+
This modules makes it easy to set up a new VPC Network in GCP by defining your network and subnet ranges in a concise syntax.
4+
5+
It supports creating:
6+
7+
- A Google Virtual Private Network (VPC)
8+
- Subnets within the VPC
9+
- Secondary ranges for the subnets (if applicable)
10+
11+
## Requirements
12+
### Terraform plugins
13+
- [Terraform](https://www.terraform.io/downloads.html) 0.10.x
14+
- [terraform-provider-google](https://github.com/terraform-providers/terraform-provider-google) plugin v1.8.0
15+
16+
### Configure a Service Account
17+
In order to execute this module you must have a Service Account with the following roles:
18+
19+
- roles/compute.networkAdmin on the organization
20+
21+
### Enable API's
22+
In order to operate with the Service Account you must activate the following API on the project where the Service Account was created:
23+
24+
- Compute Engine API - compute.googleapis.com
25+
26+
## Install
27+
28+
### Terraform
29+
Be sure you have the correct Terraform version (0.10.x), you can choose the binary here:
30+
- https://releases.hashicorp.com/terraform/
31+
32+
## Usage
33+
You can go to the examples folder, however the usage of the module could be like this in your own main.tf file:
34+
35+
```hcl
36+
module "vpc" {
37+
source = "github.com/terraform-google-modules/terraform-google-network"
38+
project_id = "<PROJECT ID>"
39+
vpc_name = "example-vpc"
40+
41+
subnets = [
42+
{
43+
subnet_name = "subnet-01"
44+
subnet_ip = "10.10.10.0/24"
45+
subnet_region = "us-west1"
46+
subnet_private_access = false
47+
},
48+
{
49+
subnet_name = "subnet-02"
50+
subnet_ip = "10.10.20.0/24"
51+
subnet_region = "us-west1"
52+
subnet_private_access = false
53+
},
54+
]
55+
56+
secondary_ranges = {
57+
subnet-01 = [
58+
{
59+
range_name = "subnet-01-secondary-01"
60+
ip_cidr_range = "192.168.64.0/24"
61+
},
62+
]
63+
64+
subnet-02 = []
65+
}
66+
}
67+
```
68+
69+
Then perform the following commands on the root folder:
70+
71+
- `terraform init` to get the plugins
72+
- `terraform plan` to see the infrastructure plan
73+
- `terraform apply` to apply the infrastructure build
74+
- `terraform destroy` to destroy the built infrastructure
75+
76+
#### Variables
77+
Please refer the /variables.tf file for the required and optional variables.
78+
79+
#### Outputs
80+
Please refer the /outputs.tf file for the outputs that you can get with the `terraform output` command
81+
82+
## File structure
83+
The project has the following folders and files:
84+
85+
- /: root folder
86+
- /examples: examples for using this module
87+
- /test: Folders with files for testing the module (see Testing section on this file)
88+
- /main.tf: main file for this module, contains all the resources to create
89+
- /variables.tf: all the variables for the module
90+
- /output.tf: the outputs of the module
91+
- /README.md: this file
92+
93+
## Testing
94+
95+
### Requirements
96+
- [bats](https://github.com/sstephenson/bats) 0.4.0
97+
- [jq](https://stedolan.github.io/jq/) 1.5
98+
99+
### Integration test
100+
##### Terraform integration tests
101+
The integration tests for this module are built with bats, basically the test checks the following:
102+
- Perform `terraform init` command
103+
- Perform `terraform get` command
104+
- Perform `terraform plan` command and check that it'll create *n* resources, modify 0 resources and delete 0 resources
105+
- Perform `terraform apply -auto-approve` command and check that it has created the *n* resources, modified 0 resources and deleted 0 resources
106+
- Perform several `gcloud` commands and check the infrastructure is in the desired state
107+
- Perform `terraform destroy -force` command and check that it has destroyed the *n* resources
108+
109+
You can use the following command to run the integration test in the folder */test/integration/gcloud-test*
110+
111+
`. launch.sh`
112+
113+
### Linting
114+
The makefile in this project will lint or sometimes just format any shell,
115+
Python, golang, Terraform, or Dockerfiles. The linters will only be run if
116+
the makefile finds files with the appropriate file extension.
117+
118+
All of the linter checks are in the default make target, so you just have to
119+
run
120+
121+
```
122+
make -s
123+
```
124+
125+
The -s is for 'silent'. Successful output looks like this
126+
127+
```
128+
Running shellcheck
129+
Running flake8
130+
Running gofmt
131+
Running terraform validate
132+
Running hadolint on Dockerfiles
133+
Test passed - Verified all file Apache 2 headers
134+
```
135+
136+
The linters
137+
are as follows:
138+
* Shell - shellcheck. Can be found in homebrew
139+
* Python - flake8. Can be installed with 'pip install flake8'
140+
* Golang - gofmt. gofmt comes with the standard golang installation. golang
141+
is a compiled language so there is no standard linter.
142+
* Terraform - terraform has a built-in linter in the 'terraform validate'
143+
command.
144+
* Dockerfiles - hadolint. Can be found in homebrew

examples/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.tfvars

examples/multi_vpc/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Multiple Networks
2+
3+
This example configures a host network project with two separate networks.

examples/multi_vpc/main.tf

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
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+
17+
module "test-vpc-module-01" {
18+
source = "../../"
19+
project_id = "${var.project_id}"
20+
network_name = "test-network-01"
21+
22+
subnets = [
23+
{
24+
subnet_name = "test-network-01-subnet-01"
25+
subnet_ip = "10.10.10.0/24"
26+
subnet_region = "us-west1"
27+
subnet_private_access = false
28+
},
29+
{
30+
subnet_name = "test-network-01-subnet-02"
31+
subnet_ip = "10.10.20.0/24"
32+
subnet_region = "us-west1"
33+
subnet_private_access = false
34+
},
35+
{
36+
subnet_name = "test-network-01-subnet-03"
37+
subnet_ip = "10.10.30.0/24"
38+
subnet_region = "us-west1"
39+
subnet_private_access = false
40+
},
41+
]
42+
43+
secondary_ranges = {
44+
test-network-01-subnet-01 = [
45+
{
46+
range_name = "test-network-01-subnet-01-01"
47+
ip_cidr_range = "192.168.64.0/24"
48+
},
49+
{
50+
range_name = "test-network-01-subnet-01-02"
51+
ip_cidr_range = "192.168.65.0/24"
52+
},
53+
]
54+
55+
test-network-01-subnet-02 = [
56+
{
57+
range_name = "test-network-01-subnet-02-01"
58+
ip_cidr_range = "192.168.74.0/24"
59+
},
60+
]
61+
62+
test-network-01-subnet-03 = []
63+
}
64+
}
65+
66+
module "test-vpc-module-02" {
67+
source = "../../"
68+
project_id = "${var.project_id}"
69+
network_name = "test-network-02"
70+
71+
subnets = [
72+
{
73+
subnet_name = "test-network-02-subnet-01"
74+
subnet_ip = "10.10.40.0/24"
75+
subnet_region = "us-west1"
76+
subnet_private_access = false
77+
},
78+
{
79+
subnet_name = "test-network-02-subnet-02"
80+
subnet_ip = "10.10.50.0/24"
81+
subnet_region = "us-west1"
82+
subnet_private_access = false
83+
},
84+
]
85+
86+
secondary_ranges = {
87+
test-network-02-subnet-01 = [
88+
{
89+
range_name = "est-network-02-subnet-02-01"
90+
ip_cidr_range = "192.168.75.0/24"
91+
},
92+
]
93+
94+
test-network-02-subnet-02 = []
95+
}
96+
}

0 commit comments

Comments
 (0)