Skip to content

Commit

Permalink
Added support for Terrafrom 0.12
Browse files Browse the repository at this point in the history
- Migrated to terraform 0.12 syntax
- Added variables type validation.
- Added provider version restriction.
- Added/upgraded helper functions
- Replaced MD markers for doc generator, removed old script
- Bumbed version, updaed CHANGELOG and README
- Upgraded tf validator and md doc generator fucntions to latest versions.
- Added versions.tf with restriction to TF 0.12
- Fixed linters calls, Makefile and linters bug reported in #5
- Fixed broken docker image variables reported in #6
- Upgraded to new docker image
- Fixed `make create | converge | verify | dsetroy` calls  reported in #8
- Removed docker checks which are now deprecated as well as [hadolint issue](terraform-google-modules/terraform-google-project-factory#252)
  • Loading branch information
ivankorn committed Jul 31, 2019
1 parent 56aacc3 commit c9aa385
Show file tree
Hide file tree
Showing 20 changed files with 1,047 additions and 246 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,14 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this
project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

## [0.2.0] 2019-YY-ZZ

### Changed
- Supported version of Terraform is 0.12. [#10]

## [0.1.0]
### ADDED
- Initial module release with basic functionality.

[#10]: https://github.com/terraform-google-modules/terraform-google-memorystore/pull/10
90 changes: 34 additions & 56 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,12 @@
SHELL := /usr/bin/env bash

# Docker build config variables
BUILD_TERRAFORM_VERSION ?= 0.11.10
BUILD_CLOUD_SDK_VERSION ?= 216.0.0
BUILD_PROVIDER_GOOGLE_VERSION ?= 1.19.1
BUILD_PROVIDER_GSUITE_VERSION ?= 0.1.10
DOCKER_IMAGE_TERRAFORM := cftk/terraform
DOCKER_TAG_TERRAFORM ?= ${BUILD_TERRAFORM_VERSION}_${BUILD_CLOUD_SDK_VERSION}_${BUILD_PROVIDER_GOOGLE_VERSION}_${BUILD_PROVIDER_GSUITE_VERSION}
BUILD_RUBY_VERSION ?= 2.5.3
DOCKER_IMAGE_KITCHEN_TERRAFORM := cftk/kitchen_terraform
DOCKER_TAG_KITCHEN_TERRAFORM ?= ${BUILD_TERRAFORM_VERSION}_${BUILD_CLOUD_SDK_VERSION}_${BUILD_PROVIDER_GOOGLE_VERSION}_${BUILD_PROVIDER_GSUITE_VERSION}
CREDENTIALS_PATH ?= /cft/workdir/credentials.json
DOCKER_ORG := gcr.io/cloud-foundation-cicd
DOCKER_TAG_BASE_KITCHEN_TERRAFORM ?= 2.3.0
DOCKER_REPO_BASE_KITCHEN_TERRAFORM := ${DOCKER_ORG}/cft/kitchen-terraform:${DOCKER_TAG_BASE_KITCHEN_TERRAFORM}


all: check_shell check_python check_golang check_terraform check_docker check_base_files test_check_headers check_headers check_trailing_whitespace generate_docs ## Run all linters and update documentation
all: check_shell check_python check_golang check_terraform test_check_headers check_headers check_trailing_whitespace generate_docs ## Run all linters and update documentation

# The .PHONY directive tells make that this isn't a real target and so
# the presence of a file named 'check_shell' won't cause this target to stop
Expand All @@ -45,16 +39,8 @@ check_golang: ## Lint Go source files
@source test/make.sh && golang

.PHONY: check_terraform
check_terraform:
@source ## Lint Terraform source files

.PHONY: check_docker
check_docker: ## Lint Dockerfiles
@source test/make.sh && docker

.PHONY: check_base_files
check_base_files:
@source test/make.sh && basefiles
check_terraform: ## Lint Terraform source files
@source test/make.sh && check_terraform

.PHONY: check_shebangs
check_shebangs: ## Check that scripts have correct shebangs
Expand All @@ -67,12 +53,11 @@ check_trailing_whitespace:
.PHONY: test_check_headers
test_check_headers:
@echo "Testing the validity of the header check"
@python test/test_verify_boilerplate.py
@source test/make.sh && check_headers

.PHONY: check_headers
check_headers: ## Check that source files have appropriate boilerplate
@echo "Checking file headers"
@python test/verify_boilerplate.py
@source test/make.sh && check_headers

# Integration tests
.PHONY: test_integration
Expand All @@ -88,62 +73,55 @@ test_integration: ## Run integration tests
generate_docs: ## Update README documentation for Terraform variables and outputs
@source test/make.sh && generate_docs

# Versioning
.PHONY: version
version:
@source helpers/version-repo.sh

# Build Docker
.PHONY: docker_build_terraform
docker_build_terraform:
docker build -f build/docker/terraform/Dockerfile \
--build-arg BUILD_TERRAFORM_VERSION=${BUILD_TERRAFORM_VERSION} \
--build-arg BUILD_CLOUD_SDK_VERSION=${BUILD_CLOUD_SDK_VERSION} \
--build-arg BUILD_PROVIDER_GOOGLE_VERSION=${BUILD_PROVIDER_GOOGLE_VERSION} \
--build-arg BUILD_PROVIDER_GSUITE_VERSION=${BUILD_PROVIDER_GSUITE_VERSION} \
-t ${DOCKER_IMAGE_TERRAFORM}:${DOCKER_TAG_TERRAFORM} .

.PHONY: docker_build_kitchen_terraform
docker_build_kitchen_terraform:
docker build -f build/docker/kitchen_terraform/Dockerfile \
--build-arg BUILD_TERRAFORM_IMAGE="${DOCKER_IMAGE_TERRAFORM}:${DOCKER_TAG_TERRAFORM}" \
--build-arg BUILD_RUBY_VERSION="${BUILD_RUBY_VERSION}" \
-t ${DOCKER_IMAGE_KITCHEN_TERRAFORM}:${DOCKER_TAG_KITCHEN_TERRAFORM} .

# Run docker
.PHONY: docker_run
docker_run: ## Launch a shell within the Docker test environment
docker run --rm -it \
-v $(CURDIR):/cftk/workdir \
${DOCKER_IMAGE_KITCHEN_TERRAFORM}:${DOCKER_TAG_KITCHEN_TERRAFORM} \
-e SERVICE_ACCOUNT_JSON \
-e CLOUDSDK_AUTH_CREDENTIAL_FILE_OVERRIDE=${CREDENTIALS_PATH} \
-e GOOGLE_APPLICATION_CREDENTIALS=${CREDENTIALS_PATH} \
-v $(CURDIR):/cft/workdir \
${DOCKER_REPO_BASE_KITCHEN_TERRAFORM} \
/bin/bash

.PHONY: docker_create
docker_create: ## Run `kitchen create` within the Docker test environment
docker run --rm -it \
-v $(CURDIR):/cftk/workdir \
${DOCKER_IMAGE_KITCHEN_TERRAFORM}:${DOCKER_TAG_KITCHEN_TERRAFORM} \
-e SERVICE_ACCOUNT_JSON \
-e CLOUDSDK_AUTH_CREDENTIAL_FILE_OVERRIDE=${CREDENTIALS_PATH} \
-e GOOGLE_APPLICATION_CREDENTIALS=${CREDENTIALS_PATH} \
-v $(CURDIR):/cft/workdir \
${DOCKER_REPO_BASE_KITCHEN_TERRAFORM} \
/bin/bash -c "kitchen create"

.PHONY: docker_converge
docker_converge: ## Run `kitchen converge` within the Docker test environment
docker run --rm -it \
-v $(CURDIR):/cftk/workdir \
${DOCKER_IMAGE_KITCHEN_TERRAFORM}:${DOCKER_TAG_KITCHEN_TERRAFORM} \
-e SERVICE_ACCOUNT_JSON \
-e CLOUDSDK_AUTH_CREDENTIAL_FILE_OVERRIDE=${CREDENTIALS_PATH} \
-e GOOGLE_APPLICATION_CREDENTIALS=${CREDENTIALS_PATH} \
-v $(CURDIR):/cft/workdir \
${DOCKER_REPO_BASE_KITCHEN_TERRAFORM} \
/bin/bash -c "kitchen converge && kitchen converge"

.PHONY: docker_verify
docker_verify: ## Run `kitchen verify` within the Docker test environment
docker run --rm -it \
-v $(CURDIR):/cftk/workdir \
${DOCKER_IMAGE_KITCHEN_TERRAFORM}:${DOCKER_TAG_KITCHEN_TERRAFORM} \
-e SERVICE_ACCOUNT_JSON \
-e CLOUDSDK_AUTH_CREDENTIAL_FILE_OVERRIDE=${CREDENTIALS_PATH} \
-e GOOGLE_APPLICATION_CREDENTIALS=${CREDENTIALS_PATH} \
-v $(CURDIR):/cft/workdir \
${DOCKER_REPO_BASE_KITCHEN_TERRAFORM} \
/bin/bash -c "kitchen verify"

.PHONY: docker_destroy
docker_destroy: ## Run `kitchen destroy` within the Docker test environment
docker run --rm -it \
-v $(CURDIR):/cftk/workdir \
${DOCKER_IMAGE_KITCHEN_TERRAFORM}:${DOCKER_TAG_KITCHEN_TERRAFORM} \
-e SERVICE_ACCOUNT_JSON \
-e CLOUDSDK_AUTH_CREDENTIAL_FILE_OVERRIDE=${CREDENTIALS_PATH} \
-e GOOGLE_APPLICATION_CREDENTIALS=${CREDENTIALS_PATH} \
-v $(CURDIR):/cft/workdir \
${DOCKER_REPO_BASE_KITCHEN_TERRAFORM} \
/bin/bash -c "kitchen destroy"

.PHONY: test_integration_docker
Expand Down
41 changes: 25 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

A Terraform module for creating a fully functional Google Memorystore (redis) instance.

## Compatibility
This module is meant for use with Terraform 0.12. If you haven't [upgraded](https://www.terraform.io/upgrade-guides/0-12.html) and need a Terraform 0.11.x-compatible version of this module, the last released version intended for Terraform 0.11.x
is [0.1.0](https://registry.terraform.io/modules/terraform-google-modules/memorystore/google/0.1.0).

## Usage

Check the [examples/](./examples/) directory for more.
Expand All @@ -16,25 +20,24 @@ module "memorystore" {
}
```

[^]: (autogen_docs_start)

<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|:----:|:-----:|:-----:|
| alternative\_location\_id | The alternative zone where the instance will be provisioned. | string | `` | no |
| authorized\_network | The name of the memorystore authorized network. | string | `` | no |
| display\_name | An arbitrary and optional user-provided name for the instance. | string | `` | no |
| enable\_apis | Enable required APIs for Cloud Memorystore. | string | `true` | no |
| labels | The resource labels to represent user provided metadata. | map | `<map>` | no |
| location\_id | The zone where the instance will be provisioned. | string | `` | no |
| memory\_size\_gb | Redis memory size in GiB. | string | - | yes |
| name | The ID of the instance or a fully qualified identifier for the instance. | string | - | yes |
| project | The ID of the project in which the resource belongs to. | string | - | yes |
| redis\_version | The version of Redis software. | string | `` | no |
| region | The GCP region to use. | string | `` | no |
| reserved\_ip\_range | The CIDR range of internal addresses that are reserved for this instance. | string | `` | no |
| tier | The service tier of the instance. | string | `STANDARD_HA` | no |
| alternative\_location\_id | The alternative zone where the instance will be provisioned. | string | `"null"` | no |
| authorized\_network | The full name of the Google Compute Engine network to which the instance is connected. If left unspecified, the default network will be used. | string | `"null"` | no |
| display\_name | An arbitrary and optional user-provided name for the instance. | string | `"null"` | no |
| enable\_apis | Enable required APIs for Cloud Memorystore. | bool | `"true"` | no |
| labels | The resource labels to represent user provided metadata. | object | `<map>` | no |
| location\_id | The zone where the instance will be provisioned. If not provided, the service will choose a zone for the instance. For STANDARD_HA tier, instances will be created across two zones for protection against zonal failures. If [alternativeLocationId] is also provided, it must be different from [locationId]. | string | `"null"` | no |
| memory\_size\_gb | Redis memory size in GiB. Defaulted to 1 GiB | number | `"1"` | no |
| name | The ID of the instance or a fully qualified identifier for the instance. | string | n/a | yes |
| project | The ID of the project in which the resource belongs to. | string | n/a | yes |
| redis\_version | The version of Redis software. | string | `"null"` | no |
| region | The GCP region to use. | string | `"null"` | no |
| reserved\_ip\_range | The CIDR range of internal addresses that are reserved for this instance. | string | `"null"` | no |
| tier | The service tier of the instance. https://cloud.google.com/memorystore/docs/redis/reference/rest/v1/projects.locations.instances#Tier | string | `"STANDARD_HA"` | no |

## Outputs

Expand All @@ -45,7 +48,7 @@ module "memorystore" {
| id | The memorystore instance ID. |
| region | The region the instance lives in. |

[^]: (autogen_docs_end)
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

## File structure

Expand All @@ -65,11 +68,17 @@ The project has the following folders and files:

### Requirements

- Terraform is [installed](#software-dependencies) on the machine where Terraform is executed.
- An existing google cloud project
- The `redis.googleapis.com` API should be enabled
- A service account key
- Docker

### Software Dependencies
### Terraform
- [Terraform](https://www.terraform.io/downloads.html) >= 0.12.0
- [terraform-provider-google](https://github.com/terraform-providers/terraform-provider-google) >= v2.5.0

### Running Integration Tests

Tests are run inside of an existing google cloud project.
Expand Down
9 changes: 5 additions & 4 deletions examples/basic/memorystore.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2018 Google LLC
* Copyright 2019 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,7 +15,8 @@
*/

module "memorystore" {
source = "git::ssh://git@github.com/terraform-google-modules/terraform-google-memorystore"
name = "memorystore"
project = "memorystore"
source = "git::ssh://git@github.com/terraform-google-modules/terraform-google-memorystore"
name = "memorystore"
project = "memorystore"
memory_size_gb = "1"
}
19 changes: 19 additions & 0 deletions examples/basic/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Copyright 2019 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

terraform {
required_version = ">= 0.12"
}
47 changes: 0 additions & 47 deletions helpers/combine_docfiles.py

This file was deleted.

Loading

0 comments on commit c9aa385

Please sign in to comment.