Skip to content

Commit a111499

Browse files
committed
Event function: update testing to new approach
Added Region and Zone variable for test/setup/variables.tf required to run example terraform files during testing. Fixes #26
1 parent a45f1d1 commit a111499

File tree

6 files changed

+23
-170
lines changed

6 files changed

+23
-170
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,15 @@
1-
CONTRIBUTING# Contributing
1+
# Contributing
22

33
This document provides guidelines for contributing to the module.
44

55
## Dependencies
66

77
The following dependencies must be installed on the development system:
88

9-
- [Terraform][terraform-site] v0.12.Z
109
- [Docker Engine][docker-engine]
1110
- [Google Cloud SDK][google-cloud-sdk]
1211
- [make]
1312

14-
### IAM Roles
15-
16-
The Service Account which will be used to invoke this module must have
17-
the following IAM roles:
18-
19-
- Cloud Functions Developer: `roles/cloudfunctions.developer`
20-
- Storage Admin: `roles/storage.admin`
21-
22-
### APIs
23-
24-
The project against which this module will be invoked must have the
25-
following APIs enabled:
26-
27-
- Cloud Functions API: `cloudfunctions.googleapis.com`
28-
- Cloud Storage API: `storage-component.googleapis.com`
29-
30-
The [Project Factory module][project-factory-module-site] can be used to
31-
provision projects with specific APIs activated.
32-
3313
## Generating Documentation for Inputs and Outputs
3414

3515
The Inputs and Outputs tables in the READMEs of the root module,

README.md

Lines changed: 1 addition & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -86,121 +86,4 @@ following APIs enabled:
8686
- Cloud Storage API: `storage-component.googleapis.com`
8787

8888
The [Project Factory module][project-factory-module-site] can be used to
89-
provision projects with specific APIs activated.
90-
91-
## Testing
92-
93-
The [fixtures directory](test/fixtures) and
94-
[integration directory](test/integration) comprise Terraform
95-
modules and InSpec tests used to verify the behaviour of this module.
96-
97-
### Testing Software Dependencies
98-
99-
The following software dependencies must be installed on the system
100-
from which the tests will be invoked:
101-
102-
- [Ruby][ruby-site] v2.5
103-
- [Bundler][bundler-site] v1.17
104-
105-
### Integration Tests
106-
107-
Integration tests are invoked using [Kitchen][kitchen-site],
108-
[Kitchen-Terraform][kitchen-terraform-site], and [InSpec][inspec-site].
109-
110-
Kitchen instances are configured in the
111-
[Kitchen configuration file](kitchen.yml). The instances use the modules
112-
in [fixtures directory](test/fixtures) to invoke identically named
113-
modules in the [examples directory](examples) and test this module.
114-
115-
#### Integration Tests Configuration
116-
117-
Each Kitchen instance requires a variable file named `terraform.tfvars`
118-
to be created and populated in the associated test fixture. For
119-
convenience, a [sample variable file][sameple-variable-file] is
120-
available.
121-
122-
A key file for a Service Account with the required
123-
[IAM roles](#iam-roles) must be downloaded from the GCP console and
124-
placed in the root directory of this repository. The key file must be
125-
renamed to `credentials.json`.
126-
127-
#### Integration Tests Execution
128-
129-
Run `make test_integration_docker` to execute all of the Kitchen
130-
instances in a non-interactive manner within a Docker container.
131-
132-
Alternatively, the Kitchen instances can be invoked interactively:
133-
134-
1. Run `make docker_run` to start the Docker container. The root
135-
directory of this repository will be mounted in the Docker container
136-
at `/cft/workdir/`.
137-
1. Run `kitchen create` to initialize all Kitchen instances, or run
138-
`kitchen create <INSTANCE_NAME>` to initialize a specific Kitchen
139-
instance.
140-
1. Run `kitchen converge` to apply all Kitchen instances, or run
141-
`kitchen converge <INSTANCE_NAME>` to apply a specific Kitchen
142-
instance.
143-
1. Run `kitchen verify` to test all Kitchen instances, or run
144-
`kitchen verify <INSTANCE_NAME>` to test a specific Kitchen instance.
145-
1. Run `kitchen destroy` to destroy all Kitchen instances, or run
146-
`kitchen destroy <INSTANCE_NAME>` to destroy a specific Kitchen
147-
instance.
148-
149-
## Linting
150-
151-
Linters are available for most of the filetypes in this repository.
152-
153-
### Linting Software Dependencies
154-
155-
The following software dependencies must be installed on the system
156-
from which the linting will be invoked:
157-
158-
- [flake8][flake8-site].
159-
- [ShellCheck][shellcheck-site].
160-
- [terrafom validate][terraform-validate-site].
161-
162-
### Linting Execution
163-
164-
Run `make check --silent` to execute all of the linters.
165-
166-
Alternatively, the linters can be invoked individually.
167-
168-
- Run `make check_python` to lint Python files.
169-
- Run `make check_shell` to lint Shell files.
170-
- Run `make check_terraform` to lint Terraform files.
171-
172-
## Documentation
173-
174-
The documentation of inputs and outputs for modules in this repository
175-
is automatically generated in each module's `README.md` based on the
176-
contents of the relevant `.tf` files.
177-
178-
### Documentation Software Dependencies
179-
180-
The following software dependencies must be installed on the system
181-
from which the documentation will be generated:
182-
183-
- [terraform-docs][terraform-docs-site] v0.6.0
184-
185-
### Generation
186-
187-
Run `make generate_docs` to update the documentation.
188-
189-
[automatic-labelling-from-localhost-example]: examples/automatic-labelling-from-localhost
190-
[bundler-site]: https://bundler.io/
191-
[event-project-log-entry-submodule]: modules/event-project-log-entry
192-
[repository-function-submodule]: modules/repository-function
193-
[flake8-site]: https://pypi.org/project/flake8/
194-
[gofmt-site]: https://golang.org/cmd/gofmt/
195-
[hadolint-site]: https://github.com/hadolint/hadolint/
196-
[inspec-site]: https://inspec.io/
197-
[kitchen-site]: https://kitchen.ci/
198-
[kitchen-terraform-site]: https://github.com/newcontext-oss/kitchen-terraform/
199-
[project-factory-module-site]: https://github.com/terraform-google-modules/terraform-google-project-factory/
200-
[ruby-site]: https://ruby-lang.org/
201-
[sample-variable-file]: test/fixtures/shared/terraform.tfvars.sample
202-
[shellcheck-site]: https://www.shellcheck.net/
203-
[terraform-docs-site]: https://github.com/segmentio/terraform-docs/releases/
204-
[terraform-provider-gcp-site]: https://github.com/terraform-providers/terraform-provider-google/
205-
[terraform-site]: https://www.terraform.io/
206-
[terraform-validate-site]: https://www.terraform.io/docs/commands/validate.html
89+
provision projects with specific APIs activated.

test/setup/iam.tf

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,13 @@
1616

1717
locals {
1818
int_required_roles = [
19-
"roles/owner",
20-
"roles/compute.admin"
19+
"roles/cloudfunctions.developer",
20+
"roles/storage.admin",
21+
"roles/compute.admin",
22+
"roles/pubsub.admin",
23+
"roles/logging.configWriter",
24+
"roles/source.admin",
25+
"roles/iam.serviceAccountUser"
2126
]
2227
}
2328

test/setup/main.tf

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

17-
resource "random_id" "project" {
18-
byte_length = 4
19-
}
20-
2117
locals {
22-
project_name = "ci-event-function-${random_id.project.hex}"
23-
region = random_shuffle.available_regions.result[0]
24-
zone = random_shuffle.available_zones.result[0]
18+
project_name = "ci-event-function"
2519
}
2620

2721

@@ -30,7 +24,7 @@ module "project" {
3024
version = "~> 3.0"
3125

3226
name = local.project_name
33-
random_project_id = false
27+
random_project_id = true
3428
auto_create_network = true
3529
org_id = var.org_id
3630
folder_id = var.folder_id
@@ -47,22 +41,3 @@ module "project" {
4741
]
4842
}
4943

50-
data "google_compute_regions" "available" {
51-
project = module.project.project_id
52-
}
53-
54-
resource "random_shuffle" "available_regions" {
55-
input = data.google_compute_regions.available.names
56-
result_count = 1
57-
}
58-
59-
data "google_compute_zones" "available" {
60-
project = module.project.project_id
61-
region = local.region
62-
}
63-
64-
resource "random_shuffle" "available_zones" {
65-
input = data.google_compute_zones.available.names
66-
result_count = 3
67-
}
68-

test/setup/outputs.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ output "sa_key" {
2424
}
2525

2626
output "region" {
27-
value = local.region
27+
value = var.region
2828
}
2929

3030
output "zone" {
31-
value = local.zone
31+
value = var.zone
3232
}
3333

test/setup/variables.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,13 @@ variable "folder_id" {
2424
variable "billing_account" {
2525
description = "The billing account id associated with the project, e.g. XXXXXX-YYYYYY-ZZZZZZ"
2626
}
27+
28+
variable "region" {
29+
description = "Compute region to create test resources"
30+
default = "us-east4"
31+
}
32+
33+
variable "zone" {
34+
description = "Compute region zone to create test resources"
35+
default = "us-east4-a"
36+
}

0 commit comments

Comments
 (0)