Skip to content

Commit be03448

Browse files
committed
Add CircleCI. Fix formatting
1 parent d7fba63 commit be03448

File tree

7 files changed

+97
-9
lines changed

7 files changed

+97
-9
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

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
[![CircleCI](https://circleci.com/gh/devops-workflow/terraform-aws-s3-buckets?style=svg)](https://circleci.com/gh/devops-workflow/terraform-aws-s3-buckets)
2+
13
AWS S3 Buckets Terraform module
24
========================
35

main.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,17 @@ module "label" {
4848

4949
resource "aws_s3_bucket" "this" {
5050
count = "${module.enabled.value ? length(var.names) : 0}"
51+
5152
bucket = "${var.namespaced ?
5253
format("%s-%s-%s", var.org, var.environment, replace(element(var.names, count.index), "_", "-")) :
5354
format("%s-%s", var.org, replace(element(var.names, count.index), "_", "-"))}"
55+
5456
acl = "${var.public ? "public-read" : "private"}"
57+
5558
versioning {
5659
enabled = "${var.versioned}"
5760
}
61+
5862
#acceleration_status
5963
#force_destroy = true
6064
#lifecycle_rule {}
@@ -91,8 +95,10 @@ resource "aws_s3_bucket_policy" "bucket_policy" {
9195
}
9296
*/
9397

98+
9499
#resource "aws_s3_bucket_notification"
95100

101+
96102
/*
97103
resource "aws_s3_bucket_object" "this" {
98104
count = "${length(var.files)}"
@@ -102,3 +108,4 @@ resource "aws_s3_bucket_object" "this" {
102108
etag = "${md5(file("${lookup(var.files, element(keys(var.files), count.index))}"))}"
103109
}
104110
*/
111+

outputs.tf

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,34 @@
1-
21
output "arns" {
32
description = "List of AWS S3 Bucket ARNs"
4-
value = "${aws_s3_bucket.this.*.arn}"
3+
value = "${aws_s3_bucket.this.*.arn}"
54
}
5+
66
output "domain_names" {
77
description = "List of AWS S3 Bucket Domain Names"
8-
value = "${aws_s3_bucket.this.*.bucket_domain_name}"
8+
value = "${aws_s3_bucket.this.*.bucket_domain_name}"
99
}
10+
1011
output "hosted_zone_ids" {
1112
description = "List of AWS S3 Bucket Hosted Zone IDs"
12-
value = "${aws_s3_bucket.this.*.hosted_zone_id}"
13+
value = "${aws_s3_bucket.this.*.hosted_zone_id}"
1314
}
15+
1416
output "ids" {
1517
description = "List of AWS S3 Bucket IDs"
1618
value = "${aws_s3_bucket.this.*.id}"
1719
}
20+
1821
output "names" {
1922
description = "List of AWS S3 Bucket Names"
20-
value = "${aws_s3_bucket.this.*.id}"
23+
value = "${aws_s3_bucket.this.*.id}"
2124
}
25+
2226
output "regions" {
2327
description = "List of AWS S3 Bucket Regions"
24-
value = "${aws_s3_bucket.this.*.region}"
28+
value = "${aws_s3_bucket.this.*.region}"
2529
}
2630

2731
#aws_s3_bucket_object.this.id
2832
#aws_s3_bucket_object.this.etag
2933
#aws_s3_bucket_object.this.version_id
34+

test/main.tf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
module "s3-none" {
32
source = ".."
43
names = []

test/variables.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
variable "environment" {
22
default = "dev"
33
}
4+
45
variable "organization" {
56
default = "testorg"
67
}
8+
79
variable "region" {
810
default = "us-west-2"
911
}

variables.tf

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
1-
2-
31
// Standard Variables
42

53
variable "names" {
64
description = "List of S3 bucket names"
75
type = "list"
86
}
7+
98
variable "environment" {
109
description = "Environment (ex: dev, qa, stage, prod)"
1110
}
11+
1212
variable "namespaced" {
1313
description = "Namespace all resources (prefixed with the environment)?"
1414
default = true
1515
}
16+
1617
variable "tags" {
1718
description = "A map of tags to add to all resources"
1819
default = {}
1920
}
21+
2022
variable "org" {
2123
description = "Organization name to prefix S3 buckets with"
2224
}
@@ -32,10 +34,12 @@ variable "principal" {
3234
description = "principal"
3335
default = "*"
3436
}
37+
3538
variable "public" {
3639
description = "Allow public read access to bucket"
3740
default = false
3841
}
42+
3943
variable "versioned" {
4044
description = "Version the bucket"
4145
default = false

0 commit comments

Comments
 (0)