Skip to content

Commit 071d0d4

Browse files
feat: add integration tests (#11)
* Add support for terraform 0.13 - Update the README - fix the tests (need test docker image update) - bump inspec-gcp version to the latest - remove bucket tests and add gcloud and gcp tests - set the versions to allow terraform 0.13 - change kitchen.yml to be more standardized * Slightly fix the variable names * - pin the image version to 0.12.0 * fix the variable description * bump the version of the developer tools to the latest * - pin the makefile version to 0.13 to be able to automatically get the patch versions - remove the integration test for the compute api - bump the project-factory module to the latest version (v9.0.0) - bump the providers to the latest versions (3.36.0) - re-ran the tests one more time, and they were successful ```sh Profile: simple_example Version: (not specified) Target: local:// ✔ gcloud: Gcloud checks: cloud router existence ✔ JSON from command: gcloud compute routers describe simple-example-crane --region=europe-west1 --project=ci-cloud-router-df88 --format=json name is expected to eq "simple-example- crane" ✔ JSON from command: gcloud compute routers describe simple-example-crane --region=europe-west1 --project=ci-cloud-router-df88 --format=json kind is expected to eq "compute#router" ✔ JSON from command: gcloud compute routers describe simple-example-crane --region=europe-west1 --project=ci-cloud-router-df88 --format=json region is expected to eq "https://www.g oogleapis.com/compute/v1/projects/ci-cloud-router-df88/regions/europe-west1" ✔ JSON from command: gcloud compute routers describe simple-example-crane --region=europe-west1 --project=ci-cloud-router-df88 --format=json selfLink is expected to eq "https://www .googleapis.com/compute/v1/projects/ci-cloud-router-df88/regions/europe-west1/routers/simple-example-crane" Profile Summary: 1 successful control, 0 control failures, 0 controls skipped Test Summary: 4 successful, 0 failures, 0 skipped $$$$$$ Finished verifying the 'local' system. $$$$$$ Verifying the 'inspec-gcp' system... Profile: simple_example Version: (not specified) Target: gcp://[email protected] ✔ gcp: GCP Resources ✔ Router simple-example-crane is expected to exist ✔ Router simple-example-crane name is expected to eq "simple-example-crane" ✔ Router simple-example-crane region is expected to match /\/europe-west1$/ ✔ Router dupe is expected not to exist Profile: Google Cloud Platform Resource Pack (inspec-gcp) Version: 1.7.0 Target: gcp://[email protected] No tests executed. Profile Summary: 1 successful control, 0 control failures, 0 controls skipped Test Summary: 4 successful, 0 failures, 0 skipped ``` * regen docs, fix header * address comments, hardcode example vars Co-authored-by: Bharath KKB <[email protected]>
1 parent 14ec248 commit 071d0d4

File tree

17 files changed

+129
-70
lines changed

17 files changed

+129
-70
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
# Make will use bash instead of sh
1919
SHELL := /usr/bin/env bash
2020

21-
DOCKER_TAG_VERSION_DEVELOPER_TOOLS := 0.12.0
21+
DOCKER_TAG_VERSION_DEVELOPER_TOOLS := 0.12.2
2222
DOCKER_IMAGE_DEVELOPER_TOOLS := cft/developer-tools
2323
REGISTRY_URL := gcr.io/cloud-foundation-cicd
2424

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ Functional examples are included in the
2525
## Inputs
2626

2727
| Name | Description | Type | Default | Required |
28-
|------|-------------|:----:|:-----:|:-----:|
29-
| bgp | BGP information specific to this router. | any | `"null"` | no |
30-
| name | Name of the router | string | n/a | yes |
31-
| nats | NATs to deploy on this router. | any | `<list>` | no |
32-
| network | A reference to the network to which this router belongs | string | n/a | yes |
33-
| project | The project ID to deploy to | string | n/a | yes |
34-
| region | Region where the router resides | string | n/a | yes |
28+
|------|-------------|------|---------|:--------:|
29+
| bgp | BGP information specific to this router. | `any` | `null` | no |
30+
| name | Name of the router | `string` | n/a | yes |
31+
| nats | NATs to deploy on this router. | `any` | `[]` | no |
32+
| network | A reference to the network to which this router belongs | `string` | n/a | yes |
33+
| project | The project ID to deploy to | `string` | n/a | yes |
34+
| region | Region where the router resides | `string` | n/a | yes |
3535

3636
## Outputs
3737

@@ -49,7 +49,7 @@ These sections describe requirements for using this module.
4949

5050
The following dependencies must be available:
5151

52-
- [Terraform][terraform] v0.12
52+
- [Terraform][terraform] v0.12 and above
5353
- [Terraform Provider for GCP][terraform-provider-gcp] plugin v2.0
5454

5555
### Service Account

build/int.cloudbuild.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@ tags:
3838
- 'integration'
3939
substitutions:
4040
_DOCKER_IMAGE_DEVELOPER_TOOLS: 'cft/developer-tools'
41-
_DOCKER_TAG_VERSION_DEVELOPER_TOOLS: '0.12.0'
41+
_DOCKER_TAG_VERSION_DEVELOPER_TOOLS: '0.12.2'

build/lint.cloudbuild.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ tags:
2121
- 'lint'
2222
substitutions:
2323
_DOCKER_IMAGE_DEVELOPER_TOOLS: 'cft/developer-tools'
24-
_DOCKER_TAG_VERSION_DEVELOPER_TOOLS: '0.12.0'
24+
_DOCKER_TAG_VERSION_DEVELOPER_TOOLS: '0.12.2'

examples/simple/main.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ provider "google" {
2121
module "cloud_router" {
2222
source = "../../"
2323

24-
name = "example-router"
25-
project = "example-project"
26-
network = "default"
24+
name = "test-router"
25+
project = var.project
26+
network = var.network
2727
region = "us-central1"
2828
}

examples/simple/outputs.tf

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* Copyright 2020 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 "router_name" {
18+
value = module.cloud_router.router.name
19+
description = "The name of the created router"
20+
}
21+
22+
output "router_region" {
23+
value = module.cloud_router.router.region
24+
description = "The region of the created router"
25+
}

examples/simple/variables.tf

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* Copyright 2020 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 "network" {
18+
type = string
19+
description = "A reference to the network to which this router belongs"
20+
}
21+
22+
variable "project" {
23+
type = string
24+
description = "The GCP project ID"
25+
}

kitchen.yml

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,28 @@
1515
---
1616
driver:
1717
name: terraform
18+
verify_version: false
1819

1920
provisioner:
2021
name: terraform
2122

22-
verifier:
23-
name: terraform
24-
2523
platforms:
26-
- name: default
24+
- name: local
2725

2826
suites:
29-
- name: simple_example
27+
- name: "simple_example"
3028
driver:
29+
name: terraform
3130
root_module_directory: test/fixtures/simple_example/
3231
verifier:
33-
color: false
32+
name: terraform
33+
color: true
3434
systems:
35-
- name: simple_example local
35+
- name: local
3636
backend: local
3737
controls:
3838
- gcloud
39-
- gsutil
40-
- name: simple_example gcp
39+
- name: inspec-gcp
4140
backend: gcp
4241
controls:
4342
- gcp

test/fixtures/simple_example/main.tf

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,18 @@ resource "random_pet" "main" {
2525
}
2626

2727
module "example" {
28-
source = "../../../examples/simple_example"
28+
source = "../../../examples/simple"
2929

30-
project_id = var.project_id
31-
bucket_name = random_pet.main.id
30+
project = var.project_id
31+
network = module.vpc.network_name
32+
}
33+
34+
module "vpc" {
35+
source = "terraform-google-modules/network/google"
36+
version = "~> 2.5"
37+
38+
project_id = var.project_id
39+
network_name = "test-network"
40+
routing_mode = "GLOBAL"
41+
subnets = []
3242
}

test/fixtures/simple_example/outputs.tf

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,17 @@
1414
* limitations under the License.
1515
*/
1616

17-
output "bucket_name" {
18-
description = "The name of the bucket."
19-
value = module.example.bucket_name
20-
}
21-
2217
output "project_id" {
2318
description = "The ID of the project in which resources are provisioned."
2419
value = var.project_id
2520
}
21+
22+
output "cloud_router_name" {
23+
description = "The name of the cloud router"
24+
value = module.example.router_name
25+
}
26+
27+
output "region" {
28+
description = "The region of the cloud router"
29+
value = module.example.router_region
30+
}

0 commit comments

Comments
 (0)