Skip to content

Commit 54afb7c

Browse files
committed
feat(guardrails): add module
1 parent 6079c0d commit 54afb7c

5 files changed

Lines changed: 96 additions & 20 deletions

File tree

guardrails/README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Guardrails
2+
3+
## About
4+
5+
This module allows you to setup default guardrails to harden your AWS account with the following features:
6+
7+
- EBS encryption by default
8+
- S3 account wide public block access
9+
- IAM account password policy
10+
11+
## Usage
12+
13+
See `variables.tf` for the full argument reference.
14+
15+
```hcl
16+
module "guardrails" {
17+
source = "github.com/script47/aws-tf-modules/guardrails"
18+
19+
ebs = {
20+
encrypted = true
21+
}
22+
23+
s3 = {
24+
public_access_block = {
25+
enabled = true
26+
block_public_acls = true
27+
block_public_policy = true
28+
ignore_public_acls = true
29+
restrict_public_buckets = true
30+
}
31+
}
32+
33+
iam = {
34+
password_policy = {
35+
36+
}
37+
}
38+
}
39+
```

guardrails/iam.tf

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,14 @@
1-
# aws_iam_account_password_policy
1+
resource "aws_iam_account_password_policy" "this" {
2+
count = var.iam.password_policy.enabled ? 1 : 0
3+
4+
allow_users_to_change_password = var.iam.password_policy.allow_users_to_change_password
5+
password_reuse_prevention = var.iam.password_policy.password_reuse_prevention
6+
hard_expiry = var.iam.password_policy.hard_expiry
7+
max_password_age = var.iam.password_policy.max_password_age
8+
minimum_password_length = var.iam.password_policy.minimum_password_length
9+
10+
require_lowercase_characters = var.iam.password_policy.require_lowercase_characters
11+
require_uppercase_characters = var.iam.password_policy.require_uppercase_characters
12+
require_numbers = var.iam.password_policy.require_numbers
13+
require_symbols = var.iam.password_policy.require_symbols
14+
}

guardrails/providers.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
terraform {
2+
required_version = ">= 1.13"
3+
4+
required_providers {
5+
aws = {
6+
source = "hashicorp/aws"
7+
version = "~> 6"
8+
}
9+
}
10+
}

guardrails/s3.tf

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
resource "aws_s3_account_public_access_block" "this" {
2-
block_public_acls = var.s3.block_public_acls
3-
block_public_policy = var.s3.block_public_policy
4-
ignore_public_acls = var.s3.ignore_public_acls
5-
restrict_public_buckets = var.s3.restrict_public_buckets
2+
count = var.s3.public_access_block.enabled
3+
4+
block_public_acls = var.s3.public_access_block.block_public_acls
5+
block_public_policy = var.s3.public_access_block.block_public_policy
6+
ignore_public_acls = var.s3.public_access_block.ignore_public_acls
7+
restrict_public_buckets = var.s3.public_access_block.restrict_public_buckets
68
}

guardrails/variables.tf

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,41 @@
11
variable "ebs" {
2+
description = "EBS account-level config"
23
type = object({
34
encrypted = optional(bool, true)
45
})
56
default = {}
67
}
78

89
variable "s3" {
10+
description = "S3 account-level config"
911
type = object({
10-
block_public_acls = optional(bool, true)
11-
block_public_policy = optional(bool, true)
12-
ignore_public_acls = optional(bool, true)
13-
restrict_public_buckets = optional(bool, true)
12+
public_access_block = optional(object({
13+
enabled = optional(bool, true)
14+
block_public_acls = optional(bool, true)
15+
block_public_policy = optional(bool, true)
16+
ignore_public_acls = optional(bool, true)
17+
restrict_public_buckets = optional(bool, true)
18+
}), {})
1419
})
1520
default = {}
1621
}
1722

18-
# variable "iam" {
19-
# type = object({
20-
# password_policy = optional(object({
21-
# allow_password_change = optional(bool, true)
22-
# reuse_prevention = optional(bool, true)
23-
# hard_expiry = optional(bool, false)
24-
# max_password_age = optional(number, null)
25-
# min_length = optional(number, 8)
23+
variable "iam" {
24+
description = "IAM account-level config"
25+
type = object({
26+
password_policy = optional(object({
27+
enabled = optional(bool, true)
28+
allow_users_to_change_password = optional(bool, true)
29+
password_reuse_prevention = optional(number, 0)
30+
hard_expiry = optional(bool, false)
31+
max_password_age = optional(number, null)
32+
minimum_password_length = optional(number, 12)
2633

27-
# }), {})
28-
# })
29-
# }
34+
require_lowercase_characters = optional(bool, true)
35+
require_uppercase_characters = optional(bool, true)
36+
require_numbers = optional(bool, true)
37+
require_symbols = optional(bool, true)
38+
}), {})
39+
})
40+
default = {}
41+
}

0 commit comments

Comments
 (0)