Skip to content

Commit ad62d4f

Browse files
authored
feat: adding thee ability to define the organizational units (#33)
1 parent c32d059 commit ad62d4f

9 files changed

+89
-55
lines changed

.commitlintrc.yaml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
rules:
3+
body-leading-blank: [1, always]
4+
body-max-line-length: [2, always, 100]
5+
footer-leading-blank: [1, always]
6+
footer-max-line-length: [2, always, 100]
7+
header-max-length: [2, always, 100]
8+
subject-case:
9+
- 2
10+
- never
11+
- [sentence-case, start-case, pascal-case, upper-case]
12+
subject-empty: [2, never]
13+
subject-full-stop: [2, never, "."]
14+
type-case: [2, always, lower-case]
15+
type-empty: [2, never]
16+
type-enum:
17+
- 2
18+
- always
19+
- [build, chore, ci, docs, feat, fix, perf, refactor, revert, style, test]

.terraform-docs.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
formatter: markdown
2-
#header-from: .header.md
32
settings:
43
anchor: true
54
color: true

.tflint.hcl

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
plugin "aws" {
22
enabled = true
3-
version = "0.32.0"
3+
version = "0.33.0"
44
source = "github.com/terraform-linters/tflint-ruleset-aws"
55
}
66

77
plugin "terraform" {
88
enabled = true
9-
version = "0.7.0"
9+
version = "0.9.1"
1010
source = "github.com/terraform-linters/tflint-ruleset-terraform"
1111
}
1212

Makefile

+15-45
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
#
2-
# Copyright (C) 2024 Appvia Ltd <[email protected]>
3-
#
42
# This program is free software; you can redistribute it and/or
53
# modify it under the terms of the GNU General Public License
64
# as published by the Free Software Foundation; either version 2
@@ -14,9 +12,8 @@
1412
# You should have received a copy of the GNU General Public License
1513
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1614
#
17-
AUTHOR_EMAIL[email protected]
1815

19-
.PHONY: all security lint format documentation documentation-examples validate-all validate validate-examples init
16+
.PHONY: all security lint format documentation validate init commitlint
2017

2118
default: all
2219

@@ -31,65 +28,38 @@ all:
3128
documentation:
3229
@echo "--> Generating documentation"
3330
@terraform-docs markdown table --output-file ${PWD}/README.md --output-mode inject .
34-
$(MAKE) documentation-examples
35-
36-
documentation-examples:
37-
@echo "--> Generating documentation examples"
38-
@find examples -type d -mindepth 1 -maxdepth 1 -exec terraform-docs markdown table --output-file README.md --output-mode inject {} \;
3931

4032
init:
4133
@echo "--> Running terraform init"
4234
@terraform init -backend=false
4335

4436
security:
4537
@echo "--> Running Security checks"
46-
@trivy config .
47-
$(MAKE) security-examples
48-
49-
security-examples:
50-
@echo "--> Running Security checks on examples"
51-
@find examples -type d -mindepth 1 -maxdepth 1 | while read -r dir; do \
52-
echo "--> Validating $$dir"; \
53-
trivy config $$dir; \
54-
done
55-
56-
validate-all:
57-
@echo "--> Running all validation checks"
58-
$(MAKE) validate
59-
$(MAKE) validate-examples
60-
61-
validate:
62-
@echo "--> Running terraform validate"
63-
@terraform init -backend=false
64-
@terraform validate
65-
$(MAKE) validate-examples
38+
trivy config --format table --exit-code 1 --severity CRITICAL,HIGH --ignorefile .trivyignore .
6639

67-
validate-examples:
68-
@echo "--> Running terraform validate on examples"
69-
@find examples -type d -mindepth 1 -maxdepth 1 | while read -r dir; do \
70-
echo "--> Validating $$dir"; \
71-
terraform -chdir=$$dir init; \
72-
terraform -chdir=$$dir validate; \
73-
done
40+
commitlint:
41+
@echo "--> Running commitlint against the main branch"
42+
@command -v commitlint >/dev/null 2>&1 || { echo "commitlint is not installed. Please install it by running 'npm install -g commitlint'"; exit 1; }
43+
@git log --pretty=format:"%s" origin/main..HEAD | commitlint --from=origin/main
7444

7545
lint:
7646
@echo "--> Running tflint"
7747
@tflint --init
7848
@tflint -f compact
79-
$(MAKE) lint-examples
80-
81-
lint-examples:
82-
@echo "--> Running tflint on examples"
83-
@find examples -type d -mindepth 1 -maxdepth 1 | while read -r dir; do \
84-
echo "--> Linting $$dir"; \
85-
tflint --chdir=$$dir --init; \
86-
tflint --chdir=$$dir -f compact; \
87-
done
8849

8950
format:
9051
@echo "--> Running terraform fmt"
9152
@terraform fmt -recursive -write=true
9253

54+
validate:
55+
@echo "--> Running terraform validate"
56+
@terraform init -backend=false
57+
@terraform validate
58+
$(MAKE) lint
59+
$(MAKE) commitlint
60+
$(MAKE) format
61+
$(MAKE) security
62+
9363
clean:
9464
@echo "--> Cleaning up"
9565
@find . -type d -name ".terraform" | while read -r dir; do \

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ No modules.
8282
| <a name="input_capabilities"></a> [capabilities](#input\_capabilities) | The capabilities required to deploy the cloudformation template | `list(string)` | <pre>[<br/> "CAPABILITY_NAMED_IAM",<br/> "CAPABILITY_AUTO_EXPAND",<br/> "CAPABILITY_IAM"<br/>]</pre> | no |
8383
| <a name="input_enable_management_account"></a> [enable\_management\_account](#input\_enable\_management\_account) | Enable the deployment to the management account | `bool` | `false` | no |
8484
| <a name="input_max_concurrent_count"></a> [max\_concurrent\_count](#input\_max\_concurrent\_count) | The maximum number of concurrent deployments | `number` | `10` | no |
85+
| <a name="input_organization_units"></a> [organization\_units](#input\_organization\_units) | A list of organization units to deploy the boundary (defaults to all organization units) | `list(string)` | `[]` | no |
8586
| <a name="input_parameters"></a> [parameters](#input\_parameters) | The parameters to pass to the cloudformation template | `map(string)` | `{}` | no |
8687

8788
## Outputs

examples/basic/main.tf

+36-6
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,41 @@
77
module "boundary" {
88
source = "../.."
99

10-
description = "Used to deploy the default permissions boundary for the pipelines."
10+
## The description of the cloudformation stack
11+
description = "Used to deploy the default permissions boundary for the pipelines."
12+
## Enable the deployment to the management account as well
1113
enable_management_account = true
12-
name = "LZA-IAM-DefaultBoundary"
13-
region = "us-west-2"
14-
tags = {}
15-
template = file("assets/default-boundary.yml")
16-
parameters = {}
14+
## The name of the cloudformation stack
15+
name = "LZA-IAM-DefaultBoundary-Sandbox"
16+
## The region to deploy the cloudformation template
17+
region = "us-west-2"
18+
## The tags to apply to the cloudformation stack
19+
tags = {}
20+
## The cloudformation template to deploy
21+
template = file("assets/default-boundary.yml")
22+
## Parameters passed to the cloudformation template
23+
parameters = {}
24+
## Optional list of organization units to deploy the boundary, else defaults to all organization units
25+
}
26+
27+
## Deploy the boundary to a specific organization unit
28+
module "boundary_by_organization" {
29+
source = "../.."
30+
31+
## The description of the cloudformation stack
32+
description = "Used to deploy the default permissions boundary for the pipelines."
33+
## Enable the deployment to the management account as well
34+
enable_management_account = true
35+
## The name of the cloudformation stack
36+
name = "LZA-IAM-DefaultBoundary-Sandbox"
37+
## The region to deploy the cloudformation template
38+
region = "us-west-2"
39+
## The tags to apply to the cloudformation stack
40+
tags = {}
41+
## The cloudformation template to deploy
42+
template = file("assets/default-boundary.yml")
43+
## Parameters passed to the cloudformation template
44+
parameters = {}
45+
## Optional list of organization units to deploy the boundary, else defaults to all organization units
46+
organization_units = ["ou-1234567890"]
1747
}

locals.tf

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
locals {
3+
## The root organization unit
4+
root_organization_unit = data.aws_organizations_organization.current.roots[0].id
5+
6+
## The organization units to deploy the boundary - defaults to all organization units if the
7+
## organization_units variable is not set
8+
organizational_units = length(var.organization_units) > 0 ? var.organization_units : [local.root_organization_unit]
9+
}

main.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ resource "aws_cloudformation_stack_set" "boundary" {
3232
## Deploy the permissive boundary to the organizational root
3333
resource "aws_cloudformation_stack_set_instance" "root" {
3434
deployment_targets {
35-
organizational_unit_ids = [data.aws_organizations_organization.current.roots[0].id]
35+
organizational_unit_ids = local.organizational_units
3636
}
3737
region = var.region
3838
stack_set_name = aws_cloudformation_stack_set.boundary.name

variables.tf

+6
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ variable "enable_management_account" {
1515
default = false
1616
}
1717

18+
variable "organization_units" {
19+
description = "A list of organization units to deploy the boundary (defaults to all organization units)"
20+
type = list(string)
21+
default = []
22+
}
23+
1824
variable "max_concurrent_count" {
1925
description = "The maximum number of concurrent deployments"
2026
type = number

0 commit comments

Comments
 (0)