Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: allowing the consumer to use account id #24

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .commitlintrc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
rules:
body-leading-blank: [1, always]
body-max-line-length: [2, always, 100]
footer-leading-blank: [1, always]
footer-max-line-length: [2, always, 100]
header-max-length: [2, always, 100]
subject-case:
- 2
- never
- [sentence-case, start-case, pascal-case, upper-case]
subject-empty: [2, never]
subject-full-stop: [2, never, "."]
type-case: [2, always, lower-case]
type-empty: [2, never]
type-enum:
- 2
- always
- [build, chore, ci, docs, feat, fix, perf, refactor, revert, style, test]
10 changes: 5 additions & 5 deletions .tflint.hcl
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
plugin "aws" {
enabled = true
version = "0.30.0"
version = "0.32.0"
source = "github.com/terraform-linters/tflint-ruleset-aws"
}

plugin "terraform" {
enabled = true
version = "0.7.0"
source = "github.com/terraform-linters/tflint-ruleset-terraform"
enabled = true
version = "0.7.0"
source = "github.com/terraform-linters/tflint-ruleset-terraform"
}

config {
call_module_type = "local"
force = false
force = false
}

rule "terraform_required_providers" {
Expand Down
31 changes: 28 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,22 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
.PHONY: all security lint format documentation documentation-examples validate-all validate validate-examples init examples
.PHONY: all security lint format documentation documentation-examples validate-all validate validate-examples init examples tests

default: all

all:
$(MAKE) init
$(MAKE) validate
$(MAKE) tests
$(MAKE) lint
$(MAKE) security
$(MAKE) format
$(MAKE) documentation

examples:
$(MAKE) validate-examples
$(MAKE) tests
$(MAKE) lint-examples
$(MAKE) lint
$(MAKE) security
Expand All @@ -50,6 +52,19 @@ documentation-examples:
find examples -type d -mindepth 1 -maxdepth 1 -exec terraform-docs markdown table --output-file README.md --output-mode inject {} \; ; \
fi

upgrade-terraform-providers:
@printf "%s Upgrading Terraform providers for %-24s" "-->" "."
@terraform init -upgrade >/dev/null && echo "[OK]" || echo "[FAILED]"
@$(MAKE) upgrade-terraform-example-providers

upgrade-terraform-example-providers:
@if [ -d examples ]; then \
find examples -type d -mindepth 1 -maxdepth 1 | while read -r dir; do \
printf "%s Upgrading Terraform providers for %-24s" "-->" "$$dir"; \
terraform -chdir=$$dir init -upgrade >/dev/null && echo "[OK]" || echo "[FAILED]"; \
done; \
fi

init:
@echo "--> Running terraform init"
@terraform init -backend=false
Expand All @@ -65,7 +80,7 @@ security-modules:
@if [ -d modules ]; then \
find modules -type d -mindepth 1 -maxdepth 1 | while read -r dir; do \
echo "--> Validating $$dir"; \
trivy config $$dir; \
trivy config --format table --exit-code 1 --severity CRITICAL,HIGH --ignorefile .trivyignore $$dir; \
done; \
fi

Expand All @@ -74,16 +89,21 @@ security-examples:
@if [ -d examples ]; then \
find examples -type d -mindepth 1 -maxdepth 1 | while read -r dir; do \
echo "--> Validating $$dir"; \
trivy config $$dir; \
trivy config --format table --exit-code 1 --severity CRITICAL,HIGH --ignorefile .trivyignore $$dir; \
done; \
fi

tests:
@echo "--> Running Terraform Tests"
@terraform test

validate:
@echo "--> Running terraform validate"
@terraform init -backend=false
@terraform validate
$(MAKE) validate-modules
$(MAKE) validate-examples
$(MAKE) validate-commits

validate-modules:
@echo "--> Running terraform validate on modules"
Expand All @@ -105,6 +125,11 @@ validate-examples:
done; \
fi

validate-commits:
@echo "--> Running commitlint against the main branch"
@command -v commitlint >/dev/null 2>&1 || { echo "commitlint is not installed. Please install it by running 'npm install -g commitlint'"; exit 1; }
@git log --pretty=format:"%s" origin/main..HEAD | commitlint --from=origin/main

lint:
@echo "--> Running tflint"
@tflint --init
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ No modules.
| Name | Type |
|------|------|
| [aws_cloudformation_stack_set.stackset](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudformation_stack_set) | resource |
| [aws_cloudformation_stack_set_instance.account](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudformation_stack_set_instance) | resource |
| [aws_cloudformation_stack_set_instance.ou](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudformation_stack_set_instance) | resource |
| [aws_region.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/region) | data source |

Expand All @@ -33,6 +34,7 @@ No modules.
| <a name="input_name"></a> [name](#input\_name) | The name of the cloudformation stack | `string` | n/a | yes |
| <a name="input_tags"></a> [tags](#input\_tags) | The tags to apply to the cloudformation stack | `map(string)` | n/a | yes |
| <a name="input_template"></a> [template](#input\_template) | The body of the cloudformation template to deploy | `string` | n/a | yes |
| <a name="input_account_ids"></a> [account\_ids](#input\_account\_ids) | The account ids to deploy the stackset to | `list(string)` | `[]` | no |
| <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 |
| <a name="input_failure_tolerance_count"></a> [failure\_tolerance\_count](#input\_failure\_tolerance\_count) | The number of failures that are tolerated before the stack operation is stopped | `number` | `0` | no |
| <a name="input_max_concurrent_count"></a> [max\_concurrent\_count](#input\_max\_concurrent\_count) | The maximum number of concurrent deployments | `number` | `10` | no |
Expand Down
13 changes: 12 additions & 1 deletion main.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@


# tfsec:ignore:aws-iam-no-policy-wildcards
resource "aws_cloudformation_stack_set" "stackset" {
name = var.name
Expand Down Expand Up @@ -38,3 +37,15 @@ resource "aws_cloudformation_stack_set_instance" "ou" {
organizational_unit_ids = [each.value]
}
}

## Deploy the stackset to the following account ids
resource "aws_cloudformation_stack_set_instance" "account" {
count = length(var.account_ids) ? 1 : 0

region = local.region
stack_set_name = aws_cloudformation_stack_set.stackset.name

deployment_targets {
accounts = var.account_ids
}
}
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ variable "organizational_units" {
default = []
}

variable "account_ids" {
description = "The account ids to deploy the stackset to"
type = list(string)
default = []
}

variable "tags" {
description = "The tags to apply to the cloudformation stack"
type = map(string)
Expand Down
Loading