Skip to content

BrownUniversity/terraform-gcp-vpc

Repository files navigation

terraform-gcp-vpc

kitchen-tests

Terraform module for creating a VPC in GCP. Basic features:

Getting Started

This module depends on you having GCP credentials of some kind. The module looks for a credential file in JSON format. You should export the following:

GOOGLE_APPLICATION_CREDENTIALS=/path/to/file.json

How to use this module

This repository defines a Terraform module, which you can use in your code by adding a module configuration and setting its source parameter to URL of this repository. See the examples folder for guidance

Requirements

Name Version
terraform >= 1.9.0
google 5.38.0

Providers

No providers.

Modules

Name Source Version
vpc terraform-google-modules/network/google 9.1.0

Resources

No resources.

Inputs

Name Description Type Default Required
description Subnet description string "Deployed through Terraform." no
ip_range_pods The secondary ip range to use for pods string "192.168.0.0/18" no
ip_range_services The secondary ip range to use for pods string "192.168.64.0/18" no
network_name Name of the VPC. string n/a yes
project_id The project ID to host the VPC in string n/a yes
range_name_pods The range name for pods string "kubernetes-pods" no
range_name_services The range name for services string "kubernetes-services" no
routing_mode Routing mode. GLOBAL or REGIONAL string "GLOBAL" no
subnet_flow_logs Whether to enable flow logging for the subnetwork. string "true" no
subnet_ip Subnet IP CIDR. string "10.0.0.0/17" no
subnet_name Name of the subnet. string n/a yes
subnet_private_access Enable private Google access string "true" no
subnet_region Region subnet lives in. string n/a yes

Outputs

Name Description
network_name Name of the VPC.
routing_mode Routing mode. GLOBAL or REGIONAL
subnet_ip Subnet IP
subnet_name Name of the subnetwok.

Local Development

Merging Policy

Use GitLab Flow.

  • Create feature branches for features and fixes from default branch
  • Merge only from PR with review
  • After merging to default branch a release is drafted using a github action. Check the draft and publish if you and tests are happy

Version managers

We recommend using asdf to manage your versions of Terrafom and Ruby.

brew install asdf

Terraform

You can also install the latest version of terraform version via brew.

brew tap hashicorp/tap
brew install hashicorp/tap/terraform

Pre-commit hooks

You should make sure that pre-commit hooks are installed to run the formater, linter, etc. Install and configure terraform pre-commit hooks as follows:

Install rependencies

brew bundle install

Install the pre-commit hook globally

DIR=~/.git-template
git config --global init.templateDir ${DIR}
pre-commit init-templatedir -t pre-commit ${DIR}

To run the hooks specified in .pre-commit-config.yaml:

pre-commit run -a

GCloud

This is only needed if running tests locally. The google-cloud-sdk is included in the Brewfile so it should now be installed This repo includes a env.sh file that where you set the path to the google credentials file, then use

source env.sh

and

deactivate

to set and uset the GOOGLE_APPLICATION_CREDENTIALS variable.

Testing

The tests can be run locally with terraform test after running terraform init. You will need to supply org_id, folder_id, and billing_account variables through terraform.tfvars file. Please see terraform.tfvars.example file for an example.

CI

This project has three workflows enabled:

  1. PR labeler: When opening a PR to default branch, a label is given assigned automatically according to the name of your feature branch. The labeler follows the follows rules in pr-labeler.yml

  2. Release Drafter: When merging to master, a release is drafted using the Release-Drafter Action

  3. terraform test runs on PR, merge to main and releases.