Skip to content

Commit

Permalink
Merge pull request #11 from bohdanyurov-gl/fix/9
Browse files Browse the repository at this point in the history
Add support for Terraform 0.12
  • Loading branch information
aaron-lane authored Jul 30, 2019
2 parents aa3ae39 + 06c2e67 commit 074443b
Show file tree
Hide file tree
Showing 24 changed files with 929 additions and 180 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ terraform.tfstate
credentials.json
*.iml
.idea
*.pyc
.kitchen

examples/**/*.zip
examples/**/terraform.tfvars
Expand Down
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog][keepachangelog-site],
and this project adheres to [Semantic Versioning][semver-site].


## [Unreleased]

## [1.0.0] - 2019-YY-ZZ

### Changed

- Supported version of Terraform is 0.12. [#11]

## [0.4.1] - 2019-07-03

### Fixed
Expand Down Expand Up @@ -45,6 +50,7 @@ and this project adheres to [Semantic Versioning][semver-site].
[0.2.0]: https://github.com/terraform-google-modules/terraform-google-scheduled-function/compare/v0.1.0...v0.2.0
[0.1.0]: https://github.com/terraform-google-modules/terraform-google-scheduled-function/releases/tag/v0.1.0

[#11]: https://github.com/terraform-google-modules/terraform-google-scheduled-function/pull/11
[#8]: https://github.com/terraform-google-modules/terraform-google-scheduled-function/pull/8
[#5]: https://github.com/terraform-google-modules/terraform-google-scheduled-function/pull/5

Expand Down
48 changes: 29 additions & 19 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@ SHELL := /usr/bin/env bash
# Docker build config variables
CREDENTIALS_PATH ?= /cft/workdir/credentials.json
DOCKER_ORG := gcr.io/cloud-foundation-cicd
DOCKER_TAG_BASE_KITCHEN_TERRAFORM ?= 0.11.11_235.0.0_1.19.1_0.1.10
DOCKER_TAG_BASE_KITCHEN_TERRAFORM ?= 2.3.0
DOCKER_REPO_BASE_KITCHEN_TERRAFORM := ${DOCKER_ORG}/cft/kitchen-terraform:${DOCKER_TAG_BASE_KITCHEN_TERRAFORM}

# All is the first target in the file so it will get picked up when you just run 'make' on its own
all: check_shell check_python check_golang check_terraform check_docker check_base_files test_check_headers check_headers check_trailing_whitespace generate_docs
all: check generate_docs

.PHONY: check
check: check_shell check_python check_golang check_terraform check_docker check_base_files test_check_headers check_headers check_trailing_whitespace


# 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 Down Expand Up @@ -82,53 +86,59 @@ version:
.PHONY: docker_run
docker_run:
docker run --rm -it \
-e CLOUDSDK_AUTH_CREDENTIAL_FILE_OVERRIDE=${CREDENTIALS_PATH} \
-e PROJECT_ID \
-e SERVICE_ACCOUNT_JSON \
-e GOOGLE_APPLICATION_CREDENTIALS=${CREDENTIALS_PATH} \
-e TF_VAR_project_id \
-v $(CURDIR):/cft/workdir \
${DOCKER_REPO_BASE_KITCHEN_TERRAFORM} \
/bin/bash
/bin/bash -c "source test/ci_integration.sh && setup_environment && exec /bin/bash"

.PHONY: docker_create
docker_create:
docker run --rm -it \
-e CLOUDSDK_AUTH_CREDENTIAL_FILE_OVERRIDE=${CREDENTIALS_PATH} \
-e PROJECT_ID \
-e SERVICE_ACCOUNT_JSON \
-e GOOGLE_APPLICATION_CREDENTIALS=${CREDENTIALS_PATH} \
-e TF_VAR_project_id \
-v $(CURDIR):/cft/workdir \
${DOCKER_REPO_BASE_KITCHEN_TERRAFORM} \
/bin/bash -c "kitchen create"
/bin/bash -c "source test/ci_integration.sh && setup_environment && kitchen create"

.PHONY: docker_converge
docker_converge:
docker run --rm -it \
-e CLOUDSDK_AUTH_CREDENTIAL_FILE_OVERRIDE=${CREDENTIALS_PATH} \
-e PROJECT_ID \
-e SERVICE_ACCOUNT_JSON \
-e GOOGLE_APPLICATION_CREDENTIALS=${CREDENTIALS_PATH} \
-e TF_VAR_project_id \
-v $(CURDIR):/cft/workdir \
${DOCKER_REPO_BASE_KITCHEN_TERRAFORM} \
/bin/bash -c "kitchen converge && kitchen converge"
/bin/bash -c "source test/ci_integration.sh && setup_environment && kitchen converge"

.PHONY: docker_verify
docker_verify:
docker run --rm -it \
-e CLOUDSDK_AUTH_CREDENTIAL_FILE_OVERRIDE=${CREDENTIALS_PATH} \
-e PROJECT_ID \
-e SERVICE_ACCOUNT_JSON \
-e GOOGLE_APPLICATION_CREDENTIALS=${CREDENTIALS_PATH} \
-e TF_VAR_project_id \
-v $(CURDIR):/cft/workdir \
${DOCKER_REPO_BASE_KITCHEN_TERRAFORM} \
/bin/bash -c "kitchen verify"
/bin/bash -c "source test/ci_integration.sh && setup_environment && kitchen verify"

.PHONY: docker_destroy
docker_destroy:
docker run --rm -it \
-e CLOUDSDK_AUTH_CREDENTIAL_FILE_OVERRIDE=${CREDENTIALS_PATH} \
-e PROJECT_ID \
-e SERVICE_ACCOUNT_JSON \
-e GOOGLE_APPLICATION_CREDENTIALS=${CREDENTIALS_PATH} \
-e TF_VAR_project_id \
-v $(CURDIR):/cft/workdir \
${DOCKER_REPO_BASE_KITCHEN_TERRAFORM} \
/bin/bash -c "kitchen destroy"
/bin/bash -c "source test/ci_integration.sh && setup_environment && kitchen destroy"

.PHONY: test_integration_docker
test_integration_docker: docker_create docker_converge docker_verify docker_destroy
@echo "Running test-kitchen tests in docker"
test_integration_docker:
docker run --rm -it \
-e PROJECT_ID \
-e SERVICE_ACCOUNT_JSON \
-e GOOGLE_APPLICATION_CREDENTIALS=${CREDENTIALS_PATH} \
-v $(CURDIR):/cft/workdir \
${DOCKER_REPO_BASE_KITCHEN_TERRAFORM} \
make test_integration
19 changes: 14 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
# Terraform Google Scheduled Functions Module

This modules makes it easy to set up a scheduled job to trigger events/run functions.

## 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 [v0.4.1](https://registry.terraform.io/modules/terraform-google-modules/scheduled-function/google/0.4.1).

## Usage
You can go to the examples folder, however the usage of the module could be like this in your own main.tf file:

Expand Down Expand Up @@ -62,15 +70,16 @@ Then perform the following commands on the root folder:

## Requirements
### Terraform plugins
- [Terraform](https://www.terraform.io/downloads.html) 0.11.x
- [Terraform](https://www.terraform.io/downloads.html) 0.12.x
- [terraform-provider-google](https://github.com/terraform-providers/terraform-provider-google) plugin v2.1

### App Engine
Note that this module requires App Engine being configured in the specified project/region.
Note that this module requires App Engine being configured in the specified project/region.
This is because Google Cloud Scheduler is dependent on the project being configured with App Engine.
Refer to the [Google Cloud Scheduler documentation](https://cloud.google.com/scheduler/docs/) for more information on the App Engine dependency.
Refer to the [Google Cloud Scheduler documentation](https://cloud.google.com/scheduler/docs/) for more
information on the App Engine dependency.

The recommended way to create projects with App Engine enabled is via the [Project Factory module](https://github.com/terraform-google-modules/terraform-google-project-factory).
The recommended way to create projects with App Engine enabled is via the [Project Factory module](https://github.com/terraform-google-modules/terraform-google-project-factory).
There is an example of how to create the project [within that module](https://github.com/terraform-google-modules/terraform-google-project-factory/tree/master/examples/app_engine)

### Configure a Service Account
Expand All @@ -93,7 +102,7 @@ In order to operate with the Service Account you must activate the following API
## Install

### Terraform
Be sure you have the correct Terraform version (0.11.x), you can choose the binary here:
Be sure you have the correct Terraform version (0.12.x), you can choose the binary here:
- https://releases.hashicorp.com/terraform/

## Testing and documentation generation
Expand Down
2 changes: 1 addition & 1 deletion examples/pubsub_scheduled/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

This example module schedules a job to publish a message to a Pub/Sub topic every 5 minutes, which will trigger a CloudFunctions function.

Running this module requires an App Engine app in the specified project/region, which is not handled by this example.
Running this module requires an App Engine app in the specified project/region, which is not handled by this example.
More information is in the [root readme](../../README.md#app-engine).

[^]: (autogen_docs_start)
Expand Down
Binary file removed examples/pubsub_scheduled/function_source.zip
Binary file not shown.
16 changes: 10 additions & 6 deletions examples/pubsub_scheduled/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,28 @@
* limitations under the License.
*/

terraform {
required_version = ">= 0.12"
}

provider "google-beta" {
version = "~> 2.1"
project = "${var.project_id}"
region = "${var.region}"
version = "~> 2.5"
project = var.project_id
region = var.region
}

module "pubsub_scheduled_example" {
providers = {
google = "google-beta"
google = google-beta
}

source = "../../"
project_id = "${var.project_id}"
project_id = var.project_id
job_name = "pubsub-example"
job_schedule = "*/5 * * * *"
function_entry_point = "doSomething"
function_source_directory = "${path.module}/function_source"
function_name = "testfunction-foo"
region = "${var.region}"
region = var.region
topic_name = "pubsub_example_topic"
}
4 changes: 2 additions & 2 deletions examples/pubsub_scheduled/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
*/

output "name" {
value = "${module.pubsub_scheduled_example.name}"
value = module.pubsub_scheduled_example.name
description = "The name of the job created"
}

output "project_id" {
value = "${var.project_id}"
value = var.project_id
description = "The project ID"
}
2 changes: 2 additions & 0 deletions examples/pubsub_scheduled/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@
*/

variable "project_id" {
type = string
description = "The project ID to host the network in"
}

variable "region" {
type = string
description = "The region the project is in (App Engine specific)"
default = "us-central1"
}
59 changes: 0 additions & 59 deletions helpers/combine_docfiles.py

This file was deleted.

Loading

0 comments on commit 074443b

Please sign in to comment.