-
Notifications
You must be signed in to change notification settings - Fork 47
Initial Commit #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 19 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
b00976d
Initial commit
2a75974
remove lock
aedb2b5
README fix, and remove provider from module
2c7121a
Paramerize data
e71f99d
Change 2018 to 2019
3f13889
Clean up terraform format
d56bc94
Remove tfvars sample file
151e03f
CR comments
3c9c3a3
Fix test verify script
1404396
Add some randominzation options to bucket name
982a4cd
Update variables.tf
aaron-lane 64cbf4b
Update variables.tf
aaron-lane c82aceb
Update variables.tf
aaron-lane 5a6dbca
Update examples/pubsub_scheduled/variables.tf
aaron-lane 85f6395
Update README.md
aaron-lane fff5db8
Update examples/pubsub_scheduled/variables.tf
aaron-lane 8a59f0b
Update examples/pubsub_scheduled/main.tf
aaron-lane 00b1800
Apply suggestions from code review
aaron-lane 3f35c5f
Documentaion update
4997cff
doc cleanup
b962034
Remove all_examples because it wasn't used
9ccb662
Update docs
2b94122
Missed period
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
terraform.tfstate | ||
*.tfstate.* | ||
.terraform | ||
credentials.json | ||
*.iml | ||
.idea | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# 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. | ||
|
||
--- | ||
driver: | ||
name: "terraform" | ||
command_timeout: 1800 | ||
|
||
provisioner: | ||
name: "terraform" | ||
|
||
platforms: | ||
- name: local | ||
|
||
suites: | ||
- name: "pubsub_scheduled" | ||
driver: | ||
name: "terraform" | ||
command_timeout: 1800 | ||
root_module_directory: test/fixtures/pubsub_scheduled | ||
verifier: | ||
name: terraform | ||
color: true | ||
systems: | ||
- name: pubsub_scheduled | ||
backend: local | ||
controls: | ||
- gcloud | ||
provisioner: | ||
name: terraform |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Changelog | ||
|
||
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]. | ||
|
||
|
||
## 0.1.0 - 2018-08-08 | ||
|
||
### Added | ||
|
||
- Initial release | ||
|
||
[keepachangelog-site]: https://keepachangelog.com/en/1.0.0/ | ||
[semver-site]: https://semver.org/spec/v2.0.0.html |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
|
||
ruby '2.5.3' | ||
|
||
source 'https://rubygems.org/' do | ||
gem 'kitchen-terraform', '~> 4.3' | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
# 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 | ||
# | ||
# https://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. | ||
|
||
# Make will use bash instead of sh | ||
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_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 | ||
|
||
# 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 | ||
# working | ||
.PHONY: check_shell | ||
check_shell: | ||
@source test/make.sh && check_shell | ||
|
||
.PHONY: check_python | ||
check_python: | ||
@source test/make.sh && check_python | ||
|
||
.PHONY: check_golang | ||
check_golang: | ||
@source test/make.sh && golang | ||
|
||
.PHONY: check_terraform | ||
check_terraform: | ||
@source test/make.sh && check_terraform | ||
|
||
.PHONY: check_docker | ||
check_docker: | ||
@source test/make.sh && docker | ||
|
||
.PHONY: check_base_files | ||
check_base_files: | ||
@source test/make.sh && basefiles | ||
|
||
.PHONY: check_trailing_whitespace | ||
check_trailing_whitespace: | ||
@source test/make.sh && check_trailing_whitespace | ||
|
||
.PHONY: test_check_headers | ||
test_check_headers: | ||
@echo "Testing the validity of the header check" | ||
@python test/test_verify_boilerplate.py | ||
|
||
.PHONY: check_headers | ||
check_headers: | ||
@source test/make.sh && check_headers | ||
|
||
# Integration tests | ||
.PHONY: test_integration | ||
test_integration: | ||
./test/ci_integration.sh | ||
|
||
.PHONY: generate_docs | ||
generate_docs: | ||
@source test/make.sh && generate_docs | ||
|
||
# Versioning | ||
.PHONY: version | ||
version: | ||
@source helpers/version-repo.sh | ||
|
||
# Run docker | ||
.PHONY: docker_run | ||
docker_run: | ||
docker run --rm -it \ | ||
-e CLOUDSDK_AUTH_CREDENTIAL_FILE_OVERRIDE=${CREDENTIALS_PATH} \ | ||
-e GOOGLE_APPLICATION_CREDENTIALS=${CREDENTIALS_PATH} \ | ||
-e TF_VAR_project_id \ | ||
-v $(CURDIR):/cft/workdir \ | ||
${DOCKER_REPO_BASE_KITCHEN_TERRAFORM} \ | ||
/bin/bash | ||
|
||
.PHONY: docker_create | ||
docker_create: | ||
docker run --rm -it \ | ||
-e CLOUDSDK_AUTH_CREDENTIAL_FILE_OVERRIDE=${CREDENTIALS_PATH} \ | ||
-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" | ||
|
||
.PHONY: docker_converge | ||
docker_converge: | ||
docker run --rm -it \ | ||
-e CLOUDSDK_AUTH_CREDENTIAL_FILE_OVERRIDE=${CREDENTIALS_PATH} \ | ||
-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" | ||
|
||
.PHONY: docker_verify | ||
docker_verify: | ||
docker run --rm -it \ | ||
-e CLOUDSDK_AUTH_CREDENTIAL_FILE_OVERRIDE=${CREDENTIALS_PATH} \ | ||
-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" | ||
|
||
.PHONY: docker_destroy | ||
docker_destroy: | ||
docker run --rm -it \ | ||
-e CLOUDSDK_AUTH_CREDENTIAL_FILE_OVERRIDE=${CREDENTIALS_PATH} \ | ||
-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" | ||
|
||
.PHONY: test_integration_docker | ||
test_integration_docker: docker_create docker_converge docker_verify docker_destroy | ||
@echo "Running test-kitchen tests in docker" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,147 @@ | ||
# terraform-google-scheduled-function | ||
# Terraform Google Scheduled Functions Module | ||
This modules makes it easy to set up a scheduled job to trigger events/run functions. | ||
|
||
## Usage | ||
You can go to the examples folder, however the usage of the module could be like this in your own main.tf file: | ||
|
||
```hcl | ||
module "scheduled-function" { | ||
source = "terraform-google-modules/scheduled-functions/google" | ||
version = "0.1.0" | ||
project_id = "<PROJECT ID>" | ||
job_name="<NAME_OF_JOB>" | ||
schedule="<CRON_SYNTAX_SCHEDULE" | ||
function_entry_point="<NAME_OF_FUNCTION>" | ||
function_source_directory="<DIRECTORY_OF_FUNCTION_SOURCE>" | ||
name="<RESOURCE_NAMES>" | ||
region="<REGION>" | ||
} | ||
``` | ||
|
||
Then perform the following commands on the root folder: | ||
|
||
- `terraform init` to get the plugins | ||
- `terraform plan` to see the infrastructure plan | ||
- `terraform apply` to apply the infrastructure build | ||
- `terraform destroy` to destroy the built infrastructure | ||
|
||
[^]: (autogen_docs_start) | ||
|
||
## Inputs | ||
|
||
| Name | Description | Type | Default | Required | | ||
|------|-------------|:----:|:-----:|:-----:| | ||
| bucket\_name | The name to apply to the bucket. Will default to a string of <project-id>-scheduled-function-XXXX> with XXXX being random characters. | string | `""` | no | | ||
| function\_available\_memory\_mb | The amount of memory in megabytes allotted for the function to use. | string | `"256"` | no | | ||
| function\_description | The description of the function. | string | `"Processes log export events provided through a Pub/Sub topic subscription."` | no | | ||
| function\_entry\_point | The name of a method in the function source which will be invoked when the function is executed. | string | n/a | yes | | ||
| function\_environment\_variables | A set of key/value environment variable pairs to assign to the function. | map | `<map>` | no | | ||
| function\_event\_trigger\_failure\_policy\_retry | A toggle to determine if the function should be retried on failure. | string | `"false"` | no | | ||
| function\_labels | A set of key/value label pairs to assign to the function. | map | `<map>` | no | | ||
| function\_name | The name to apply to the function | string | n/a | yes | | ||
| function\_runtime | The runtime in which the function will be executed. | string | `"nodejs6"` | no | | ||
| function\_source\_archive\_bucket\_labels | A set of key/value label pairs to assign to the function source archive bucket. | map | `<map>` | no | | ||
| function\_source\_directory | The contents of this directory will be archived and used as the function source. | string | n/a | yes | | ||
| function\_timeout\_s | The amount of time in seconds allotted for the execution of the function. | string | `"60"` | no | | ||
| job\_description | Addition text to describet the job | string | `""` | no | | ||
| job\_name | The name of the scheduled job to run | string | n/a | yes | | ||
| job\_schedule | The job frequency, in cron syntax | string | `"*/2 * * * *"` | no | | ||
| message\_data | The data to send in the topic message. | string | `"dGVzdA=="` | no | | ||
| project\_id | The ID of the project where this VPC will be created | string | n/a | yes | | ||
| region | The region in which resources will be applied. | string | n/a | yes | | ||
| topic\_name | Name of pubsub topic connecting the scheduled job and the function | string | `"test-topic"` | no | | ||
|
||
## Outputs | ||
|
||
| Name | Description | | ||
|------|-------------| | ||
| name | The name of the job created | | ||
|
||
[^]: (autogen_docs_end) | ||
|
||
## Requirements | ||
### Terraform plugins | ||
- [Terraform](https://www.terraform.io/downloads.html) 0.11.x | ||
- [terraform-provider-google](https://github.com/terraform-providers/terraform-provider-google) plugin v2.1 | ||
|
||
### App Engine | ||
Note that this module requires a 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. | ||
Documentation on the App Engine dependency is here: https://cloud.google.com/scheduler/docs/ | ||
ogreface marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
### Configure a Service Account | ||
In order to execute this module you must have a Service Account with the following roles. | ||
|
||
- roles/storage.admin | ||
- roles/pubsub.editor | ||
- roles/cloudscheduler.admin | ||
- roles/cloudfunctions.developer | ||
- roles/iam.serviceAccountUser | ||
|
||
|
||
### Enable API's | ||
In order to operate with the Service Account you must activate the following API on the project where the Service Account was created: | ||
|
||
- Cloud Scheduler API - cloudscheduler.googleapis.com | ||
- Cloud PubSub API - pubsub.googleapis.com | ||
- Cloud Functions API - cloudfunctions.googleapis.com | ||
|
||
## Install | ||
|
||
### Terraform | ||
Be sure you have the correct Terraform version (0.11.x), you can choose the binary here: | ||
- https://releases.hashicorp.com/terraform/ | ||
|
||
## Testing and documentation generation | ||
|
||
### Requirements | ||
- [docker](https://docker.com) | ||
- [terraform-docs](https://github.com/segmentio/terraform-docs/releases) 0.6.0 | ||
|
||
### Integration test | ||
##### Terraform integration tests | ||
It is recommended to to run the integration tests via docker. To do so, run `make test_integration_docker`. In containers, this will | ||
- Perform `terraform init` command | ||
- Perform `terraform get` command | ||
- Perform `terraform validate` command | ||
- Perform `terraform apply -auto-approve` command and check that it has created the appropriate resources | ||
- Perform `terraform destroy -force` command and check that it has destroyed the appropriate resources | ||
|
||
### Autogeneration of documentation from .tf files | ||
Run | ||
``` | ||
make generate_docs | ||
``` | ||
|
||
### Linting | ||
The makefile in this project will lint or sometimes just format any shell, | ||
Python, golang, Terraform, or Dockerfiles. The linters will only be run if | ||
the makefile finds files with the appropriate file extension. | ||
|
||
All of the linter checks are in the default make target, so you just have to | ||
run | ||
|
||
``` | ||
make -s | ||
``` | ||
|
||
The -s is for 'silent'. Successful output looks like this | ||
|
||
``` | ||
Running shellcheck | ||
Running flake8 | ||
Running gofmt | ||
Running terraform validate | ||
Running hadolint on Dockerfiles | ||
Test passed - Verified all file Apache 2 headers | ||
``` | ||
|
||
The linters | ||
are as follows: | ||
* Shell - shellcheck. Can be found in homebrew | ||
* Python - flake8. Can be installed with 'pip install flake8' | ||
* Golang - gofmt. gofmt comes with the standard golang installation. golang | ||
is a compiled language so there is no standard linter. | ||
* Terraform - terraform has a built-in linter in the 'terraform validate' | ||
command. | ||
* Dockerfiles - hadolint. Can be found in homebrew |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.