Skip to content

Commit

Permalink
Merge pull request #16 from binbashar/feature/single-block
Browse files Browse the repository at this point in the history
Feature/single block
  • Loading branch information
lgallard authored Oct 26, 2021
2 parents ccfbb49 + 55403e4 commit c58f947
Show file tree
Hide file tree
Showing 18 changed files with 145 additions and 293 deletions.
155 changes: 19 additions & 136 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ jobs:
# Automated Tests
#
test-static-code-and-linting:
machine:
image: ubuntu-1604:202007-01 # Ubuntu 16.04, Docker v19.03.12, Docker Compose v1.26.1
machine: # https://circleci.com/docs/2.0/configuration-reference/#available-machine-images
image: ubuntu-2004:202107-01 # Ubuntu 16.04, Docker v19.03.12, Docker Compose v1.26.1

# This job has been blocked because Docker Layer Caching is not available on your plan.
# Should upgrade if necessary.
Expand All @@ -26,31 +26,33 @@ jobs:
git update-index --assume-unchanged "Makefile"
- run:
name: test-terraform-format-and-docs
name: test-dependencies
command: |
#
# Install pre-commit
pip install pre-commit
sudo -H pip3 install pre-commit
#
# Install terraform
sudo apt-get install unzip
sudo apt-get install unzip curl
curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add -
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
curl -Lo ./terraform-docs https://github.com/terraform-docs/terraform-docs/releases/download/v0.12.1/terraform-docs-v0.12.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: test-terraform-format-and-docs
command: make pre-commit

- run:
name: Install awscli
command: sudo -H pip install awscli
command: sudo -H pip3 install awscli

- run:
name: Configure awscli
Expand All @@ -65,7 +67,7 @@ jobs:
aws configure set region us-east-1
aws configure set output json
# AWS dev awscli profile
# AWS network awscli profile
aws configure set role_arn arn:aws:iam::$AWS_ACCOUNT_ID_DEV:role/DeployMaster --profile $AWS_PROFILE_NAME
aws configure set source_profile default --profile $AWS_PROFILE_NAME
Expand All @@ -77,128 +79,13 @@ jobs:
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'

#
# Tests E2E
#
test-e2e-terratests:
machine:
image: ubuntu-1604:202007-01
docker_layer_caching: false

steps:
- checkout

- run:
name: Context Info Cmds
command: pwd && ls -ltra && git branch

- run:
name: Initialize Repo Makefiles
command: |
make init-makefiles
git update-index --assume-unchanged "Makefile"
- run:
name: Install awscli
command: sudo pip install awscli

- run:
name: Configure awscli
command: |
# AWS defautl awscli profile
aws configure set aws_access_key_id $AWS_ACCESS_KEY_ID
aws configure set aws_secret_access_key $AWS_SECRET_ACCESS_KEY
aws configure set region us-east-1
aws configure set output json
# AWS dev awscli profile
aws configure set role_arn arn:aws:iam::$AWS_ACCOUNT_ID_DEV:role/DeployMaster --profile $AWS_PROFILE_NAME
aws configure set source_profile default --profile $AWS_PROFILE_NAME
# moving credentials to specific project folder
mkdir --parents /home/circleci/.aws/bb
cp /home/circleci/.aws/credentials /home/circleci/.aws/bb/credentials
cp /home/circleci/.aws/config /home/circleci/.aws/bb/config
- run:
name: Test AWS permissions
command: aws ec2 describe-instances --region us-east-1 --profile $AWS_PROFILE_NAME

- run:
name: test-terratests-dep-init
command: make terratest-dep-init

- run:
name: test-terratests-go-test
#command: make AWS_ACCOUNT_ID=$AWS_ACCOUNT_ID_DEV terratest-go-test
command: make terratest-go-test

- slack/notify:
Expand Down Expand Up @@ -276,7 +163,7 @@ jobs:
#
release-version-with-changelog:
machine:
image: ubuntu-1604:202007-01
image: ubuntu-2004:202107-01 # Ubuntu 16.04, Docker v19.03.12, Docker Compose v1.26.1
docker_layer_caching: false

environment:
Expand Down Expand Up @@ -402,14 +289,8 @@ workflows:
context: binbashar-org-global-context
filters:
branches:
ignore: # only branches matching the below regex filters will run
- master
- test-e2e-terratests:
context: binbashar-org-global-context
filters:
branches:
ignore: # only branches matching the below regex filters will run
- master
ignore: # only branches matching the below regex filters will run
- master
- release-version-with-changelog:
context: binbashar-org-global-context
filters:
Expand All @@ -418,3 +299,5 @@ workflows:
- master
- sumologic/workflow-collector:
context: binbashar-org-global-context
requires:
- release-version-with-changelog
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
SHELL := /bin/bash
MAKEFILE_PATH := ./Makefile
MAKEFILES_DIR := ./@bin/makefiles
MAKEFILES_VER := v0.1.5
MAKEFILES_VER := v0.1.33

help:
@echo 'Available Commands:'
Expand All @@ -19,5 +19,6 @@ init-makefiles: ## initialize makefiles

-include ${MAKEFILES_DIR}/circleci/circleci.mk
-include ${MAKEFILES_DIR}/release-mgmt/release.mk
-include ${MAKEFILES_DIR}/terraform13/terraform13.mk
-include ${MAKEFILES_DIR}/terratest13/terratest13.mk
-include ${MAKEFILES_DIR}/terraform14/terraform14-root-context.mk
-include ${MAKEFILES_DIR}/terraform14/terraform14.mk
-include ${MAKEFILES_DIR}/terratest14/terratest14.mk
39 changes: 25 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,39 +25,50 @@ If `aws_sns_topic_enabled = true` then you'll still need to subscribe to the cre

| Name | Version |
|------|---------|
| terraform | >= 0.12.28 |
| aws | >= 2.70.0 |
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.12.28 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 2.70.0 |

## Providers

| Name | Version |
|------|---------|
| aws | >= 2.70.0 |
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 2.70.0 |

## Modules

No modules.

## Resources

| Name | Type |
|------|------|
| [aws_cloudwatch_metric_alarm.account_billing_alarm](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_metric_alarm) | resource |
| [aws_sns_topic.sns_alert_topic](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/sns_topic) | resource |

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| 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 |
| <a name="input_aws_account_id"></a> [aws\_account\_id](#input\_aws\_account\_id) | AWS account id | `string` | `null` | no |
| <a name="input_aws_env"></a> [aws\_env](#input\_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 |
| <a name="input_create_sns_topic"></a> [create\_sns\_topic](#input\_create\_sns\_topic) | Creates a SNS Topic if `true`. | `bool` | `true` | no |
| <a name="input_currency"></a> [currency](#input\_currency) | Short notation for currency type (e.g. USD, CAD, EUR) | `string` | `"USD"` | no |
| <a name="input_monthly_billing_threshold"></a> [monthly\_billing\_threshold](#input\_monthly\_billing\_threshold) | The threshold for which estimated monthly charges will trigger the metric alarm. | `string` | n/a | yes |
| <a name="input_sns_topic_arns"></a> [sns\_topic\_arns](#input\_sns\_topic\_arns) | List of SNS topic ARNs to be used. If `create_sns_topic` is `true`, it merges the created SNS Topic by this module with this list of ARNs | `list(string)` | `[]` | no |
| <a name="input_tags"></a> [tags](#input\_tags) | A mapping of tags to assign to all resources | `map(string)` | `{}` | no |

## Outputs

| Name | Description |
|------|-------------|
| sns\_topic\_arn | SNS Topic ARN to be subscribed to in order to delivery the clodwatch billing alarms |

| <a name="output_sns_topic_arns"></a> [sns\_topic\_arns](#output\_sns\_topic\_arns) | List of SNS Topic ARNs to be subscribed to in order to delivery the clodwatch billing alarms |
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

The module outputs one block,.sns_topic_arn. Access it like this:
The module outputs one block, sns_topic_arns. Access it like this:

```
output "sns_topic_arn" {
value = "${module.billing_alert.sns_topic_arn}"
output "sns_topic_arns" {
value = module.billing_alert.sns_topic_arns
}
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ when you don't need these resources.

| Name | Description |
|------|-------------|
| sns\_topic\_arn | SNS Topic ARN to be subscribed to in order to delivery the clodwatch billing alarms
| sns\_topic\_arns | List of SNS Topic ARNs to be subscribed to in order to delivery the clodwatch billing alarms |

The module outputs one block, sns_topic. Access it like this:
The module outputs one block, sns_topic_arns. Access it like this:

```
output "sns_topic" {
value = module.billing_alert.sns_topic
output "sns_topic_arns" {
value = module.billing_alert.sns_topic_arns
}
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ module "billing_cloudwatch_alert" {
currency = "USD"
}

output "sns_topic" {
value = module.billing_cloudwatch_alert.sns_topic_arn
output "sns_topics" {
value = module.billing_cloudwatch_alert.sns_topic_arns
}

# Will output the following:
# arn:aws:sns:us-east-1:111111111111:billing-alarm-notification-usd-dev
# [arn:aws:sns:us-east-1:111111111111:billing-alarm-notification-usd-dev]

Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,13 @@ when you don't need these resources.

| Name | Description |
|------|-------------|
| 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:
| sns\_topic\_arns | List of SNS Topic ARNs to be subscribed to in order to delivery the clodwatch billing alarms |

The module outputs one block, sns_topic_arns. Access it like this:

```
output "sns_topic" {
value = module.billing_alert.sns_topic
output "sns_topic_arns" {
value = module.billing_alert.sns_topic_arns
}
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ module "billing_cloudwatch_alert" {
currency = "USD"
}

output "sns_topic" {
value = module.billing_cloudwatch_alert.sns_topic_arn
output "sns_topics" {
value = module.billing_cloudwatch_alert.sns_topic_arns
}

# Will output the following:
# arn:aws:sns:us-east-1:111111111111:billing-alarm-notification-usd-dev
# [arn:aws:sns:us-east-1:111111111111:billing-alarm-notification-usd-dev]

Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ when you don't need these resources.

| Name | Description |
|------|-------------|
| sns\_topic\_arn | SNS Topic ARN to be subscribed to in order to delivery the clodwatch billing alarms
| sns\_topic\_arns | List of SNS Topic ARNs to be subscribed to in order to delivery the clodwatch billing alarms |

The module outputs one block, sns_topic. Access it like this:
The module outputs one block, sns_topic_arns. Access it like this:

```
output "sns_topic" {
value = module.billing_alert.sns_topic
output "sns_topic_arns" {
value = module.billing_alert.sns_topic_arns
}
```

Expand Down
Loading

0 comments on commit c58f947

Please sign in to comment.