Skip to content
This repository has been archived by the owner on Mar 29, 2023. It is now read-only.

Commit

Permalink
Merge pull request #104 from gruntwork-io/tf13
Browse files Browse the repository at this point in the history
Update repo to work with Terraform 0.13.x
  • Loading branch information
robmorgan authored Nov 24, 2020
2 parents cc12ff4 + fbf2b0d commit 0403a93
Show file tree
Hide file tree
Showing 11 changed files with 262 additions and 174 deletions.
192 changes: 95 additions & 97 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,127 +1,125 @@
version: 2.1

defaults: &defaults
machine: true

env: &env
environment:
GRUNTWORK_INSTALLER_VERSION: v0.0.23
TERRATEST_LOG_PARSER_VERSION: v0.13.13
HELM_VERSION: v3.1.2
MODULE_CI_VERSION: v0.18.4
TERRAFORM_VERSION: 0.12.20
GRUNTWORK_INSTALLER_VERSION: v0.0.30
TERRATEST_LOG_PARSER_VERSION: v0.30.4
MODULE_CI_VERSION: v0.29.1
TERRAFORM_VERSION: 0.13.5
TERRAGRUNT_VERSION: NONE
PACKER_VERSION: NONE
GOLANG_VERSION: 1.13.8
HELM_VERSION: v3.1.2
K8S_VERSION: v1.10.0
KUBECONFIG: /home/circleci/.kube/config

install_gruntwork_utils: &install_gruntwork_utils
name: install gruntwork utils
command: |
curl -Ls https://raw.githubusercontent.com/gruntwork-io/gruntwork-installer/master/bootstrap-gruntwork-installer.sh | bash /dev/stdin --version "${GRUNTWORK_INSTALLER_VERSION}"
gruntwork-install --module-name "gruntwork-module-circleci-helpers" --repo "https://github.com/gruntwork-io/module-ci" --tag "${MODULE_CI_VERSION}"
gruntwork-install --binary-name "terratest_log_parser" --repo "https://github.com/gruntwork-io/terratest" --tag "${TERRATEST_LOG_PARSER_VERSION}"
configure-environment-for-gruntwork-module \
--terraform-version ${TERRAFORM_VERSION} \
--terragrunt-version ${TERRAGRUNT_VERSION} \
--packer-version ${PACKER_VERSION} \
--go-version ${GOLANG_VERSION} \
--go-src-path ./test/
install_helm_client: &install_helm_client
name: install helm client
command: |
# install helm client
curl -Lo helm.tar.gz https://get.helm.sh/helm-${HELM_VERSION}-linux-amd64.tar.gz
tar -xvf helm.tar.gz
chmod +x linux-amd64/helm
sudo mv linux-amd64/helm /usr/local/bin/
version: 2
jobs:
build:
<<: *defaults
precommit:
<<: *env
docker:
- image: circleci/python:3.8.1
steps:
- checkout
- restore_cache:
keys:
- gomod-{{ checksum "test/go.sum" }}

# Install gruntwork utilities
- run:
<<: *install_gruntwork_utils

- save_cache:
key: gomod-{{ checksum "test/go.sum" }}
paths:
- $HOME/go/src/

name: install dependencies
command: |
curl -Ls https://raw.githubusercontent.com/gruntwork-io/gruntwork-installer/master/bootstrap-gruntwork-installer.sh | bash /dev/stdin --version "${GRUNTWORK_INSTALLER_VERSION}"
gruntwork-install --module-name "gruntwork-module-circleci-helpers" --repo "https://github.com/gruntwork-io/module-ci" --tag "${MODULE_CI_VERSION}"
configure-environment-for-gruntwork-module \
--terraform-version ${TERRAFORM_VERSION} \
--terragrunt-version NONE \
--packer-version NONE \
--go-version ${GOLANG_VERSION}
# Fail the build if the pre-commit hooks don't pass. Note: if you run pre-commit install locally, these hooks will
# execute automatically every time before you commit, ensuring the build never fails at this step!
- run:
name: run pre-commit hooks
command: |
pyenv global 3.5.2
pip install pre-commit==1.21.0 cfgv==2.0.1
pip install pre-commit==1.21.0 cfgv==2.0.1 zipp==1.1.0 yapf
pre-commit install
pre-commit run --all-files
- persist_to_workspace:
root: /home/circleci
paths:
- project
- terraform
- packer

test:
<<: *defaults
<<: *env
steps:
- attach_workspace:
at: /home/circleci
- checkout
- run: echo 'export PATH=$HOME/terraform:$HOME/packer:$PATH' >> $BASH_ENV
- run:
<<: *install_gruntwork_utils
- checkout
- run: &install_gruntwork_tooling
name: install gruntwork tooling
command: |
sudo apt-get -y update
curl -Ls https://raw.githubusercontent.com/gruntwork-io/gruntwork-installer/master/bootstrap-gruntwork-installer.sh | bash /dev/stdin --version "${GRUNTWORK_INSTALLER_VERSION}"
gruntwork-install --module-name "gruntwork-module-circleci-helpers" --repo "https://github.com/gruntwork-io/module-ci" --tag "${MODULE_CI_VERSION}"
gruntwork-install --module-name "git-helpers" --repo "https://github.com/gruntwork-io/module-ci" --tag "${MODULE_CI_VERSION}"
gruntwork-install --binary-name "terratest_log_parser" --repo "https://github.com/gruntwork-io/terratest" --tag "${TERRATEST_LOG_PARSER_VERSION}"
configure-environment-for-gruntwork-module --go-src-path ./test --terraform-version ${TERRAFORM_VERSION} --terragrunt-version ${TERRAGRUNT_VERSION} --packer-version ${PACKER_VERSION} --go-version ${GOLANG_VERSION}
# Install helm
- run:
<<: *install_helm_client
- run:
name: install helm client
command: |
# install helm client
curl -Lo helm.tar.gz https://get.helm.sh/helm-${HELM_VERSION}-linux-amd64.tar.gz
tar -xvf helm.tar.gz
chmod +x linux-amd64/helm
sudo mv linux-amd64/helm /usr/local/bin/
- run:
name: update gcloud
command: |
sudo apt-get remove -y google-cloud-sdk
sudo /opt/google-cloud-sdk/bin/gcloud --quiet components update
sudo /opt/google-cloud-sdk/bin/gcloud --quiet components update beta kubectl
- run:
name: configure kubectl
command: |
mkdir -p ${HOME}/.kube
touch ${HOME}/.kube/config
- run:
name: run tests
command: |
mkdir -p /tmp/logs
# required for gcloud and kubectl to authenticate correctly
echo $GCLOUD_SERVICE_KEY | gcloud auth activate-service-account --key-file=-
gcloud --quiet config set project ${GOOGLE_PROJECT_ID}
gcloud --quiet config set compute/zone ${GOOGLE_COMPUTE_ZONE}
# required for terraform and terratest to authenticate correctly
echo $GCLOUD_SERVICE_KEY > /tmp/gcloud.json
export GOOGLE_APPLICATION_CREDENTIALS="/tmp/gcloud.json"
# run the tests
run-go-tests --path test --timeout 60m | tee /tmp/logs/all.log
no_output_timeout: 3600s
- run:
command: terratest_log_parser --testlog /tmp/logs/all.log --outputdir /tmp/logs
when: always
- store_artifacts:
path: /tmp/logs
- store_test_results:
path: /tmp/logs
# Install external dependencies
- run:
name: update gcloud
command: |
sudo apt-get remove -y google-cloud-sdk
sudo /opt/google-cloud-sdk/bin/gcloud --quiet components update
sudo /opt/google-cloud-sdk/bin/gcloud --quiet components update beta kubectl
- run:
name: configure kubectl
command: |
mkdir -p ${HOME}/.kube
touch ${HOME}/.kube/config
- run:
name: run tests
command: |
# required for gcloud and kubectl to authenticate correctly
echo $GCLOUD_SERVICE_KEY | gcloud auth activate-service-account --key-file=-
gcloud --quiet config set project ${GOOGLE_PROJECT_ID}
gcloud --quiet config set compute/zone ${GOOGLE_COMPUTE_ZONE}
# required for terraform and terratest to authenticate correctly
echo $GCLOUD_SERVICE_KEY > /tmp/gcloud.json
export GOOGLE_APPLICATION_CREDENTIALS="/tmp/gcloud.json"
# run the tests
mkdir -p /tmp/logs
run-go-tests --path test --timeout 2h | tee /tmp/logs/all.log
no_output_timeout: 1h

- run:
name: parse test output
command: terratest_log_parser --testlog /tmp/logs/all.log --outputdir /tmp/logs
when: always

- store_artifacts:
path: /tmp/logs
- store_test_results:
path: /tmp/logs

workflows:
version: 2
build-and-test:
test:
jobs:
- build
- test:
requires:
- build
# We have to explicitly tell CircleCI to run on all tags and branches, or tag commits/pushes will not trigger
# builds: https://circleci.com/docs/2.0/workflows/#git-tag-job-execution.
- precommit:
filters:
branches:
only: /.*/
tags:
only: /.*/
- test:
requires:
- precommit
filters:
tags:
only: /^v.*/
3 changes: 2 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
repos:
- repo: https://github.com/gruntwork-io/pre-commit
sha: v0.0.2
rev: v0.1.10
hooks:
- id: terraform-fmt
- id: gofmt

26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[![Maintained by Gruntwork.io](https://img.shields.io/badge/maintained%20by-gruntwork.io-%235849a6.svg)](https://gruntwork.io/?ref=repo_google_gke)
[![GitHub tag (latest SemVer)](https://img.shields.io/github/tag/gruntwork-io/terraform-google-gke.svg?label=latest)](https://github.com/gruntwork-io/terraform-google-gke/releases/latest)
![Terraform Version](https://img.shields.io/badge/tf-%3E%3D0.12.0-blue.svg)
![Terraform Version](https://img.shields.io/badge/tf-%3E%3D0.13.0-blue.svg)

# Google Kubernetes Engine (GKE) Module

Expand All @@ -17,28 +17,28 @@ for instructions.

This repo has the following folder structure:

* [root](https://github.com/gruntwork-io/terraform-google-gke/tree/master): The root folder contains an example of how
- [root](https://github.com/gruntwork-io/terraform-google-gke/tree/master): The root folder contains an example of how
to deploy a GKE Public Cluster with and an example chart with [Helm](https://helm.sh/). See [gke-basic-helm](https://github.com/gruntwork-io/terraform-google-gke/blob/master/examples/gke-basic-helm)
for the documentation.

* [modules](https://github.com/gruntwork-io/terraform-google-gke/tree/master/modules): This folder contains the
- [modules](https://github.com/gruntwork-io/terraform-google-gke/tree/master/modules): This folder contains the
main implementation code for this Module, broken down into multiple standalone submodules.

The primary module is:

* [gke-cluster](https://github.com/gruntwork-io/terraform-google-gke/tree/master/modules/gke-cluster): The GKE Cluster module is used to
- [gke-cluster](https://github.com/gruntwork-io/terraform-google-gke/tree/master/modules/gke-cluster): The GKE Cluster module is used to
administer the [cluster master](https://cloud.google.com/kubernetes-engine/docs/concepts/cluster-architecture)
for a [GKE Cluster](https://cloud.google.com/kubernetes-engine/docs/how-to/cluster-admin-overview).

There are also several supporting modules that add extra functionality on top of `gke-cluster`:
There are also several supporting modules that add extra functionality on top of `gke-cluster`:

* [gke-service-account](https://github.com/gruntwork-io/terraform-google-gke/tree/master/modules/gke-service-account):
- [gke-service-account](https://github.com/gruntwork-io/terraform-google-gke/tree/master/modules/gke-service-account):
Used to configure a GCP service account for use with a GKE cluster.

* [examples](https://github.com/gruntwork-io/terraform-google-gke/tree/master/examples): This folder contains
- [examples](https://github.com/gruntwork-io/terraform-google-gke/tree/master/examples): This folder contains
examples of how to use the submodules.

* [test](https://github.com/gruntwork-io/terraform-google-gke/tree/master/test): Automated tests for the submodules
- [test](https://github.com/gruntwork-io/terraform-google-gke/tree/master/test): Automated tests for the submodules
and examples.

## What is Kubernetes?
Expand Down Expand Up @@ -104,11 +104,11 @@ commercial support, send an email to

Gruntwork can help with:

* Setup, customization, and support for this Module.
* Modules and submodules for other types of infrastructure, such as VPCs, Docker clusters, databases, and continuous
- Setup, customization, and support for this Module.
- Modules and submodules for other types of infrastructure, such as VPCs, Docker clusters, databases, and continuous
integration.
* Modules and Submodules that meet compliance requirements, such as HIPAA.
* Consulting & Training on AWS, Terraform, and DevOps.
- Modules and Submodules that meet compliance requirements, such as HIPAA.
- Consulting & Training on AWS, Terraform, and DevOps.

## How do I contribute to this Module?

Expand All @@ -129,4 +129,4 @@ MINOR, and PATCH versions on each release to indicate any incompatibilities.
Please see [LICENSE](https://github.com/gruntwork-io/terraform-google-gke/blob/master/LICENSE) for how the code in this
repo is licensed.

Copyright &copy; 2019 Gruntwork, Inc.
Copyright &copy; 2020 Gruntwork, Inc.
6 changes: 3 additions & 3 deletions examples/gke-basic-helm/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# GKE Basic Helm Example

The root folder contains an example of how to deploy a GKE Public Cluster with an example chart
with [Helm](https://helm.sh/).
The root folder contains an example of how to deploy a GKE Public Cluster with an example chart
using [Helm](https://helm.sh/).

## Overview

Expand Down Expand Up @@ -54,7 +54,7 @@ So let's verify that in the next step!

## Verify the Deployed Chart

The example configures your `kubectl` context, so you can use `kubectl` and `helm` commands without further configuration.
The example configures your `kubectl` context, so you can use `kubectl` and `helm` commands without further configuration.

To see the created resources, run the following commands:

Expand Down
13 changes: 7 additions & 6 deletions examples/gke-private-cluster/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,24 @@
# ---------------------------------------------------------------------------------------------------------------------

terraform {
# The modules used in this example have been updated with 0.12 syntax, additionally we depend on a bug fixed in
# version 0.12.7.
required_version = ">= 0.12.7"
# This module is now only being tested with Terraform 0.13.x. However, to make upgrading easier, we are setting
# 0.12.26 as the minimum version, as that version added support for required_providers with source URLs, making it
# forwards compatible with 0.13.x code.
required_version = ">= 0.12.26"
}

# ---------------------------------------------------------------------------------------------------------------------
# PREPARE PROVIDERS
# ---------------------------------------------------------------------------------------------------------------------

provider "google" {
version = "~> 2.9.0"
version = "~> 3.43.0"
project = var.project
region = var.region
}

provider "google-beta" {
version = "~> 2.9.0"
version = "~> 3.43.0"
project = var.project
region = var.region
}
Expand Down Expand Up @@ -158,7 +159,7 @@ module "gke_service_account" {
# ---------------------------------------------------------------------------------------------------------------------

module "vpc_network" {
source = "github.com/gruntwork-io/terraform-google-network.git//modules/vpc-network?ref=v0.2.1"
source = "github.com/gruntwork-io/terraform-google-network.git//modules/vpc-network?ref=v0.6.0"

name_prefix = "${var.cluster_name}-network-${random_string.suffix.result}"
project = var.project
Expand Down
13 changes: 7 additions & 6 deletions examples/gke-public-cluster/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,24 @@
# ---------------------------------------------------------------------------------------------------------------------

terraform {
# The modules used in this example have been updated with 0.12 syntax, additionally we depend on a bug fixed in
# version 0.12.7.
required_version = ">= 0.12.7"
# This module is now only being tested with Terraform 0.13.x. However, to make upgrading easier, we are setting
# 0.12.26 as the minimum version, as that version added support for required_providers with source URLs, making it
# forwards compatible with 0.13.x code.
required_version = ">= 0.12.26"
}

# ---------------------------------------------------------------------------------------------------------------------
# PREPARE PROVIDERS
# ---------------------------------------------------------------------------------------------------------------------

provider "google" {
version = "~> 2.9.0"
version = "~> 3.43.0"
project = var.project
region = var.region
}

provider "google-beta" {
version = "~> 2.9.0"
version = "~> 3.43.0"
project = var.project
region = var.region
}
Expand Down Expand Up @@ -145,7 +146,7 @@ resource "random_string" "suffix" {
}

module "vpc_network" {
source = "github.com/gruntwork-io/terraform-google-network.git//modules/vpc-network?ref=v0.2.1"
source = "github.com/gruntwork-io/terraform-google-network.git//modules/vpc-network?ref=v0.6.0"

name_prefix = "${var.cluster_name}-network-${random_string.suffix.result}"
project = var.project
Expand Down
Loading

0 comments on commit 0403a93

Please sign in to comment.