File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ name : pre-commit-check
2+ on :
3+ push :
4+ branches :
5+ - master
6+ pull_request :
7+
8+ jobs :
9+ build :
10+ runs-on : macOS-latest
11+ steps :
12+ - uses : actions/checkout@v1
13+
14+ - name : Install prerequisites
15+ run : |
16+ brew install tfenv tflint terraform-docs pre-commit
17+ pre-commit install
18+ tfenv install
19+
20+ - name : pre-commit run all
21+ run : |
22+ pre-commit run -a
Original file line number Diff line number Diff line change 11# Local .terraform directories
22** /.terraform /*
3+ terraform.d
34
45# .tfstate files
56* .tfstate
@@ -26,4 +27,4 @@ override.tf.json
2627# !example_override.tf
2728
2829# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan
29- # example: *tfplan*
30+ # example: *tfplan*
Original file line number Diff line number Diff line change 11---
22repos :
33- repo : git://github.com/antonbabenko/pre-commit-terraform
4- rev : v1.20 .0
4+ rev : v1.24 .0
55 hooks :
66 - id : terraform_fmt
77 - id : terraform_docs
Original file line number Diff line number Diff line change 1- 0.12.17
1+ 0.12.20
Original file line number Diff line number Diff line change 1+ SHELL := /bin/bash
2+ TF_WORKSPACE := $(shell terraform workspace show)
3+ WORKSPACE ?= $(TF_WORKSPACE )
4+ NEW= := $(NEW )
5+ FOLDER_NAME := $(shell pwd | xargs basename)
6+
7+ .PHONY : init list apply destroy new
8+ ALL : apply
9+
10+ setup :
11+ @echo setting up AWS environment
12+ bin/setup.sh
13+
14+ clean :
15+ @echo WARNING - removing local terraform dirs
16+ rm -rf .terraform
17+
18+ init :
19+ @echo sourcing environmental variables
20+ terraform init -backend-config backend.auto.tfvars -backend-config " key=$( FOLDER_NAME) .tfstate"
21+
22+ list :
23+ @echo listing terraform workspaces:
24+ terraform workspace list
25+
26+ plan : init
27+ @echo planning changes to the $(WORKSPACE ) workspace
28+ terraform workspace select $(WORKSPACE)
29+ terraform plan -var-file $(WORKSPACE ) .tfvars
30+
31+ apply : init
32+ @echo applying changes to the $(WORKSPACE ) workspace
33+ terraform workspace select $(WORKSPACE)
34+ terraform apply -var-file $(WORKSPACE ) .tfvars
35+
36+ destroy : init
37+ @echo applying changes to the $(WORKSPACE ) workspace
38+ terraform workspace select $(WORKSPACE)
39+ terraform destroy -var-file $(WORKSPACE ) .tfvars
40+
41+ new : init
42+ @echo " create a new terraform workspace by running 'make NEW=my-new-name new'"
43+ $(shell [ -z $(NEW ) ] && echo 'please define the NEW env var'; exit 1;)
44+ terraform workspace new $(NEW )
45+ echo " env = \" $( NEW) \" " >> $(NEW ) .tfvars
Original file line number Diff line number Diff line change 11# sample-aws-project
2+ [ ![ GH Action Status] ( https://github.com/rhythmictech/sample-aws-project/workflows/pre-commit-check/badge.svg )] ( https://github.com/rhythmictech/sample-aws-project/actions )
3+
24
35A sample AWS project managed by Terraform
6+
7+ ## Initial Setup
8+
9+ There is a handy setup script at ` bin/setup.sh ` which will create a
10+ [ terraform s3 backend] ( https://www.terraform.io/docs/backends/types/s3.html )
11+ with locking via DynamoDB and add it's resources to your remote state.
12+
13+ To all the DevOps engineers out there with bosses to impress it's easy to do just follow these steps:
14+ 1 . Install the prerequisites
15+ - ` git `
16+ - ` terraform ` (We use [ tfenv] ( https://github.com/tfutils/tfenv ) to manage ` terraform ` versions)
17+ - ` pre-commit `
18+ - ` GNUMake `
19+ 1 . [ provide authentication for the aws provider] ( https://www.terraform.io/docs/providers/aws/index.html#authentication )
20+ 1 . Clone the repo: ` git clone https://github.com/rhythmictech/sample-aws-project.git terraform-aws-rhythmictech `
21+ 1 . Update the values for the backend in ` account/backend.auto.tfvars `
22+ 1 . Run the setup with ` make setup `
Original file line number Diff line number Diff line change 11# Account Settings
22
33<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
4+ ## Providers
5+
6+ | Name | Version |
7+ | ------| ---------|
8+ | errorcheck | n/a |
9+
410## Inputs
511
612| Name | Description | Type | Default | Required |
7- | ------| -------------| :----:| :-----:| :-----:|
13+ | ------| -------------| ------| ---------| :-----:|
14+ | bucket | Bucket that tfstate is stored in | ` string ` | n/a | yes |
15+ | dynamodb\_ table | DynamoDB table for locking/state management | ` string ` | n/a | yes |
16+ | env | Environment being deployed to | ` string ` | n/a | yes |
17+ | iam\_ master\_ account | n/a | ` string ` | n/a | yes |
18+ | iam\_ role\_ prefix | n/a | ` string ` | n/a | yes |
19+ | key | Key that tfstate is stored in | ` string ` | n/a | yes |
20+ | namespace | Project name | ` string ` | n/a | yes |
21+ | owner | Owner of this infrastructure | ` string ` | n/a | yes |
22+ | region | Region resources are being deployed to | ` string ` | n/a | yes |
23+ | tags | n/a | ` map(string) ` | ` {} ` | no |
824
925## Outputs
1026
11- | Name | Description |
12- | ------| -------------|
27+ No output.
1328
1429<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
Original file line number Diff line number Diff line change 1- tfstate_bucket = " 012345678912-us-east-1-tf-state"
2- tfstate_key = " account.tfstate"
3- tfstate_dynamodb_table = " tf-locktable"
4- region = " us-east-1"
1+ bucket = " 012345678912-us-east-1-tf-state"
2+ key = " account.tfstate"
3+ dynamodb_table = " tf-locktable"
4+ region = " us-east-1"
Original file line number Diff line number Diff line change @@ -4,9 +4,8 @@ provider "aws" {
44
55module "backend" {
66 source = " git::ssh://git@github.com/rhythmictech/terraform-aws-backend?ref=v1.2.0"
7- bucket = var. tfstate_bucket
8- table = var. tfstate_dynamodb_table
7+ bucket = var. bucket
8+ table = var. dynamodb_table
99 region = var. region
1010 tags = var. tags
1111}
12-
Original file line number Diff line number Diff line change @@ -15,20 +15,17 @@ variable "tags" {
1515 type = map (string )
1616}
1717
18- variable "tfstate_bucket " {
18+ variable "bucket " {
1919 description = " Bucket that tfstate is stored in"
2020 type = string
2121}
2222
23- variable "tfstate_dynamodb_table " {
23+ variable "dynamodb_table " {
2424 description = " DynamoDB table for locking/state management"
2525 type = string
2626}
2727
28- variable "tfstate_key " {
28+ variable "key " {
2929 description = " Key that tfstate is stored in"
3030 type = string
3131}
32-
33-
34-
You can’t perform that action at this time.
0 commit comments