Skip to content

Commit 4644e73

Browse files
author
Michael Kania
authored
Merge pull request #19 from trussworks/mk-012-tests
Terratest Plumbing
2 parents 0295e61 + fabfa34 commit 4644e73

File tree

11 files changed

+329
-3
lines changed

11 files changed

+329
-3
lines changed

.dependabot/config.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
version: 1
2+
update_configs:
3+
# Keep go modules up to date, batching pull requests weekly
4+
- package_manager: "go:modules"
5+
directory: "/"
6+
update_schedule: "weekly"
7+
# Apply default reviewer @trussworks/waddlers group to PRs
8+
default_reviewers:
9+
- "trussworks/waddlers"
10+
# Apply dependencies label to PRs
11+
default_labels:
12+
- "dependencies"

.gitignore

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

.golangci.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
linters:
2+
enable:
3+
- gosec
4+
- golint
5+
- gofmt
6+
- goimports

.pre-commit-config.yaml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: git://github.com/pre-commit/pre-commit-hooks
3-
rev: v2.2.3
3+
rev: v2.4.0
44
hooks:
55
- id: check-json
66
- id: check-merge-conflict
@@ -12,12 +12,19 @@ repos:
1212
- id: trailing-whitespace
1313

1414
- repo: git://github.com/igorshubovych/markdownlint-cli
15-
rev: v0.17.0
15+
rev: v0.19.0
1616
hooks:
1717
- id: markdownlint
1818

1919
- repo: git://github.com/antonbabenko/pre-commit-terraform
2020
rev: v1.19.0
2121
hooks:
2222
- id: terraform_docs
23-
- id: terraform_fmt
23+
- id: terraform_fmt
24+
25+
- repo: git://github.com/golangci/golangci-lint
26+
rev: v1.21.0
27+
hooks:
28+
- id: golangci-lint
29+
entry: golangci-lint run --verbose
30+
verbose: true

Makefile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
.PHONY: ensure_pre_commit
2+
ensure_pre_commit: .git/hooks/pre-commit ## Ensure pre-commit is installed
3+
.git/hooks/pre-commit: /usr/local/bin/pre-commit
4+
pre-commit install
5+
pre-commit install-hooks
6+
7+
.PHONY: pre_commit_tests
8+
pre_commit_tests: ensure_pre_commit ## Run pre-commit tests
9+
pre-commit run --all-files
10+
11+
.PHONY: test
12+
test: pre_commit_tests
13+
go test -v -timeout 90m ./test/...
14+
15+
.PHONY: clean
16+
clean:
17+
rm -f .*.stamp

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ The following AWS Config Rules are supported:
1313
* rds-storage-encrypted: Checks whether storage encryption is enabled for your RDS DB instances.
1414
* s3-bucket-public-write-prohibited: Checks that your S3 buckets do not allow public write access.
1515

16+
## Terraform Versions
17+
18+
Terraform 0.12. Pin module version to ~> 2.x Submit pull-requests to master branch.
19+
20+
Terraform 0.11. Pin module version to ~> 1.5.1. Submit pull-requests to terraform011 branch.
21+
1622
## Usage
1723

1824
```hcl
@@ -49,3 +55,27 @@ module "aws_config" {
4955
| password\_reuse\_prevention | Number of passwords before allowing reuse. | string | `"24"` | no |
5056

5157
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
58+
59+
## Developer Setup
60+
61+
Install dependencies (macOS)
62+
63+
```shell
64+
brew install pre-commit go terraform terraform-docs
65+
```
66+
67+
### Testing
68+
69+
[Terratest](https://github.com/gruntwork-io/terratest) is being used for
70+
automated testing with this module. Tests in the `test` folder can be run
71+
locally by running the following command:
72+
73+
```text
74+
make test
75+
```
76+
77+
Or with aws-vault:
78+
79+
```text
80+
AWS_VAULT_KEYCHAIN_NAME=<NAME> aws-vault exec <PROFILE> -- make test
81+
```

examples/simple/main.tf

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#
2+
# AWS Config Logs Bucket
3+
#
4+
5+
module "config_logs" {
6+
source = "trussworks/logs/aws"
7+
version = "~> 3"
8+
9+
s3_bucket_name = "${var.config_logs_bucket}"
10+
region = "${var.region}"
11+
allow_config = "true"
12+
config_logs_prefix = "config"
13+
}
14+
15+
module "config" {
16+
source = "../../"
17+
18+
config_logs_bucket = "${module.config_logs.aws_logs_bucket}"
19+
config_logs_prefix = "config"
20+
}

examples/simple/variables.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
variable "config_logs_bucket" {
2+
type = "string"
3+
}
4+
5+
variable "region" {
6+
type = "string"
7+
}

go.mod

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module github.com/trussworks/terraform-aws-config
2+
3+
go 1.13
4+
5+
require github.com/gruntwork-io/terratest v0.22.2

go.sum

Lines changed: 183 additions & 0 deletions
Large diffs are not rendered by default.

test/terraform_aws_config_test.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package test
2+
3+
import (
4+
"fmt"
5+
"strings"
6+
"testing"
7+
8+
"github.com/gruntwork-io/terratest/modules/aws"
9+
"github.com/gruntwork-io/terratest/modules/random"
10+
"github.com/gruntwork-io/terratest/modules/terraform"
11+
)
12+
13+
func TestTerraformAwsConfig(t *testing.T) {
14+
t.Parallel()
15+
16+
expectedConfigLogsBucket := fmt.Sprintf("terratest-aws-config-%s", strings.ToLower(random.UniqueId()))
17+
awsRegion := aws.GetRandomStableRegion(t, nil, nil)
18+
19+
terraformOptions := &terraform.Options{
20+
TerraformDir: "../examples/simple/",
21+
Vars: map[string]interface{}{
22+
"region": awsRegion,
23+
"config_logs_bucket": expectedConfigLogsBucket,
24+
},
25+
EnvVars: map[string]string{
26+
"AWS_DEFAULT_REGION": awsRegion,
27+
},
28+
}
29+
30+
defer terraform.Destroy(t, terraformOptions)
31+
terraform.InitAndApply(t, terraformOptions)
32+
33+
// Empty config_logs_bucket before terraform destroy
34+
aws.EmptyS3Bucket(t, awsRegion, expectedConfigLogsBucket)
35+
}

0 commit comments

Comments
 (0)