Skip to content

Commit 257d6af

Browse files
committed
Changes from module template
This commit contains all changes resulting from copying the module template over the existing module structure.
1 parent f359716 commit 257d6af

File tree

21 files changed

+465
-45
lines changed

21 files changed

+465
-45
lines changed

.gitignore

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33

44
# OSX trash
55
.DS_Store
6-
*.pyc*
6+
7+
# Python
8+
*.pyc
79

810
# Emacs save files
911
*~
@@ -29,8 +31,17 @@ Session.vim
2931
# Crash log files
3032
crash.log
3133

34+
# Kitchen files
35+
**/inspec.lock
36+
**/.kitchen
37+
**/.kitchen.local.yml
38+
**/Gemfile.lock
39+
3240
# Ignore any .tfvars files that are generated automatically for each Terraform run. Most
3341
# .tfvars files are managed as part of configuration and so should be included in
3442
# version control.
3543
#
3644
# example.tfvars
45+
test/fixtures/shared/terraform.tfvars
46+
47+
credentials.json

.kitchen.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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+
# http://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+
---
16+
driver:
17+
name: "terraform"
18+
command_timeout: 1800
19+
20+
provisioner:
21+
name: "terraform"
22+
23+
platforms:
24+
- name: local
25+
26+
suites:
27+
- name: "simple_example"
28+
driver:
29+
name: "terraform"
30+
command_timeout: 1800
31+
root_module_directory: test/fixtures/simple_example/
32+
verifier:
33+
name: terraform
34+
color: false
35+
systems:
36+
- name: simple_example
37+
backend: local
38+
controls:
39+
- gcloud
40+
- name: simple_example
41+
backend: gcp
42+
shell: true
43+
controls:
44+
- gcp
45+
provisioner:
46+
name: terraform

.ruby-version

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

Gemfile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
# http://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+
ruby '2.5.3'
16+
17+
source 'https://rubygems.org/' do
18+
gem 'kitchen-terraform', '~> 4.0.3'
19+
end

Makefile

Lines changed: 72 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@
1515
# Make will use bash instead of sh
1616
SHELL := /usr/bin/env bash
1717

18+
# Docker build config variables
19+
CREDENTIALS_PATH ?= /cft/workdir/credentials.json
20+
DOCKER_ORG := gcr.io/cloud-foundation-cicd
21+
DOCKER_TAG_BASE_KITCHEN_TERRAFORM ?= 0.11.10_216.0.0_1.19.1_0.1.10
22+
DOCKER_REPO_BASE_KITCHEN_TERRAFORM := ${DOCKER_ORG}/cft/kitchen-terraform:${DOCKER_TAG_BASE_KITCHEN_TERRAFORM}
23+
1824
# All is the first target in the file so it will get picked up when you just run 'make' on its own
1925
all: check_shell check_python check_golang check_terraform check_docker check_base_files test_check_headers check_headers check_trailing_whitespace generate_docs
2026

@@ -45,10 +51,6 @@ check_docker:
4551
check_base_files:
4652
@source test/make.sh && basefiles
4753

48-
.PHONY: check_shebangs
49-
check_shebangs:
50-
@source test/make.sh && check_bash
51-
5254
.PHONY: check_trailing_whitespace
5355
check_trailing_whitespace:
5456
@source test/make.sh && check_trailing_whitespace
@@ -60,9 +62,73 @@ test_check_headers:
6062

6163
.PHONY: check_headers
6264
check_headers:
63-
@echo "Checking file headers"
64-
@python test/verify_boilerplate.py
65+
@source test/make.sh && check_headers
66+
67+
# Integration tests
68+
.PHONY: test_integration
69+
test_integration:
70+
bundle install
71+
bundle exec kitchen create
72+
bundle exec kitchen converge
73+
bundle exec kitchen converge
74+
bundle exec kitchen verify
75+
bundle exec kitchen destroy
6576

6677
.PHONY: generate_docs
6778
generate_docs:
6879
@source test/make.sh && generate_docs
80+
81+
# Versioning
82+
.PHONY: version
83+
version:
84+
@source helpers/version-repo.sh
85+
86+
# Run docker
87+
.PHONY: docker_run
88+
docker_run:
89+
docker run --rm -it \
90+
-e CLOUDSDK_AUTH_CREDENTIAL_FILE_OVERRIDE=${CREDENTIALS_PATH} \
91+
-e GOOGLE_APPLICATION_CREDENTIALS=${CREDENTIALS_PATH} \
92+
-v $(CURDIR):/cft/workdir \
93+
${DOCKER_REPO_BASE_KITCHEN_TERRAFORM} \
94+
/bin/bash
95+
96+
.PHONY: docker_create
97+
docker_create:
98+
docker run --rm -it \
99+
-e CLOUDSDK_AUTH_CREDENTIAL_FILE_OVERRIDE=${CREDENTIALS_PATH} \
100+
-e GOOGLE_APPLICATION_CREDENTIALS=${CREDENTIALS_PATH} \
101+
-v $(CURDIR):/cft/workdir \
102+
${DOCKER_REPO_BASE_KITCHEN_TERRAFORM} \
103+
/bin/bash -c "kitchen create"
104+
105+
.PHONY: docker_converge
106+
docker_converge:
107+
docker run --rm -it \
108+
-e CLOUDSDK_AUTH_CREDENTIAL_FILE_OVERRIDE=${CREDENTIALS_PATH} \
109+
-e GOOGLE_APPLICATION_CREDENTIALS=${CREDENTIALS_PATH} \
110+
-v $(CURDIR):/cft/workdir \
111+
${DOCKER_REPO_BASE_KITCHEN_TERRAFORM} \
112+
/bin/bash -c "kitchen converge && kitchen converge"
113+
114+
.PHONY: docker_verify
115+
docker_verify:
116+
docker run --rm -it \
117+
-e CLOUDSDK_AUTH_CREDENTIAL_FILE_OVERRIDE=${CREDENTIALS_PATH} \
118+
-e GOOGLE_APPLICATION_CREDENTIALS=${CREDENTIALS_PATH} \
119+
-v $(CURDIR):/cft/workdir \
120+
${DOCKER_REPO_BASE_KITCHEN_TERRAFORM} \
121+
/bin/bash -c "kitchen verify"
122+
123+
.PHONY: docker_destroy
124+
docker_destroy:
125+
docker run --rm -it \
126+
-e CLOUDSDK_AUTH_CREDENTIAL_FILE_OVERRIDE=${CREDENTIALS_PATH} \
127+
-e GOOGLE_APPLICATION_CREDENTIALS=${CREDENTIALS_PATH} \
128+
-v $(CURDIR):/cft/workdir \
129+
${DOCKER_REPO_BASE_KITCHEN_TERRAFORM} \
130+
/bin/bash -c "kitchen destroy"
131+
132+
.PHONY: test_integration_docker
133+
test_integration_docker: docker_create docker_converge docker_verify docker_destroy
134+
@echo "Running test-kitchen tests in docker"

helpers/combine_docfiles.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17+
# Please note that this file was generated from
18+
# [terraform-google-module-template](https://github.com/terraform-google-modules/terraform-google-module-template).
19+
# Please make sure to contribute relevant changes upstream!
20+
1721
''' Combine file from:
1822
* script argument 1
1923
with content of file from:
@@ -25,23 +29,31 @@
2529
regex specified here
2630
'''
2731

32+
import os
2833
import re
2934
import sys
3035

31-
insert_separator_regex = '(.*?\[\^\]\:\ \(autogen_docs_start\))(.*?)(\n\[\^\]\:\ \(autogen_docs_end\).*?$)'
32-
exclude_separator_regex = '(.*?)Copyright 20\d\d Google LLC.*?limitations under the License.(.*?)$'
36+
insert_separator_regex = r'(.*?\[\^\]\:\ \(autogen_docs_start\))(.*?)(\n\[\^\]\:\ \(autogen_docs_end\).*?$)' # noqa: E501
37+
exclude_separator_regex = r'(.*?)Copyright 20\d\d Google LLC.*?limitations under the License.(.*?)$' # noqa: E501
3338

3439
if len(sys.argv) != 3:
35-
sys.exit(1)
40+
sys.exit(1)
41+
42+
if not os.path.isfile(sys.argv[1]):
43+
sys.exit(0)
3644

3745
input = open(sys.argv[1], "r").read()
3846
replace_content = open(sys.argv[2], "r").read()
3947

4048
# Exclude the specified content from the replacement content
41-
groups = re.match(exclude_separator_regex, replace_content, re.DOTALL).groups(0)
49+
groups = re.match(
50+
exclude_separator_regex,
51+
replace_content,
52+
re.DOTALL
53+
).groups(0)
4254
replace_content = groups[0] + groups[1]
4355

4456
# Find where to put the replacement content, overwrite the input file
4557
groups = re.match(insert_separator_regex, input, re.DOTALL).groups(0)
46-
output = groups[0] + replace_content + groups[2]
58+
output = groups[0] + replace_content + groups[2] + "\n"
4759
open(sys.argv[1], "w").write(output)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
// These outputs are used to test the module with inspec
18+
// They do not need to be included in real-world uses of this module
19+
20+
output "project_id" {
21+
value = "${var.project_id}"
22+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +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+
17+
variable "project_id" {
18+
description = "The project ID to deploy to"
19+
}

test/fixtures/shared/outputs.tf

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
output "project_id" {
18+
value = "${var.project_id}"
19+
}
20+
21+
output "bucket_name" {
22+
description = "Bucket name"
23+
value = "${module.example.bucket_name}"
24+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
project_id=""

0 commit comments

Comments
 (0)