From fbc331c5982cb3433c67232f9e2f94de25b89e7a Mon Sep 17 00:00:00 2001 From: Rohith Jayawardene Date: Sun, 27 Oct 2024 08:59:52 +0000 Subject: [PATCH] chore(deps): updating inline with the upstream template --- .commitlintrc.yaml | 19 +++ .gitignore | 9 ++ .terraform-docs.yaml => .terraform-docs.yml | 15 ++- .tflint.hcl | 12 +- Makefile | 126 +++++++++++--------- README.md | 41 ------- examples/basic/README.md | 18 --- examples/basic/assets/README.md | 13 ++ examples/basic/values/README.md | 13 ++ 9 files changed, 143 insertions(+), 123 deletions(-) create mode 100644 .commitlintrc.yaml rename .terraform-docs.yaml => .terraform-docs.yml (74%) create mode 100644 examples/basic/assets/README.md create mode 100644 examples/basic/values/README.md diff --git a/.commitlintrc.yaml b/.commitlintrc.yaml new file mode 100644 index 0000000..70a3ab0 --- /dev/null +++ b/.commitlintrc.yaml @@ -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] diff --git a/.gitignore b/.gitignore index 5f401a8..442367b 100755 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,12 @@ terraform.rc .DS_Store todo.md +# Ignore vim swap files +*.swp +*.swo + +# Irgnore meld diff files +*.orig +*.backup +*.rej + diff --git a/.terraform-docs.yaml b/.terraform-docs.yml similarity index 74% rename from .terraform-docs.yaml rename to .terraform-docs.yml index c955165..0c044ad 100644 --- a/.terraform-docs.yaml +++ b/.terraform-docs.yml @@ -1,4 +1,3 @@ -formatter: markdown #header-from: .header.md settings: anchor: true @@ -12,10 +11,18 @@ settings: type: true lockfile: false -sort: - enabled: true - by: required +formatter: "markdown table" output: file: README.md mode: inject + +sections: + show: + - providers + - inputs + - outputs + +sort: + enabled: true + by: required diff --git a/.tflint.hcl b/.tflint.hcl index a807c63..ea9c639 100644 --- a/.tflint.hcl +++ b/.tflint.hcl @@ -1,12 +1,18 @@ plugin "aws" { enabled = true - version = "0.30.0" + version = "0.34.0" source = "github.com/terraform-linters/tflint-ruleset-aws" } +plugin "terraform" { + enabled = true + version = "0.9.1" + source = "github.com/terraform-linters/tflint-ruleset-terraform" +} + config { - module = true - force = false + call_module_type = "local" + force = false } rule "terraform_required_providers" { diff --git a/Makefile b/Makefile index b15f043..2045b2f 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,4 @@ # -# Copyright (C) 2024 Appvia Ltd -# # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 @@ -14,43 +12,59 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . # -AUTHOR_EMAIL=info@appvia.io - -.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: - @echo "--> Running examples" - $(MAKE) documentation - $(MAKE) validate-examples +examples: + $(MAKE) validate-examples + $(MAKE) tests $(MAKE) lint-examples - $(MAKE) security-examples + $(MAKE) lint + $(MAKE) security + $(MAKE) format + $(MAKE) documentation documentation: @echo "--> Generating documentation" - @terraform-docs markdown table --output-file ${PWD}/README.md --output-mode inject . + @terraform-docs . $(MAKE) documentation-modules $(MAKE) documentation-examples documentation-modules: @echo "--> Generating documentation for modules" - @if [ -d modules ]; then \ - find modules -type d -mindepth 1 -maxdepth 1 -exec terraform-docs markdown table --output-file README.md --output-mode inject {} \; ; \ - fi + @find . -type d -regex '.*/modules/[a-za-z\-_$$]*' -not -path '*.terraform*' 2>/dev/null | while read -r dir; do \ + echo "--> Generating documentation for module: $$dir"; \ + terraform-docs $$dir; \ + done; documentation-examples: - @echo "--> Generating documentation examples" + @echo "--> Generating documentation for examples" + @find . -type d -path '*/examples/*' -not -path '*.terraform*' 2>/dev/null| while read -r dir; do \ + echo "--> Generating documentation for example: $$dir"; \ + terraform-docs $$dir; \ + done; + +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 -exec terraform-docs markdown table --output-file README.md --output-mode inject {} \; ; \ + find examples -type d -mindepth 1 -maxdepth 1 2>/dev/null | 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: @@ -65,21 +79,21 @@ security: security-modules: @echo "--> Running Security checks on modules" - @if [ -d modules ]; then \ - find modules -type d -mindepth 1 -maxdepth 1 | while read -r dir; do \ - echo "--> Validating $$dir"; \ - trivy config $$dir; \ - done; \ - fi + @find . -type d -regex '.*/modules/[a-zA-Z\-_$$]*' -not -path '*.terraform*' 2>/dev/null | while read -r dir; do \ + echo "--> Validating $$dir"; \ + trivy config --format table --exit-code 1 --severity CRITICAL,HIGH --ignorefile .trivyignore $$dir; \ + done; security-examples: @echo "--> Running Security checks on examples" - @if [ -d examples ]; then \ - find examples -type d -mindepth 1 -maxdepth 1 | while read -r dir; do \ - echo "--> Validating $$dir"; \ - trivy config $$dir; \ - done; \ - fi + @find . -type d -path '*/examples/*' -not -path '*.terraform*' 2>/dev/null | while read -r dir; do \ + echo "--> Validating $$dir"; \ + trivy config --format table --exit-code 1 --severity CRITICAL,HIGH --ignorefile .trivyignore $$dir; \ + done; + +tests: + @echo "--> Running Terraform Tests" + @terraform test validate: @echo "--> Running terraform validate" @@ -87,26 +101,28 @@ validate: @terraform validate $(MAKE) validate-modules $(MAKE) validate-examples + $(MAKE) validate-commits validate-modules: @echo "--> Running terraform validate on modules" - @if [ -d modules ]; then \ - find modules -type d -mindepth 1 -maxdepth 1 | while read -r dir; do \ - echo "--> Validating $$dir"; \ - terraform -chdir=$$dir init -backend=false; \ - terraform -chdir=$$dir validate; \ - done; \ - fi + @find . -type d -regex '.*/modules/[a-zA-Z\-_$$]*' -not -path '*.terraform*' 2>/dev/null | while read -r dir; do \ + echo "--> Validating Module $$dir"; \ + terraform -chdir=$$dir init -backend=false; \ + terraform -chdir=$$dir validate; \ + done; validate-examples: @echo "--> Running terraform validate on examples" - @if [ -d examples ]; then \ - find examples -type d -mindepth 1 -maxdepth 1 | while read -r dir; do \ - echo "--> Validating $$dir"; \ - terraform -chdir=$$dir init -backend=false; \ - terraform -chdir=$$dir validate; \ - done; \ - fi + @find . -type d -path '*/examples/*' -not -path '*.terraform*' 2>/dev/null | while read -r dir; do \ + echo "--> Validating $$dir"; \ + terraform -chdir=$$dir init -backend=false; \ + terraform -chdir=$$dir validate; \ + done; + +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" @@ -117,23 +133,19 @@ lint: lint-modules: @echo "--> Running tflint on modules" - @if [ -d modules ]; then \ - find modules -type d -mindepth 1 -maxdepth 1 | while read -r dir; do \ - echo "--> Linting $$dir"; \ - tflint --chdir=$$dir --init; \ - tflint --chdir=$$dir -f compact; \ - done; \ - fi + @find . -type d -regex '.*/modules/[a-zA-Z\-_$$]*' -not -path '*.terraform*' 2>/dev/null | while read -r dir; do \ + echo "--> Linting $$dir"; \ + tflint --chdir=$$dir --init; \ + tflint --chdir=$$dir -f compact; \ + done; lint-examples: @echo "--> Running tflint on examples" - @if [ -d examples ]; then \ - find examples -type d -mindepth 1 -maxdepth 1 | while read -r dir; do \ - echo "--> Linting $$dir"; \ - tflint --chdir=$$dir --init; \ - tflint --chdir=$$dir -f compact; \ - done; \ - fi + @find . -type d -path '*/examples/*' -not -path '*.terraform*' 2>/dev/null | while read -r dir; do \ + echo "--> Linting $$dir"; \ + tflint --chdir=$$dir --init; \ + tflint --chdir=$$dir -f compact; \ + done; format: @echo "--> Running terraform fmt" @@ -141,7 +153,7 @@ format: clean: @echo "--> Cleaning up" - @find . -type d -name ".terraform" | while read -r dir; do \ + @find . -type d -name ".terraform" 2>/dev/null | while read -r dir; do \ echo "--> Removing $$dir"; \ rm -rf $$dir; \ done diff --git a/README.md b/README.md index 64724ad..504826a 100644 --- a/README.md +++ b/README.md @@ -82,13 +82,6 @@ The `terraform-docs` utility is used to generate this README. Follow the below s To enable the Cora Data Exports, please see https://catalog.workshops.aws/awscid/en-US/dashboards/additional/cora for more information, you simply have to enable the `var.enable_cora_data_exports`. This will deploy an additional [cloudformation](./assets/cloudformation/cudos/data-exports-aggregation.yaml) with the management account. -## Requirements - -| Name | Version | -|------|---------| -| [terraform](#requirement\_terraform) | >= 1.0 | -| [aws](#requirement\_aws) | ~> 5.0 | - ## Providers | Name | Version | @@ -97,40 +90,6 @@ To enable the Cora Data Exports, please see https://catalog.workshops.aws/awscid | [aws.cost\_analysis](#provider\_aws.cost\_analysis) | ~> 5.0 | | [aws.management](#provider\_aws.management) | ~> 5.0 | -## Modules - -| Name | Source | Version | -|------|--------|---------| -| [cloudformation\_bucket](#module\_cloudformation\_bucket) | terraform-aws-modules/s3-bucket/aws | 4.1.2 | -| [collector](#module\_collector) | github.com/aws-samples/aws-cudos-framework-deployment//terraform-modules/cur-setup-destination | 0.3.10 | -| [dashboard\_bucket](#module\_dashboard\_bucket) | terraform-aws-modules/s3-bucket/aws | 4.1.2 | -| [dashboards](#module\_dashboards) | github.com/aws-samples/aws-cudos-framework-deployment//terraform-modules/cid-dashboards | 0.3.10 | -| [source](#module\_source) | github.com/aws-samples/aws-cudos-framework-deployment//terraform-modules/cur-setup-source | 0.3.10 | - -## Resources - -| Name | Type | -|------|------| -| [aws_cloudformation_stack.cora_data_export_collector](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudformation_stack) | resource | -| [aws_cloudformation_stack.core_data_export_management](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudformation_stack) | resource | -| [aws_cloudformation_stack.cudos_data_collection](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudformation_stack) | resource | -| [aws_cloudformation_stack.cudos_read_permissions](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudformation_stack) | resource | -| [aws_iam_role.cudos_sso](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role) | resource | -| [aws_iam_saml_provider.saml](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_saml_provider) | resource | -| [aws_quicksight_account_subscription.subscription](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/quicksight_account_subscription) | resource | -| [aws_quicksight_group.groups](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/quicksight_group) | resource | -| [aws_quicksight_group_membership.members](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/quicksight_group_membership) | resource | -| [aws_quicksight_user.users](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/quicksight_user) | resource | -| [aws_s3_object.cloudformation_templates](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_object) | resource | -| [aws_caller_identity.cost_analysis](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) | data source | -| [aws_caller_identity.management](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) | data source | -| [aws_iam_policy_document.cudos_sso](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source | -| [aws_iam_policy_document.cudos_sso_permissions](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source | -| [aws_iam_policy_document.dashboards_bucket_policy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source | -| [aws_iam_policy_document.stack_bucket_policy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source | -| [aws_organizations_organization.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/organizations_organization) | data source | -| [aws_region.cost_analysis](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/region) | data source | - ## Inputs | Name | Description | Type | Default | Required | diff --git a/examples/basic/README.md b/examples/basic/README.md index 3f7a6a4..9e67613 100644 --- a/examples/basic/README.md +++ b/examples/basic/README.md @@ -1,26 +1,8 @@ -## Requirements - -| Name | Version | -|------|---------| -| [terraform](#requirement\_terraform) | >= 1.0.0 | -| [aws](#requirement\_aws) | >= 5.0.0 | -| [awscc](#requirement\_awscc) | >= 0.11.0 | - ## Providers No providers. -## Modules - -| Name | Source | Version | -|------|--------|---------| -| [cudos\_framework](#module\_cudos\_framework) | ../.. | n/a | - -## Resources - -No resources. - ## Inputs | Name | Description | Type | Default | Required | diff --git a/examples/basic/assets/README.md b/examples/basic/assets/README.md new file mode 100644 index 0000000..977ad79 --- /dev/null +++ b/examples/basic/assets/README.md @@ -0,0 +1,13 @@ + +## Providers + +No providers. + +## Inputs + +No inputs. + +## Outputs + +No outputs. + \ No newline at end of file diff --git a/examples/basic/values/README.md b/examples/basic/values/README.md new file mode 100644 index 0000000..977ad79 --- /dev/null +++ b/examples/basic/values/README.md @@ -0,0 +1,13 @@ + +## Providers + +No providers. + +## Inputs + +No inputs. + +## Outputs + +No outputs. + \ No newline at end of file