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

BBL-381 | std repo structure + standalone makefile approach + README.md update #3

Merged
merged 2 commits into from
Sep 18, 2020
Merged
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
89 changes: 85 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,26 @@ jobs:
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: test1-terraform-format
command: make format-check

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

- run:
name: Configure awscli
command: |
echo "AWS_ACCESS_KEY_ID - $AWS_ACCESS_KEY_ID"
echo "AWS_PROFILE_NAME - $AWS_PROFILE_NAME"
# AWS credentials dir
mkdir --parents /home/circleci/.aws/bb
sudo chown -R $USER:$USER /home/circleci/.aws

# AWS defautl awscli profile
aws configure set aws_access_key_id $AWS_ACCESS_KEY_ID
Expand All @@ -36,13 +47,71 @@ jobs:
aws configure set output json

# AWS dev awscli profile
aws configure set role_arn arn:aws:iam::$AWS_ACCOUNT_ID_SHARED:role/DeployMaster --profile $AWS_PROFILE_NAME
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
cp /home/circleci/.aws/credentials /home/circleci/.aws/bb/credentials
cp /home/circleci/.aws/config /home/circleci/.aws/bb/config

- run:
name: test2-terraform-linting
command: make tflint-deep

#
# Test 3
#
test-e2e-terratests:
machine:
image: ubuntu-1604:201903-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: test3-terratests-dep-init
command: make terratest-dep-init

- run:
name: test3-terratests-go-test
command: make terratest-go-test

#
# Release
#
Expand All @@ -61,6 +130,12 @@ jobs:
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: Release New Version
command: |
Expand All @@ -70,7 +145,7 @@ jobs:
echo "==============================================================================================="
git config --global user.email "$GIT_USER_EMAIL"
git config --global user.name "$GIT_USER_NAME"
make -f Makefile.release release-$VERSION_NUMBER-with-changelog-circleci
make release-$VERSION_NUMBER-with-changelog-circleci
else
echo "==============================================================================================="
echo "Changes in working directory pending to be pushed - please check 'git status' cmd output below "
Expand All @@ -92,6 +167,12 @@ workflows:
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
- release-version-with-changelog:
context: binbashar-org-global-context
filters:
Expand Down
4 changes: 2 additions & 2 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Use this file to define individuals or teams that are responsible for code in a repository.
# Read more: <https://help.github.com/articles/about-codeowners/>

* @binbashar/leverage-project-terraform-admin
* @binbashar/leverage-project-terraform-dev
* @binbashar/leverage-ref-architecture-aws-admin
* @binbashar/leverage-ref-architecture-aws-dev
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

15 changes: 13 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
!*.circleci
!*.dockeringnore
!*.hosts
!/.gitignore
!.hosts.example
!*.gitignore
!/.chglog
!/.gitallowed
!/.github
Expand All @@ -19,6 +20,7 @@
############
id_rsa
id_dsa
keys/

# OS generated files #
######################
Expand Down Expand Up @@ -79,9 +81,18 @@ Thumbs.db
*.pgpass
*.vagrant

# TF Project files #
# Project files #
####################
#
# Secret Files
#
*secrets.dec.*
#
# Scripts and Makefiles
#
/@bin
!/@bin/scripts
#
# Compiled files
#
*.tfstate
Expand Down
125 changes: 18 additions & 107 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,116 +1,27 @@
.PHONY: help
SHELL := /bin/bash
LOCAL_OS_USER := $(shell whoami)
LOCAL_OS_SSH_DIR := ~/.ssh
LOCAL_OS_GIT_CONF_DIR := ~/.gitconfig
LOCAL_OS_AWS_CONF_DIR := ~/.aws

# localhost aws-iam-profile
# LOCAL_OS_AWS_PROFILE := bb-shared-deploymaster
# ci aws-iam-profile
LOCAL_OS_AWS_PROFILE := "bb-dev-deploymaster"
LOCAL_OS_AWS_REGION := us-east-1

TF_PWD_DIR := $(shell pwd)
TF_VER := 0.12.24
TF_PWD_CONT_DIR := "/go/src/project/"
TF_DOCKER_ENTRYPOINT := /usr/local/go/bin/terraform
TF_DOCKER_IMAGE := binbash/terraform-resources

TERRATEST_DOCKER_ENTRYPOINT := dep
TERRATEST_DOCKER_WORKDIR := /go/src/project/tests

#
# TERRAFORM
#
define TF_CMD_PREFIX
docker run --rm \
-v ${TF_PWD_DIR}:${TF_PWD_CONT_DIR}:rw \
--entrypoint=${TF_DOCKER_ENTRYPOINT} \
-w ${TF_PWD_CONT_DIR} \
-it ${TF_DOCKER_IMAGE}:${TF_VER}
endef

#
# TERRATEST
#
define TERRATEST_GO_CMD_PREFIX
docker run --rm \
-v ${TF_PWD_DIR}:${TF_PWD_CONT_DIR}:rw \
-v ${LOCAL_OS_SSH_DIR}:/root/.ssh \
-v ${LOCAL_OS_GIT_CONF_DIR}:/etc/gitconfig \
-v ${LOCAL_OS_AWS_CONF_DIR}:/root/.aws \
-w ${TERRATEST_DOCKER_WORKDIR} \
-it ${TF_DOCKER_IMAGE}:${TF_VER}
endef

define TERRATEST_DEP_CMD_PREFIX
docker run --rm \
-v ${TF_PWD_DIR}:${TF_PWD_CONT_DIR}:rw \
-v ${LOCAL_OS_SSH_DIR}:/root/.ssh \
-v ${LOCAL_OS_GIT_CONF_DIR}:/etc/gitconfig \
--entrypoint=${TERRATEST_DOCKER_ENTRYPOINT} \
-it ${TF_DOCKER_IMAGE}:${TF_VER}
endef
SHELL := /bin/bash
MAKEFILE_PATH := ./Makefile
MAKEFILES_DIR := ./@bin/makefiles

help:
@echo 'Available Commands:'
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " - \033[36m%-18s\033[0m %s\n", $$1, $$2}'

#==============================================================#
# TERRAFORM #
#==============================================================#
version: ## Show terraform version
docker run --rm \
--entrypoint=${TF_DOCKER_ENTRYPOINT} \
-t ${TF_DOCKER_IMAGE}:${TF_VER} version

format: ## The terraform fmt is used to rewrite tf conf files to a canonical format and style.
${TF_CMD_PREFIX} fmt -recursive

format-check: ## The terraform fmt is used to rewrite tf conf files to a canonical format and style.
${TF_CMD_PREFIX} fmt -check -recursive

pre-commit: ## Execute validation: pre-commit run --all-files.
pre-commit run --all-files

terraform-docs: ## A utility to generate documentation from Terraform 0.12 modules in various output formats.
docker run --rm \
-v $$(pwd):/data \
cytopia/terraform-docs:0.8.0 \
terraform-docs-012 --sort-inputs-by-required --with-aggregate-type-defaults markdown table .

tflint: ## TFLint is a Terraform linter for detecting errors that can not be detected by terraform plan (tf0.12 > 0.10.x).
docker run --rm \
-v ${LOCAL_OS_AWS_CONF_DIR}:/root/.aws \
-v ${TF_PWD_DIR}:/data \
-t wata727/tflint:0.13.2

tflint-deep: ## TFLint is a Terraform linter for detecting errors that can not be detected by terraform plan (tf0.12 > 0.10.x).
docker run --rm \
-v ${LOCAL_OS_AWS_CONF_DIR}:/root/.aws \
-v ${TF_PWD_DIR}:/data \
-t wata727/tflint:0.13.2 --deep \
--aws-profile=${LOCAL_OS_AWS_PROFILE} \
--aws-creds-file=/root/.aws/credentials \
--aws-region=${LOCAL_OS_AWS_REGION}

#==============================================================#
# TERRATEST #
# INITIALIZATION #
#==============================================================#
terratest-dep-init: ## dep is a dependency management tool for Go. (https://github.com/golang/dep)
${TERRATEST_DEP_CMD_PREFIX} init
${TERRATEST_DEP_CMD_PREFIX} ensure
sudo chown -R ${LOCAL_OS_USER}:${LOCAL_OS_USER} .
cp -r ./vendor ./tests/ && rm -rf ./vendor
cp -r ./Gopkg* ./tests/ && rm -rf ./Gopkg*

terratest-go-test: ## Run E2E terratests
${TERRATEST_GO_CMD_PREFIX} test -timeout 20m
sudo chown -R ${LOCAL_OS_USER}:${LOCAL_OS_USER} .
init-makefiles: ## initialize makefiles
rm -rf ${MAKEFILES_DIR}
mkdir -p ${MAKEFILES_DIR}
git clone https://github.com/binbashar/le-dev-makefiles.git ${MAKEFILES_DIR}
echo "" >> ${MAKEFILE_PATH}
sed -i '/^#include.*/s/^#//' ${MAKEFILE_PATH}

#==============================================================#
# CIRCLECI #
#==============================================================#
circleci-validate-config: ## Validate A CircleCI Config (https://circleci.com/docs/2.0/local-cli/)
circleci config validate .circleci/config.yml
#
## IMPORTANT: Automatically managed
## Must NOT UNCOMMENT the #include lines below
#
#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
Loading