Skip to content
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
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
**/.terraform
.vscode
ssh_keys
*.tfstate*
*.tfstate*
*tfvars*
.aws
secrets.tfvars
93 changes: 0 additions & 93 deletions .terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM hashicorp/terraform:1.1.3
FROM alpine/terragrunt:1.1.3

RUN apk update && apk upgrade
RUN apk add bash groff openssh git vim jq make curl
Expand All @@ -15,9 +15,11 @@ RUN apk -v --update add \
rm /var/cache/apk/*

RUN mkdir -p /infra

ENV PS1 '\[\033[1;37m\]($(echo `terraform workspace show`)) \[\033[1;33m\]\u \[\033[1;36m\]\h \[\033[1;34m\]\w\[\033[0;35m\] \[\033[1;36m\]# \[\033[0m\]'

WORKDIR /infra

RUN echo 'alias t=terraform' > ~/.bashrc && \
terraform -install-autocomplete
RUN echo 'alias t=terragrunt' > ~/.bashrc

ENTRYPOINT "bash"
16 changes: 16 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
WORKSPACE := $(shell terraform workspace show)
BUCKET := $(shell cat backend.tf | grep bucket | awk '{print $$3}')

ifeq ($(WORKSPACE),default)
REMOTE_TFVARS_PATH := "s3://$(BUCKET)/terraform.tfvars"
LOCAL_TFVARS_PATH := "../tfvars/terraform.tfvars"
else
REMOTE_TFVARS_PATH := "s3://$(BUCKET)/env:/$(WORKSPACE)/terraform.tfvars"
LOCAL_TFVARS_PATH := "tfvars/$(WORKSPACE)/terraform.tfvars"
endif

push_vars:
aws s3 cp --sse="AES256" $(LOCAL_TFVARS_PATH) $(REMOTE_TFVARS_PATH)

pull_vars:
aws s3 cp --sse="AES256" $(REMOTE_TFVARS_PATH) $(LOCAL_TFVARS_PATH)
10 changes: 10 additions & 0 deletions backend.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Generated by Terragrunt. Sig: nIlQXj57tbuaRZEa
terraform {
backend "s3" {
bucket = "infra-by-terragrunt-tf"
dynamodb_table = "infra-by-terragrunt-lock"
encrypt = true
key = "terraform.tfstate"
region = "us-east-1"
}
}
25 changes: 25 additions & 0 deletions common/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions common/backend.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Generated by Terragrunt. Sig: nIlQXj57tbuaRZEa
terraform {
backend "s3" {
bucket = "infra-by-terragrunt-tf"
dynamodb_table = "infra-by-terragrunt-lock"
encrypt = true
key = "terraform.tfstate"
region = "us-east-1"
}
}
Empty file added common/main.tf
Empty file.
24 changes: 24 additions & 0 deletions common/terragrunt.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
locals {
region = "us-east-1"
project = "infra-by-terragrunt"
}

inputs = {
region = local.region
project = local.project
}

remote_state {
backend = "s3"
generate = {
path = "backend.tf"
if_exists = "overwrite_terragrunt"
}
config = {
bucket = "${local.project}-tf"
key = "terraform.tfstate"
region = local.region
encrypt = true
dynamodb_table = "${local.project}-lock"
}
}
3 changes: 3 additions & 0 deletions common/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
variable "region" {
description = "the AWS region in which resources are created, you must set the availability_zones variable as well if you define this value to something other than the default"
}
3 changes: 1 addition & 2 deletions versions.tf → common/versions.tf
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
terraform {
required_version = ">= 0.15.3"

required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 3.38"
}
}
required_version = ">= 0.15.3"
}

provider "aws" {
Expand Down
22 changes: 0 additions & 22 deletions main.tf

This file was deleted.

3 changes: 0 additions & 3 deletions outputs.tf

This file was deleted.

5 changes: 0 additions & 5 deletions terraform.tfvars

This file was deleted.

28 changes: 28 additions & 0 deletions terragrunt.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
locals {
workspace = run_cmd("--terragrunt-quiet", "terraform", "workspace", "show")
common = read_terragrunt_config("common/terragrunt.hcl")
}

inputs = {
region = local.common.inputs.region
project = local.common.inputs.project
environment = local.workspace
}

remote_state = local.common.remote_state

terraform {
extra_arguments "conditional_vars" {
commands = get_terraform_commands_that_need_vars()

required_var_files = [
"tfvars/${local.workspace}/terraform.tfvars"
]
}

after_hook "upload_vars" {
commands = ["apply"]
execute = ["make", "push_vars"]
run_on_error = false
}
}
24 changes: 0 additions & 24 deletions variables.tf

This file was deleted.