Skip to content

Commit ce00802

Browse files
authored
Merge pull request #1 from rhythmictech/initial
initial commit
2 parents e33c3f9 + a2f0406 commit ce00802

File tree

12 files changed

+508
-108
lines changed

12 files changed

+508
-108
lines changed

.github/workflows/pre-commit-check.yaml

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,38 @@ on:
44
push:
55
branches:
66
- master
7+
- develop
78
pull_request:
89

910
jobs:
1011
build:
1112
runs-on: macOS-latest
1213
steps:
13-
- uses: actions/checkout@v1
14-
15-
- name: Install prerequisites
16-
run: |
17-
brew install tfenv tflint terraform-docs pre-commit
18-
pre-commit install
19-
tfenv install
20-
- name: pre-commit run all
21-
run: |
22-
pre-commit run -a
14+
- uses: actions/checkout@v2
15+
with:
16+
ref: ${{ github.head_ref }}
17+
- name: Install prerequisites
18+
run: ./bin/install-macos.sh
19+
- name: initialize Terraform
20+
run: terraform init --backend=false
21+
- uses: actions/cache@v1
22+
with:
23+
path: ~/.cache/pre-commit
24+
key: pre-commit|${{ hashFiles('.pre-commit-config.yaml') }}
25+
restore-keys: |
26+
pre-commit
27+
- name: pre-commit run all
28+
run: |
29+
pre-commit run -a
30+
env:
31+
AWS_DEFAULT_REGION: us-east-1
32+
SKIP: terraform_tflint_deep
33+
- uses: stefanzweifel/git-auto-commit-action@v4
34+
if: ${{ failure() }}
35+
with:
36+
commit_message: Apply automatic changes
37+
commit_options: "--no-verify"
38+
# Optional commit user and author settings
39+
commit_user_name: Linter Bot
40+
commit_user_email: [email protected]
41+
commit_author: Linter Bot <[email protected]>

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@
77

88
# .tfvars files
99
*.tfvars
10+
11+
*.zip
12+
tmp

.pre-commit-config.yaml

Lines changed: 66 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,67 @@
11
repos:
2-
- repo: git://github.com/antonbabenko/pre-commit-terraform
3-
rev: v1.30.0
4-
hooks:
5-
- id: terraform_fmt
6-
- id: terraform_docs
7-
- repo: https://github.com/pre-commit/pre-commit-hooks
8-
rev: v3.0.0
9-
hooks:
10-
- id: end-of-file-fixer
11-
- id: trailing-whitespace
12-
- id: no-commit-to-branch
2+
- repo: https://github.com/antonbabenko/pre-commit-terraform
3+
rev: v1.31.0
4+
hooks:
5+
- id: terraform_docs
6+
always_run: true
7+
args:
8+
- --args=--sort-by-required
9+
- id: terraform_fmt
10+
- id: terraform_tflint
11+
alias: terraform_tflint_deep
12+
name: terraform_tflint_deep
13+
args:
14+
- --args=--deep
15+
- id: terraform_tflint
16+
alias: terraform_tflint_nocreds
17+
name: terraform_tflint_nocreds
18+
- id: terraform_tfsec
19+
- repo: local
20+
hooks:
21+
- id: terraform_validate
22+
name: terraform_validate
23+
entry: |
24+
bash -c '
25+
AWS_DEFAULT_REGION=us-east-1
26+
declare -a DIRS
27+
for FILE in "$@"
28+
do
29+
DIRS+=($(dirname "$FILE"))
30+
done
31+
for DIR in $(printf "%s\n" "${DIRS[@]}" | sort -u)
32+
do
33+
cd $(dirname "$FILE")
34+
terraform init --backend=false
35+
terraform validate .
36+
done
37+
'
38+
language: system
39+
verbose: true
40+
files: \.tf(vars)?$
41+
exclude: examples
42+
- repo: https://github.com/pre-commit/pre-commit-hooks
43+
rev: v3.0.0
44+
hooks:
45+
- id: check-case-conflict
46+
- id: check-json
47+
- id: check-merge-conflict
48+
- id: check-symlinks
49+
- id: check-yaml
50+
args:
51+
- --unsafe
52+
- id: end-of-file-fixer
53+
- id: trailing-whitespace
54+
- id: mixed-line-ending
55+
args:
56+
- --fix=lf
57+
- id: no-commit-to-branch
58+
- id: pretty-format-json
59+
args:
60+
- --autofix
61+
- --top-keys=name,Name
62+
- id: trailing-whitespace
63+
args:
64+
- --markdown-linebreak-ext=md
65+
exclude: README.md
66+
- id: check-ast
67+
- id: check-builtin-literals

README.md

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,46 @@
1-
# terraform-anycloud-template [![](https://github.com/rhythmictech/terraform-anycloud-template/workflows/pre-commit-check/badge.svg)](https://github.com/rhythmictech/terraform-anycloud-template/actions) <a href="https://twitter.com/intent/follow?screen_name=RhythmicTech"><img src="https://img.shields.io/twitter/follow/RhythmicTech?style=social&logo=RhythmicTech" alt="follow on Twitter"></a>
2-
Template repository for terraform modules. Good for any cloud and any provider.
1+
# terraform-aws-cloudflare-restrictor [![](https://github.com/rhythmictech/terraform-aws-cloudflare-restrictor/workflows/pre-commit-check/badge.svg)](https://github.com/rhythmictech/terraform-aws-cloudflare-restrictor/actions) <a href="https://twitter.com/intent/follow?screen_name=RhythmicTech"><img src="https://img.shields.io/twitter/follow/RhythmicTech?style=social&logo=RhythmicTech" alt="follow on Twitter"></a>
2+
3+
This module will automatically manage the ingress rules for any security groups that are appropriately tagged, only permitting CloudFlare IP addresses. The module will create a Lambda that runs once per day, using the public CloudFlare API for known IP addresses to pull the latest IPs and merge them into the security group.
4+
5+
By default, the Lambda will update any security group with the tag key `CLOUDFLARE_MANAGED` set to `true`,
6+
though this can be customized. Any existing ingress rules will be removed when this tag key/value match. Since the Lambda only runs once per day, it is recommended that it be manually triggered whenever a new security group is added.
37

48
## Example
5-
Here's what using the module will look like
9+
Here's what using the module will look like:
10+
611
```
7-
module "example" {
8-
source = "rhythmictech/terraform-mycloud-mymodule
12+
module "cloudflare-restrictor" {
13+
source = "rhythmictech/terraform-aws-cloudflare-restrictor"
914
}
1015
```
1116

12-
## About
13-
A bit about this module
14-
1517
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
1618
## Requirements
1719

18-
No requirements.
20+
| Name | Version |
21+
|------|---------|
22+
| terraform | >= 0.12.19 |
1923

2024
## Providers
2125

22-
No provider.
26+
| Name | Version |
27+
|------|---------|
28+
| archive | n/a |
29+
| aws | n/a |
2330

2431
## Inputs
2532

2633
| Name | Description | Type | Default | Required |
2734
|------|-------------|------|---------|:--------:|
28-
| name | Moniker to apply to all resources in the module | `string` | n/a | yes |
35+
| allowed\_ports | Ports to allow traffic from CloudFlare on (recommended to only use 443) | `list(number)` | <pre>[<br> 443<br>]</pre> | no |
36+
| execution\_expression | cron expression for how frequently rules should be updated | `string` | `"rate(1 day)"` | no |
37+
| name | Moniker to apply to all resources in the module | `string` | `"cloudflare-restrictor"` | no |
38+
| tag\_key | Tag key to expect on security groups that will be managed by this module | `string` | `"CLOUDFLARE_MANAGED"` | no |
39+
| tag\_value | Tag value to expect on security groups that will be managed by this module | `string` | `"true"` | no |
2940
| tags | User-Defined tags | `map(string)` | `{}` | no |
3041

3142
## Outputs
3243

33-
| Name | Description |
34-
|------|-------------|
35-
| tags\_module | Tags Module in it's entirety |
44+
No output.
3645

3746
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
38-
39-
## The Giants underneath this module
40-
- pre-commit.com/
41-
- terraform.io/
42-
- github.com/tfutils/tfenv
43-
- github.com/segmentio/terraform-docs

bin/install-macos.sh

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
#!/bin/bash
22

33
echo 'installing brew packages'
4-
brew install tfenv tflint terraform-docs pre-commit
4+
brew update
5+
brew tap liamg/tfsec
6+
brew install tfenv tflint terraform-docs pre-commit liamg/tfsec/tfsec coreutils
7+
brew upgrade tfenv tflint terraform-docs pre-commit liamg/tfsec/tfsec coreutils
58

69
echo 'installing pre-commit hooks'
710
pre-commit install
811

12+
echo 'setting pre-commit hooks to auto-install on clone in the future'
13+
git config --global init.templateDir ~/.git-template
14+
pre-commit init-templatedir ~/.git-template
15+
916
echo 'installing terraform with tfenv'
10-
tfenv install
17+
tfenv install min-required
18+
tfenv use min-required

0 commit comments

Comments
 (0)