Skip to content

Commit

Permalink
Merge pull request #54 from lmilbaum/environments
Browse files Browse the repository at this point in the history
environments with Terragrunt
  • Loading branch information
lmilbaum authored Sep 22, 2023
2 parents 654c84d + ac37b63 commit e536dff
Show file tree
Hide file tree
Showing 17 changed files with 374 additions and 201 deletions.
6 changes: 3 additions & 3 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
"name": "gitlab-runner",
"dockerFile": "Dockerfile",
"features": {
"ghcr.io/devcontainers/features/docker-in-docker:2.2.1": {},
"ghcr.io/devcontainers/features/docker-in-docker:2.5.0": {},
"ghcr.io/devcontainers/features/kubectl-helm-minikube:1.1.4": {
"version": "1.27.3",
"helm": "3.12.1",
"minikube": "1.30.1"
},
"ghcr.io/devcontainers/features/ruby:1.1.0": {
"ghcr.io/devcontainers/features/ruby:1.1.1": {
"version": "3.2.2"
},
"ghcr.io/devcontainers-contrib/features/pre-commit:2.0.9": {
"version": "3.3.3"
},
"ghcr.io/devcontainers/features/terraform:1.3.3": {
"ghcr.io/devcontainers/features/terraform:1.3.4": {
"version": "1.5.3"
}
},
Expand Down
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
*.env*
*.tfvars
*.lock.hcl
*.tfstate
.terraform
.vscode/
*.backup
backend.hcl
*.zip
.terragrunt-cache/
41 changes: 26 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,29 @@
.PHONY: up down all clean test init plan apply destroy
.PHONY: all clean test

include .env
export
ENV := dev
TERRAGRUNT_CMD = cd live/${ENV} && terragrunt run-all --terragrunt-non-interactive

.PHONY: tf/init
tf/init:
${TERRAGRUNT_CMD} init -backend-config=backend.hcl

.PHONY: tf/plan
tf/plan:
${TERRAGRUNT_CMD} plan -out tfplan

.PHONY: tf/graph
tf/graph:
${TERRAGRUNT_CMD} graph

.PHONY: tf/apply
tf/apply:
${TERRAGRUNT_CMD} apply

.PHONY: tf/destroy
tf/destroy:
${TERRAGRUNT_CMD} destroy -terragrunt-log-level debug

.PHONY: up
up:
minikube start \
--cpus 4 \
Expand All @@ -17,17 +38,7 @@ up:
--set global.hosts.domain=$$(minikube ip).nip.io \
--set global.hosts.externalIP=$$(minikube ip) \
-f values.yaml

.PHONY: down
down:
minikube delete

init:
terraform -chdir=infra init -backend-config=backend.hcl

plan:
dotenv run terraform -chdir=infra plan

apply:
dotenv run terraform -chdir=infra apply

destroy:
dotenv run terraform -chdir=infra destroy
26 changes: 24 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,31 @@
| ![Pre-commit][2] | Static quality gates | pre-commit |
| ![Devcontainer][3] | Local DEV Env | devcontainer |

<!-- | ![GitHub Codespaces][4] | Remove DEV Env | codespaces | -->
## IaC Terraform & Terragrunt

## Dev Environment
Implemented in devcontainer

### DEV environment

```shell
make tf/init
make tf/plan
make tf/apply
make tf/destroy
```

### PROD environment

```shell
make tf/init ENV=prod
make tf/plan ENV=prod
make tf/apply ENV=prod
make tf/destroy ENV=prod
```

## IaC Minikube

### Dev Environment

The development environment is implemented with [devcontainer][5].

Expand Down
10 changes: 0 additions & 10 deletions env.template

This file was deleted.

160 changes: 0 additions & 160 deletions infra/main.tf

This file was deleted.

3 changes: 3 additions & 0 deletions live/dev/env.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
locals {
environment = "dev"
}
15 changes: 15 additions & 0 deletions live/dev/runner/terragrunt.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
terraform {
source = "../../../modules//runner"
}

include "root" {
path = find_in_parent_folders()
}

locals {
environment_vars = read_terragrunt_config(find_in_parent_folders("env.hcl"))
}

inputs = merge(
local.environment_vars.locals
)
3 changes: 3 additions & 0 deletions live/prod/env.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
locals {
environment = "prod"
}
15 changes: 15 additions & 0 deletions live/prod/runner/terragrunt.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
terraform {
source = "../../../modules//runner"
}

include "root" {
path = find_in_parent_folders()
}

locals {
environment_vars = read_terragrunt_config(find_in_parent_folders("env.hcl"))
}

inputs = merge(
local.environment_vars.locals
)
37 changes: 37 additions & 0 deletions live/terragrunt.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
remote_state {
backend = "s3"
generate = {
path = "backend.tf"
if_exists = "overwrite"
}
config = {
bucket = "pe-tf-backend"
key = "${path_relative_to_include()}/terraform.tfstate"
region = "eu-west-2"
profile = "default"
encrypt = true
dynamodb_table = "pe-tf-backend"
s3_bucket_tags = {
"Project" = "Platform Engineering"
"User" = "lmilbaum"
}
dynamodb_table_tags = {
"Project" = "Platform Engineering"
"User" = "lmilbaum"
}
}
}

generate "provider" {
path = "provider.tf"
if_exists = "overwrite"
contents = <<EOF
provider "aws" {
region = var.aws_region
profile = var.aws_profile
default_tags {
tags = { "Project" = "Platform Engineering", "User" = "lmilbaum" }
}
}
EOF
}
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit e536dff

Please sign in to comment.