Skip to content

Commit d437347

Browse files
author
Steven Nemetz
committed
first commit
0 parents  commit d437347

File tree

21 files changed

+627
-0
lines changed

21 files changed

+627
-0
lines changed

.circleci/config.yml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
version: 2
2+
3+
jobs:
4+
build:
5+
docker:
6+
- image: hashicorp/terraform:0.11.3
7+
entrypoint: /bin/sh
8+
steps:
9+
- checkout
10+
- run:
11+
name: "Validate tf files (terraform validate)"
12+
command: |
13+
find . -type f -name "*.tf" -exec dirname {} \;|sort -u | while read m; do (terraform validate -check-variables=false "$m" && echo "√ $m") || exit 1 ; done
14+
- run:
15+
name: "Check: Terraform formatting (terraform fmt)"
16+
command: |
17+
if [ `terraform fmt --list=true -diff=true -write=false | tee format-issues | wc -c` -ne 0 ]; then
18+
echo "Some terraform files need be formatted, run 'terraform fmt' to fix"
19+
echo "Formatting issues:"
20+
cat format-issues
21+
exit 1
22+
fi
23+
- run:
24+
name: "Install: tflint"
25+
command: |
26+
apk add jq wget
27+
# Get latest version of tflint
28+
pkg_arch=linux_amd64
29+
dl_url=$(curl -s https://api.github.com/repos/wata727/tflint/releases/latest | jq -r ".assets[] | select(.name | test(\"${pkg_arch}\")) | .browser_download_url")
30+
wget ${dl_url}
31+
unzip tflint_linux_amd64.zip
32+
mkdir -p /usr/local/tflint/bin
33+
# Setup PATH for later run steps - ONLY for Bash and not in Bash
34+
#echo 'export PATH=/usr/local/tflint/bin:$PATH' >> $BASH_ENV
35+
echo "Installing tflint..."
36+
install tflint /usr/local/tflint/bin
37+
echo "Configuring tflint..."
38+
tf_ver=$(terraform version | awk 'FNR <= 1' | cut -dv -f2)
39+
echo -e "\tConfig for terraform version: ${tf_ver}"
40+
if [ -f '.tflint.hcl' ]; then
41+
sed -i "/terraform_version =/s/\".*\"/\"${tf_ver}\"/" .tflint.hcl
42+
else
43+
{
44+
echo -e "config {\nterraform_version = \"${tf_ver}\"\ndeep_check = true\nignore_module = {"
45+
for module in $(grep -h '[^a-zA-Z]source[ =]' *.tf | sed -r 's/.*=\s+//' | sort -u); do
46+
# if not ^"../
47+
echo "${module} = true"
48+
done
49+
echo "}}"
50+
} > .tflint.hcl
51+
fi
52+
echo "tflint configuration:"
53+
cat .tflint.hcl
54+
- run:
55+
# Not supporting modules from registry ?? v0.5.4
56+
# For now, must ignore in config file
57+
name: "Check: tflint"
58+
command: |
59+
#echo "Initializing terraform..."
60+
#terraform init -input=false
61+
echo "Running tflint..."
62+
/usr/local/tflint/bin/tflint --version
63+
/usr/local/tflint/bin/tflint
64+
65+
workflows:
66+
version: 2
67+
build:
68+
jobs:
69+
- build

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*.tfstate
2+
*.tfstate.backup
3+
.terraform

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# terraform-aws-budget
2+
3+
Terraform module to setup AWS budgets and notifications
4+
5+
This is fairly specific for now. It can create budgets for multiple linked accounts. Each with it's own limit.
6+
Notification is only supported for a single email address
7+
8+
NOTE: Setting up notification and subscribers is not currently supported in Terraform
9+
10+
Notifications are predefined in this module. They are:
11+
- 110% of forecasted
12+
- 80% of actual
13+
- 90% of actual

bugs-to-report.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Issues budgets resource:
2+
3+
Why start date required? AWS doc says it is optional and has rules of how it is created when not provided
4+
Work around: Calculate start of month and provide
5+
6+
When account id is not provided get "Account min size is 12". Appears provider is not providing it properly
7+
Work around: provide account id
8+
9+
Issue with changing budget name. This should force the budget to be recreated. AWS doesn't allow changing the name
10+
Current generates error: Failed to call UpdateBudget - Unable to get budget: BUDGET_NEW_NAME - the budget doesn't exist.

examples/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
# Example and manual test cases
3+
4+
Each directory contains a configuration that serves as a manual test case and an example
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Example: Annually account budgets
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
module "budgets" {
3+
source = "../../"
4+
budgets = "${var.budgets}"
5+
email = "snemetz@wiser.com"
6+
time_unit = "ANNUALLY"
7+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
provider "aws" {
2+
region = "${var.region}"
3+
4+
# Make it faster by skipping something
5+
skip_get_ec2_platforms = true
6+
skip_metadata_api_check = true
7+
skip_region_validation = true
8+
skip_credentials_validation = true
9+
skip_requesting_account_id = true
10+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
variable "environment" {
2+
default = "test"
3+
}
4+
5+
variable "region" {
6+
default = "us-west-2"
7+
}
8+
9+
variable "budgets" {
10+
description = "List of account budget maps. Each map contains: name (name of budget), account (AWS linked account ID), and limit (budget limit)"
11+
12+
default = [
13+
{
14+
name = "acc-1"
15+
account = "123456789011"
16+
limit = 100
17+
},
18+
{
19+
name = "acc-2"
20+
account = "123456789012"
21+
limit = 200
22+
},
23+
{
24+
name = "acc-3"
25+
account = "123456789013"
26+
limit = 300
27+
},
28+
]
29+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Example: Quarterly account budgets

0 commit comments

Comments
 (0)