Skip to content

Commit

Permalink
docs(readme): Clean up (#25)
Browse files Browse the repository at this point in the history
* docs(readme): Clean up

* fix: Add region to terratest.yml file to fix tests

* fix: Increases timeout for terrafrom tests to 150 from 90

* test: Fix command execution

* ci(terratest): Add path filters, manual trigger

* fix: Add region to terratest github workflow

---------

Co-authored-by: sunil <sunil@honestbank.com>
  • Loading branch information
jai and sunilhonest authored Apr 4, 2023
1 parent c4a539a commit 9cbd462
Show file tree
Hide file tree
Showing 13 changed files with 34 additions and 70 deletions.
2 changes: 0 additions & 2 deletions .github/semantic.yml

This file was deleted.

12 changes: 9 additions & 3 deletions .github/workflows/terratest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,33 @@ name: terratest
permissions: read-all

on:
workflow_dispatch:
pull_request:
branches:
- main
paths:
- 'modules/**'
- 'examples/**'
- 'test/**'
push:
branches:
- main

env:
TERRATEST_GOOGLE_CREDENTIALS: ${{ secrets.TERRATEST_GOOGLE_CREDENTIALS }}
GOOGLE_PROJECT: ${{ secrets.TERRATEST_GOOGLE_PROJECT }}
GCP_SA_EMAIL: ${{ secrets.TERRATEST_GCP_SA_EMAIL }}
TF_VAR_google_project: ${{ secrets.TERRATEST_GOOGLE_PROJECT }}
TF_VAR_google_credentials: ${{ secrets.TERRATEST_GOOGLE_CREDENTIALS }}
TF_VAR_shared_vpc_host_google_credentials: ${{ secrets.TERRATEST_GOOGLE_CREDENTIALS }}
TF_VAR_google_region: ${{ secrets.TERRATEST_GOOGLE_REGION }}
jobs:
terratest:
name: terratest
runs-on: ubuntu-latest
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
submodules: true
- name: Set up Go (1.17)
Expand All @@ -40,8 +47,7 @@ jobs:
run: |
make tests
- name: Release
if: github.event_name == 'push'
uses: cycjimmy/semantic-release-action@v2
uses: cycjimmy/semantic-release-action@v3
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
Expand Down
7 changes: 7 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,10 @@ repos:
exclude: (test/|examples/)
- id: terraform_checkov
exclude: (test/|examples/)
- repo: https://github.com/gitguardian/ggshield
rev: v1.14.5 # Update to latest version by running `pre-commit autoupdate`
hooks:
- id: ggshield
language: python
stages: [commit]
args: [ 'secret', 'scan', 'pre-commit' ]
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ apply_and_destroy:
terraform apply -auto-approve && terraform apply -auto-approve -destroy

tests:
cd test; go clean -testcache; go test -v -timeout 60m
cd test; go clean -testcache; ./test.sh
26 changes: 3 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
# Terraform GCP SQL Module

Use this repository as a starting point for building a [Terraform Component Module](https://www.notion.so/honestbank/WIP-How-to-structure-a-Terraform-module-31374a1594f84ef7b185ef4e06b36619).
This repository/module builds a [Google Cloud SQL](https://cloud.google.com/sql) instance and related resources.

The recommended usage is to make this a public [Trunk-Based Development](https://trunkbaseddevelopment.com) repo that
automatically releases using SemVer on merge to trunk (typically called `main`). This module is then embedded and
instantiated by Layer Modules to manage live infrastructure.
This module is designed to be embedded into parent modules to be used to manage live infrastructure.

## Prerequisite
## Prerequisites

### Configure a Service Account

Expand All @@ -30,24 +28,6 @@ In order to use Private Service Access, required for using Private IPs, you must
- Service Networking API: `servicenetworking.googleapis.com`
- Cloud Resource Manager API: `cloudresourcemanager.googleapis.com`

## Customizations

### Pre-commit

This template contains a [.pre-commit-config.yaml file](./.pre-commit-config.yaml). To use this, please [install pre-commit](https://pre-commit.com/#install)
and run `pre-commit install` to install hooks. The default set of hooks should work for most Terraform modules/repos - please
customize as needed.

### Releases

This template contains a [semantic-release](https://github.com/semantic-release/semantic-release) [configuration file](./release.config.js)
that is configured to produce releases on merge to `main`.

### GitHub Actions

This template contains [a 'terraform' action/workflow](./.github/workflows/terraform.yml) that is configured to run on
PRs and pushes to `main` and is designed around a [Trunk-Based Development](https://trunkbaseddevelopment.com) workflow.

<!-- BEGIN_TF_DOCS -->
## Requirements

Expand Down
2 changes: 1 addition & 1 deletion modules/google_compute_global_address/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

| Name | Version |
|------|---------|
| <a name="provider_google"></a> [google](#provider\_google) | 4.55.0 |
| <a name="provider_google"></a> [google](#provider\_google) | ~> 4.0 |

## Modules

Expand Down
2 changes: 1 addition & 1 deletion modules/google_compute_network/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

| Name | Version |
|------|---------|
| <a name="provider_google"></a> [google](#provider\_google) | 4.55.0 |
| <a name="provider_google"></a> [google](#provider\_google) | ~> 4.0 |

## Modules

Expand Down
2 changes: 1 addition & 1 deletion modules/google_service_networking_connection/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

| Name | Version |
|------|---------|
| <a name="provider_google"></a> [google](#provider\_google) | 4.55.0 |
| <a name="provider_google"></a> [google](#provider\_google) | ~> 4.0 |

## Modules

Expand Down
2 changes: 1 addition & 1 deletion modules/google_sql_database/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

| Name | Version |
|------|---------|
| <a name="provider_google"></a> [google](#provider\_google) | 4.55.0 |
| <a name="provider_google"></a> [google](#provider\_google) | ~> 4.0 |

## Modules

Expand Down
2 changes: 1 addition & 1 deletion modules/google_sql_database_instance/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

| Name | Version |
|------|---------|
| <a name="provider_google"></a> [google](#provider\_google) | 4.55.0 |
| <a name="provider_google"></a> [google](#provider\_google) | ~> 4.0 |

## Modules

Expand Down
2 changes: 1 addition & 1 deletion modules/google_sql_user/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

| Name | Version |
|------|---------|
| <a name="provider_google"></a> [google](#provider\_google) | 4.55.0 |
| <a name="provider_google"></a> [google](#provider\_google) | ~> 4.0 |

## Modules

Expand Down
41 changes: 7 additions & 34 deletions test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,47 +3,20 @@
This package uses [Terratest](https://terratest.gruntwork.io) for automatic/E2E
testing.

To run tests, first export the needed env vars - values below are examples:
To run tests, first export the needed Terraform variables using the `TF_VAR` environment variable
syntax:

```bash
export TF_VAR_google_credentials=$(cat compute.json)
export TF_VAR_shared_vpc_host_google_credentials=$(cat vpc.json)
```shell
...
export TF_VAR_<TERRAFORM_VARIABLE_NAME>="VALUE"
...
```

Then run the tests:

```bash
go test -v -timeout 60m
go test -v -timeout 150m
```

Tests should always be performed in a separate project (and a separate account,
if possible) to completely isolate live environments from any potential issues.

## Running in a Docker image

Spin up an Ubuntu docker image from the root of the repo:

```bash
docker run -it -u 0 -v $(pwd):/terraform-test govindani/honest_terraform:0.15 /bin/bash
docker run -it -u 0 -v $(pwd):/terraform-test ubuntu /bin/bash
```

### Install Prerequisites

See [prepare-test-environment.sh](./prepare-test-environment.sh) for requirements.
Or just `source` the script 😊

### Run Tests

```bash
go test -v -timeout 30m
```

## Manual Cleanup

If the test fails and doesn't clean up after itself properly, you'll want to clean out:

* External IP address in the VPC project
* Cloud Router in the VPC project
* Firewall policies in the VPC project
* GKE cluster in the Compute project
2 changes: 1 addition & 1 deletion test/test.sh
Original file line number Diff line number Diff line change
@@ -1 +1 @@
go test -v -timeout 90m
go test -v -timeout 150m

0 comments on commit 9cbd462

Please sign in to comment.