diff --git a/.circleci/config.yml b/.circleci/config.yml index 2667922..da9833b 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -2,7 +2,7 @@ version: 2.1 jobs: # - # Test 1 & Test 2 + # Automated Tests # test-static-code-and-linting: machine: @@ -26,8 +26,27 @@ jobs: git update-index --assume-unchanged "Makefile" - run: - name: test1-terraform-format - command: make format-check + name: test-terraform-format-and-docs + command: | + # + # Install pre-commit + pip install pre-commit + # + # Install terraform + sudo apt-get install unzip + wget https://releases.hashicorp.com/terraform/${TERRAFORM_VER}/terraform_${TERRAFORM_VER}_linux_amd64.zip + unzip terraform_${TERRAFORM_VER}_linux_amd64.zip + sudo mv terraform /usr/local/bin/ + terraform --version + # + # Install terraform-docs + sudo apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main" + curl -Lo ./terraform-docs https://github.com/terraform-docs/terraform-docs/releases/download/v0.10.1/terraform-docs-v0.10.1-$(uname | tr '[:upper:]' '[:lower:]')-amd64 + chmod +x ./terraform-docs + sudo mv ./terraform-docs /usr/local/bin/terraform-docs + # + # Run tests + make pre-commit - run: name: Install awscli @@ -55,11 +74,81 @@ jobs: cp /home/circleci/.aws/config /home/circleci/.aws/bb/config - run: - name: test2-terraform-linting + name: test-terraform-linting command: make tflint-deep + - slack/notify: + event: fail + mentions: '@leverage-support' + custom: | + { + "blocks": [ + { + "type": "header", + "text": { + "type": "plain_text", + "text": "Failed Pipeline! :rotating_light::fire::bash-fire::bangbang::video-games-doom-mad::stopp:", + "emoji": true + } + }, + { + "type": "section", + "text": { + "type": "mrkdwn", + "text": ":negative_squared_cross_mark: *Project*: $CIRCLE_PROJECT_REPONAME \n :negative_squared_cross_mark: *User*: $CIRCLE_USERNAME \n :negative_squared_cross_mark: *Job*: $CIRCLE_JOB in *repo* $CIRCLE_PROJECT_REPONAME \n :negative_squared_cross_mark: *Branch:* $CIRCLE_BRANCH \n :negative_squared_cross_mark: *PR:* $CIRCLE_PULL_REQUEST \n :negative_squared_cross_mark: *Last Commit:* $CIRCLE_SHA1" + }, + "accessory": { + "type": "button", + "text": { + "type": "plain_text", + "text": ":arrow_forward: View Job in CircleCi", + "emoji": true + }, + "value": "click_me_123", + "url": "$CIRCLE_BUILD_URL", + "action_id": "button-action" + } + } + ] + } + channel: 'tools-ci' + - slack/notify: + event: pass + custom: | + { + "blocks": [ + { + "type": "header", + "text": { + "type": "plain_text", + "text": "Successful Pipeline! :checkered_flag: :video-games-star: :video-games-mario-luigi-dance: :tada: :binbash::bb-leverage: :heart: :open-source:", + "emoji": true + } + }, + { + "type": "section", + "text": { + "type": "mrkdwn", + "text": ":heavy_check_mark: *Project*: $CIRCLE_PROJECT_REPONAME \n :heavy_check_mark: *User*: $CIRCLE_USERNAME \n :heavy_check_mark: *Job*: $CIRCLE_JOB in *repo* $CIRCLE_PROJECT_REPONAME \n :heavy_check_mark: *Branch:* $CIRCLE_BRANCH \n :heavy_check_mark: *PR:* $CIRCLE_PULL_REQUEST \n :heavy_check_mark: *Last Commit:* $CIRCLE_SHA1" + }, + "accessory": { + "type": "button", + "text": { + "type": "plain_text", + "text": ":arrow_forward: View Job in CircleCi", + "emoji": true + }, + "value": "click_me_123", + "url": "$CIRCLE_BUILD_URL", + "action_id": "button-action" + } + } + ] + } + channel: 'tools-ci' + # - # Test 3 + # Tests E2E # test-e2e-terratests: machine: @@ -112,6 +201,76 @@ jobs: name: test3-terratests-go-test command: make terratest-go-test + - slack/notify: + event: fail + mentions: '@leverage-support' + custom: | + { + "blocks": [ + { + "type": "header", + "text": { + "type": "plain_text", + "text": "Failed Pipeline! :rotating_light::fire::bash-fire::bangbang::video-games-doom-mad::stopp:", + "emoji": true + } + }, + { + "type": "section", + "text": { + "type": "mrkdwn", + "text": ":negative_squared_cross_mark: *Project*: $CIRCLE_PROJECT_REPONAME \n :negative_squared_cross_mark: *User*: $CIRCLE_USERNAME \n :negative_squared_cross_mark: *Job*: $CIRCLE_JOB in *repo* $CIRCLE_PROJECT_REPONAME \n :negative_squared_cross_mark: *Branch:* $CIRCLE_BRANCH \n :negative_squared_cross_mark: *PR:* $CIRCLE_PULL_REQUEST \n :negative_squared_cross_mark: *Last Commit:* $CIRCLE_SHA1" + }, + "accessory": { + "type": "button", + "text": { + "type": "plain_text", + "text": ":arrow_forward: View Job in CircleCi", + "emoji": true + }, + "value": "click_me_123", + "url": "$CIRCLE_BUILD_URL", + "action_id": "button-action" + } + } + ] + } + channel: 'tools-ci' + - slack/notify: + event: pass + custom: | + { + "blocks": [ + { + "type": "header", + "text": { + "type": "plain_text", + "text": "Successful Pipeline! :checkered_flag: :video-games-star: :video-games-mario-luigi-dance: :tada: :binbash::bb-leverage: :heart: :open-source:", + "emoji": true + } + }, + { + "type": "section", + "text": { + "type": "mrkdwn", + "text": ":heavy_check_mark: *Project*: $CIRCLE_PROJECT_REPONAME \n :heavy_check_mark: *User*: $CIRCLE_USERNAME \n :heavy_check_mark: *Job*: $CIRCLE_JOB in *repo* $CIRCLE_PROJECT_REPONAME \n :heavy_check_mark: *Branch:* $CIRCLE_BRANCH \n :heavy_check_mark: *PR:* $CIRCLE_PULL_REQUEST \n :heavy_check_mark: *Last Commit:* $CIRCLE_SHA1" + }, + "accessory": { + "type": "button", + "text": { + "type": "plain_text", + "text": ":arrow_forward: View Job in CircleCi", + "emoji": true + }, + "value": "click_me_123", + "url": "$CIRCLE_BUILD_URL", + "action_id": "button-action" + } + } + ] + } + channel: 'tools-ci' + # # Release # @@ -154,12 +313,83 @@ jobs: echo "===============================================================================================" fi + - slack/notify: + event: fail + mentions: '@leverage-support' + custom: | + { + "blocks": [ + { + "type": "header", + "text": { + "type": "plain_text", + "text": "Failed Pipeline! :rotating_light::fire::bash-fire::bangbang::video-games-doom-mad::stopp:", + "emoji": true + } + }, + { + "type": "section", + "text": { + "type": "mrkdwn", + "text": ":negative_squared_cross_mark: *Project*: $CIRCLE_PROJECT_REPONAME \n :negative_squared_cross_mark: *User*: $CIRCLE_USERNAME \n :negative_squared_cross_mark: *Job*: $CIRCLE_JOB in *repo* $CIRCLE_PROJECT_REPONAME \n :negative_squared_cross_mark: *Branch:* $CIRCLE_BRANCH \n :negative_squared_cross_mark: *PR:* $CIRCLE_PULL_REQUEST \n :negative_squared_cross_mark: *Last Commit:* $CIRCLE_SHA1" + }, + "accessory": { + "type": "button", + "text": { + "type": "plain_text", + "text": ":arrow_forward: View Job in CircleCi", + "emoji": true + }, + "value": "click_me_123", + "url": "$CIRCLE_BUILD_URL", + "action_id": "button-action" + } + } + ] + } + channel: 'tools-ci' + - slack/notify: + event: pass + custom: | + { + "blocks": [ + { + "type": "header", + "text": { + "type": "plain_text", + "text": "Successful Pipeline! :checkered_flag: :video-games-star: :video-games-mario-luigi-dance: :tada: :binbash::bb-leverage: :heart: :open-source:", + "emoji": true + } + }, + { + "type": "section", + "text": { + "type": "mrkdwn", + "text": ":heavy_check_mark: *Project*: $CIRCLE_PROJECT_REPONAME \n :heavy_check_mark: *User*: $CIRCLE_USERNAME \n :heavy_check_mark: *Job*: $CIRCLE_JOB in *repo* $CIRCLE_PROJECT_REPONAME \n :heavy_check_mark: *Branch:* $CIRCLE_BRANCH \n :heavy_check_mark: *PR:* $CIRCLE_PULL_REQUEST \n :heavy_check_mark: *Last Commit:* $CIRCLE_SHA1" + }, + "accessory": { + "type": "button", + "text": { + "type": "plain_text", + "text": ":arrow_forward: View Job in CircleCi", + "emoji": true + }, + "value": "click_me_123", + "url": "$CIRCLE_BUILD_URL", + "action_id": "button-action" + } + } + ] + } + channel: 'tools-ci' + # # CircleCI orbs are open-source, shareable packages of parameterizable reusable # configuration elements, including jobs, commands, and executors. # orbs: sumologic: circleci/sumologic@1.0.6 + slack: circleci/slack@4.1.1 # # Jobs workflow @@ -188,5 +418,3 @@ workflows: - master - sumologic/workflow-collector: context: binbashar-org-global-context - requires: - - release-version-with-changelog diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md index c2147ff..02006fd 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -9,7 +9,7 @@ assignees: '' ## Describe the Feature -A clear and concise description of what the bug is. +A clear and concise description of what the bug is. ## Expected Behavior diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 4b8f32d..76399bb 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -3,11 +3,11 @@ * Use bullet points to be concise and to the point. ## why -* Provide the justifications for the changes (e.g. business case). +* Provide the justifications for the changes (e.g. business case). * Describe why these changes were made (e.g. why do these commits fix the problem?) * Use bullet points to be concise and to the point. ## references -* Link to any supporting github issues or helpful documentation to add some context (e.g. stackoverflow). +* Link to any supporting github issues or helpful documentation to add some context (e.g. stackoverflow). * Use `closes #123`, if this PR closes a GitHub issue `#123` diff --git a/.gitignore b/.gitignore index 4d64195..13d59e5 100644 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,7 @@ !/.github !*.gitkeep !*.editorconfig +!*.pre-commit-config.yaml # SSH keys # ############ diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100755 index 0000000..244e8e4 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,24 @@ +default_language_version: + # force all unspecified python hooks to run python3 + python: python3 + +repos: + - repo: git://github.com/pre-commit/pre-commit-hooks + rev: v3.2.0 + hooks: + - id: check-json + - id: check-merge-conflict + - id: check-yaml + - id: detect-private-key + - id: pretty-format-json + args: + - --autofix + - id: trailing-whitespace + args: + - --markdown-linebreak-ext=md + + - repo: git://github.com/antonbabenko/pre-commit-terraform + rev: v1.43.0 + hooks: + - id: terraform_fmt + - id: terraform_docs diff --git a/Makefile b/Makefile index 738abcc..761f3bc 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,7 @@ SHELL := /bin/bash MAKEFILE_PATH := ./Makefile MAKEFILES_DIR := ./@bin/makefiles +MAKEFILES_VER := v0.1.5 help: @echo 'Available Commands:' @@ -13,9 +14,10 @@ help: init-makefiles: ## initialize makefiles rm -rf ${MAKEFILES_DIR} mkdir -p ${MAKEFILES_DIR} - git clone https://github.com/binbashar/le-dev-makefiles.git ${MAKEFILES_DIR} + git clone https://github.com/binbashar/le-dev-makefiles.git ${MAKEFILES_DIR} -q + cd ${MAKEFILES_DIR} && git checkout ${MAKEFILES_VER} -q -include ${MAKEFILES_DIR}/circleci/circleci.mk -include ${MAKEFILES_DIR}/release-mgmt/release.mk --include ${MAKEFILES_DIR}/terraform12/terraform12.mk --include ${MAKEFILES_DIR}/terratest12/terratest12.mk +-include ${MAKEFILES_DIR}/terraform13/terraform13.mk +-include ${MAKEFILES_DIR}/terratest13/terratest13.mk diff --git a/README.md b/README.md index bb82cf5..9e3620a 100644 --- a/README.md +++ b/README.md @@ -20,28 +20,29 @@ If `aws_sns_topic_enabled = true` then you'll still need to subscribe to the cre - **Versions:** `>= 1.x.y` (Terraform 0.12.x compatible -> **WIP**) - eg: https://registry.terraform.io/modules/binbashar/cost-budget/aws/1.0.0 -## Requirements - -| Name | Version | -|------|---------| -| terraform | >= 0.12.28 | -| aws | >= 2.70.0 | - -## Providers - -| Name | Version | -|------|---------| -| aws | >= 2.70.0 | - + +## Requirements + +| Name | Version | +|------|---------| +| terraform | >= 0.12.28 | +| aws | >= 2.70.0 | + +## Providers + +| Name | Version | +|------|---------| +| aws | >= 2.70.0 | + ## Inputs | Name | Description | Type | Default | Required | |------|-------------|------|---------|:--------:| -| aws\_env | AWS environment you are deploying to. Will be appended to SNS topic and alarm name. (e.g. dev, stage, prod) | `string` | n/a | yes | -| monthly\_billing\_threshold | The threshold for which estimated monthly charges will trigger the metric alarm. | `string` | n/a | yes | | aws\_account\_id | AWS account id | `string` | `""` | no | +| aws\_env | AWS environment you are deploying to. Will be appended to SNS topic and alarm name. (e.g. dev, stage, prod) | `string` | n/a | yes | | aws\_sns\_topic\_arn | If aws\_sns\_topic\_enabled = false, then an existing AWS SNS topic ARN for the billing alert integration will be used | `string` | `""` | no | | currency | Short notation for currency type (e.g. USD, CAD, EUR) | `string` | `"USD"` | no | +| monthly\_billing\_threshold | The threshold for which estimated monthly charges will trigger the metric alarm. | `string` | n/a | yes | | tags | A mapping of tags to assign to all resources | `map(string)` | `{}` | no | ## Outputs @@ -50,6 +51,8 @@ If `aws_sns_topic_enabled = true` then you'll still need to subscribe to the cre |------|-------------| | sns\_topic\_arn | SNS Topic ARN to be subscribed to in order to delivery the clodwatch billing alarms | + + The module outputs one block, sns_topic. Access it like this: ``` @@ -133,21 +136,21 @@ module "billing_cloudwatch_alert" { In order to get the full automated potential of the [Binbash Leverage DevOps Automation Code Library](https://leverage.binbash.com.ar/how-it-works/code-library/code-library/) -you should initialize all the necessary helper **Makefiles**. +you should initialize all the necessary helper **Makefiles**. -#### How? +#### How? You must execute the `make init-makefiles` command at the root context - + ```shell ╭─delivery at delivery-I7567 in ~/terraform/terraform-aws-backup-by-tags on master✔ 20-09-17 ╰─⠠⠵ make Available Commands: - init-makefiles initialize makefiles -``` +``` -### Why? -You'll get all the necessary commands to automatically operate this module via a dockerized approach, +### Why? +You'll get all the necessary commands to automatically operate this module via a dockerized approach, example shown below ```shell @@ -160,11 +163,11 @@ Available Commands: - tf-dir-chmod ## run chown in ./.terraform to gran that the docker mounted dir has the right permissions - version ## Show terraform version - init-makefiles ## initialize makefiles -``` +``` ```shell ╭─delivery at delivery-I7567 in ~/terraform/terraform-aws-backup-by-tags on master✔ 20-09-17 -╰─⠠⠵ make format-check +╰─⠠⠵ make format-check docker run --rm -v /home/delivery/Binbash/repos/Leverage/terraform/terraform-aws-backup-by-tags:"/go/src/project/":rw -v :/config -v /common.config:/common-config/common.config -v ~/.ssh:/root/.ssh -v ~/.gitconfig:/etc/gitconfig -v ~/.aws/bb:/root/.aws/bb -e AWS_SHARED_CREDENTIALS_FILE=/root/.aws/bb/credentials -e AWS_CONFIG_FILE=/root/.aws/bb/config --entrypoint=/bin/terraform -w "/go/src/project/" -it binbash/terraform-awscli-slim:0.12.28 fmt -check ``` diff --git a/examples/cloudwatch-billing-alert-to-new-sns-consolidated-acct/README.md b/examples/cloudwatch-billing-alert-to-new-sns-consolidated-acct/README.md index 4e5bf05..0eb42ca 100644 --- a/examples/cloudwatch-billing-alert-to-new-sns-consolidated-acct/README.md +++ b/examples/cloudwatch-billing-alert-to-new-sns-consolidated-acct/README.md @@ -28,7 +28,6 @@ $ make apply Note that this example may create resources which can cost money (AWS EC2, for example). Run `terraform destroy` or `make destroy` when you don't need these resources. - ## Outputs | Name | Description | @@ -43,8 +42,6 @@ output "sns_topic" { } ``` - - ## cloudwatch-billing-alert-to-new-sns-consolidated-acct ```terraform module "billing_cloudwatch_alert" { diff --git a/examples/cloudwatch-billing-alert-to-new-sns-with-acct-id/README.md b/examples/cloudwatch-billing-alert-to-new-sns-with-acct-id/README.md index e864dbc..54abc48 100644 --- a/examples/cloudwatch-billing-alert-to-new-sns-with-acct-id/README.md +++ b/examples/cloudwatch-billing-alert-to-new-sns-with-acct-id/README.md @@ -28,7 +28,6 @@ $ make apply Note that this example may create resources which can cost money (AWS EC2, for example). Run `terraform destroy` or `make destroy` when you don't need these resources. - ## Outputs | Name | Description | @@ -37,14 +36,13 @@ when you don't need these resources. The module outputs one block, sns_topic. Access it like this: + ``` output "sns_topic" { value = module.billing_alert.sns_topic } ``` - - ## cloudwatch-billing-alert-to-new-sns-with-acct-id ```terraform module "billing_cloudwatch_alert" { diff --git a/examples/cloudwatch-billing-alert-to-pre-existing-sns-consolidated-acct/README.md b/examples/cloudwatch-billing-alert-to-pre-existing-sns-consolidated-acct/README.md index 826f4ba..f8ac2ae 100644 --- a/examples/cloudwatch-billing-alert-to-pre-existing-sns-consolidated-acct/README.md +++ b/examples/cloudwatch-billing-alert-to-pre-existing-sns-consolidated-acct/README.md @@ -28,7 +28,6 @@ $ make apply Note that this example may create resources which can cost money (AWS EC2, for example). Run `terraform destroy` or `make destroy` when you don't need these resources. - ## Outputs | Name | Description | @@ -43,8 +42,6 @@ output "sns_topic" { } ``` - - ## cloudwatch-billing-alert-to-pre-existing-sns-consolidated-acct ```terraform module "billing_cloudwatch_alert" { diff --git a/examples/cloudwatch-billing-alert-to-pre-existing-sns-with-acct-id/README.md b/examples/cloudwatch-billing-alert-to-pre-existing-sns-with-acct-id/README.md index 4e7b0af..9e9d877 100644 --- a/examples/cloudwatch-billing-alert-to-pre-existing-sns-with-acct-id/README.md +++ b/examples/cloudwatch-billing-alert-to-pre-existing-sns-with-acct-id/README.md @@ -28,7 +28,6 @@ $ make apply Note that this example may create resources which can cost money (AWS EC2, for example). Run `terraform destroy` or `make destroy` when you don't need these resources. - ## Outputs | Name | Description | @@ -43,8 +42,6 @@ output "sns_topic" { } ``` - - ## cloudwatch-billing-alert-to-pre-existing-sns-consolidated-acct ```terraform module "billing_cloudwatch_alert" { diff --git a/tests/fixture/main.tf b/tests/fixture/main.tf index a230e0d..f4d9ff6 100644 --- a/tests/fixture/main.tf +++ b/tests/fixture/main.tf @@ -11,7 +11,7 @@ # #module "backend" { # source = "../../" -# +# # countries = "${var.countries}" #}