From 16815580efefbfa598f5db97fb764d91cd0460e0 Mon Sep 17 00:00:00 2001 From: Simon Emms Date: Thu, 20 Jun 2024 21:22:43 +0000 Subject: [PATCH] feat(terraform): enable terragrunt --- terraform/README.md | 6 +++--- terraform/cookiecutter.json | 5 +++-- terraform/{{ cookiecutter.project_name }}/.gitignore | 1 + .../{{ cookiecutter.project_name }}/.pre-commit-config.yaml | 6 ++++-- .../{infrastructure => }/.tflint.hcl | 0 .../{{ cookiecutter.module_name }}}/README.md | 2 +- .../{{ cookiecutter.module_name }}/terraform.tf} | 0 .../modules/{{ cookiecutter.module_name }}/terragrunt.hcl | 0 .../dev/{{ cookiecutter.module_name }}/terragrunt.hcl | 3 +++ .../prod/{{ cookiecutter.module_name }}/terragrunt.hcl | 3 +++ .../staging/{{ cookiecutter.module_name }}/terragrunt.hcl | 3 +++ terraform/{{ cookiecutter.project_name }}/terragrunt.hcl | 0 12 files changed, 21 insertions(+), 8 deletions(-) rename terraform/{{ cookiecutter.project_name }}/{infrastructure => }/.tflint.hcl (100%) rename terraform/{{ cookiecutter.project_name }}/{infrastructure => modules/{{ cookiecutter.module_name }}}/README.md (57%) rename terraform/{{ cookiecutter.project_name }}/{infrastructure/providers.tf => modules/{{ cookiecutter.module_name }}/terraform.tf} (100%) create mode 100644 terraform/{{ cookiecutter.project_name }}/modules/{{ cookiecutter.module_name }}/terragrunt.hcl create mode 100644 terraform/{{ cookiecutter.project_name }}/stacks/dev/{{ cookiecutter.module_name }}/terragrunt.hcl create mode 100644 terraform/{{ cookiecutter.project_name }}/stacks/prod/{{ cookiecutter.module_name }}/terragrunt.hcl create mode 100644 terraform/{{ cookiecutter.project_name }}/stacks/staging/{{ cookiecutter.module_name }}/terragrunt.hcl create mode 100644 terraform/{{ cookiecutter.project_name }}/terragrunt.hcl diff --git a/terraform/README.md b/terraform/README.md index afdb473..29d5694 100644 --- a/terraform/README.md +++ b/terraform/README.md @@ -1,7 +1,7 @@ -# Blank +# Terraform -Simple blank project. If unsure, use this one +Terraform project with Terragrunt enabled ```shell -make blank +make terraform ``` diff --git a/terraform/cookiecutter.json b/terraform/cookiecutter.json index eb081ac..611b216 100644 --- a/terraform/cookiecutter.json +++ b/terraform/cookiecutter.json @@ -1,5 +1,6 @@ { "project_name": null, - "description": "A blank project for getting started", - "author": "Simon Emms " + "description": "A Terraform project with Terragrunt enabled", + "author": "Simon Emms ", + "module_name": null } diff --git a/terraform/{{ cookiecutter.project_name }}/.gitignore b/terraform/{{ cookiecutter.project_name }}/.gitignore index 6c3a8a7..6bcd2c6 100644 --- a/terraform/{{ cookiecutter.project_name }}/.gitignore +++ b/terraform/{{ cookiecutter.project_name }}/.gitignore @@ -13,3 +13,4 @@ Thumbs.db **/.terraform/* *.tfstate *.tfstate.* +**/.terragrunt-cache/* diff --git a/terraform/{{ cookiecutter.project_name }}/.pre-commit-config.yaml b/terraform/{{ cookiecutter.project_name }}/.pre-commit-config.yaml index 8eae797..419be63 100644 --- a/terraform/{{ cookiecutter.project_name }}/.pre-commit-config.yaml +++ b/terraform/{{ cookiecutter.project_name }}/.pre-commit-config.yaml @@ -42,7 +42,9 @@ repos: - id: terraform-docs-go args: - markdown - - infrastructure + - . + - --recursive + - --recursive-include-main=false - --output-file=README.md - repo: https://github.com/antonbabenko/pre-commit-terraform rev: "v1.91.0" @@ -52,4 +54,4 @@ repos: - --args=-recursive - id: terraform_tflint - id: terraform_trivy - - id: terraform_validate + - id: terragrunt_validate diff --git a/terraform/{{ cookiecutter.project_name }}/infrastructure/.tflint.hcl b/terraform/{{ cookiecutter.project_name }}/.tflint.hcl similarity index 100% rename from terraform/{{ cookiecutter.project_name }}/infrastructure/.tflint.hcl rename to terraform/{{ cookiecutter.project_name }}/.tflint.hcl diff --git a/terraform/{{ cookiecutter.project_name }}/infrastructure/README.md b/terraform/{{ cookiecutter.project_name }}/modules/{{ cookiecutter.module_name }}/README.md similarity index 57% rename from terraform/{{ cookiecutter.project_name }}/infrastructure/README.md rename to terraform/{{ cookiecutter.project_name }}/modules/{{ cookiecutter.module_name }}/README.md index 20612a3..59a1701 100644 --- a/terraform/{{ cookiecutter.project_name }}/infrastructure/README.md +++ b/terraform/{{ cookiecutter.project_name }}/modules/{{ cookiecutter.module_name }}/README.md @@ -1,4 +1,4 @@ -# Infrastructure +# {{ cookiecutter.module_name }} diff --git a/terraform/{{ cookiecutter.project_name }}/infrastructure/providers.tf b/terraform/{{ cookiecutter.project_name }}/modules/{{ cookiecutter.module_name }}/terraform.tf similarity index 100% rename from terraform/{{ cookiecutter.project_name }}/infrastructure/providers.tf rename to terraform/{{ cookiecutter.project_name }}/modules/{{ cookiecutter.module_name }}/terraform.tf diff --git a/terraform/{{ cookiecutter.project_name }}/modules/{{ cookiecutter.module_name }}/terragrunt.hcl b/terraform/{{ cookiecutter.project_name }}/modules/{{ cookiecutter.module_name }}/terragrunt.hcl new file mode 100644 index 0000000..e69de29 diff --git a/terraform/{{ cookiecutter.project_name }}/stacks/dev/{{ cookiecutter.module_name }}/terragrunt.hcl b/terraform/{{ cookiecutter.project_name }}/stacks/dev/{{ cookiecutter.module_name }}/terragrunt.hcl new file mode 100644 index 0000000..165fe41 --- /dev/null +++ b/terraform/{{ cookiecutter.project_name }}/stacks/dev/{{ cookiecutter.module_name }}/terragrunt.hcl @@ -0,0 +1,3 @@ +terraform { + source = "../../../modules/${basename(get_terragrunt_dir())}" +} diff --git a/terraform/{{ cookiecutter.project_name }}/stacks/prod/{{ cookiecutter.module_name }}/terragrunt.hcl b/terraform/{{ cookiecutter.project_name }}/stacks/prod/{{ cookiecutter.module_name }}/terragrunt.hcl new file mode 100644 index 0000000..165fe41 --- /dev/null +++ b/terraform/{{ cookiecutter.project_name }}/stacks/prod/{{ cookiecutter.module_name }}/terragrunt.hcl @@ -0,0 +1,3 @@ +terraform { + source = "../../../modules/${basename(get_terragrunt_dir())}" +} diff --git a/terraform/{{ cookiecutter.project_name }}/stacks/staging/{{ cookiecutter.module_name }}/terragrunt.hcl b/terraform/{{ cookiecutter.project_name }}/stacks/staging/{{ cookiecutter.module_name }}/terragrunt.hcl new file mode 100644 index 0000000..165fe41 --- /dev/null +++ b/terraform/{{ cookiecutter.project_name }}/stacks/staging/{{ cookiecutter.module_name }}/terragrunt.hcl @@ -0,0 +1,3 @@ +terraform { + source = "../../../modules/${basename(get_terragrunt_dir())}" +} diff --git a/terraform/{{ cookiecutter.project_name }}/terragrunt.hcl b/terraform/{{ cookiecutter.project_name }}/terragrunt.hcl new file mode 100644 index 0000000..e69de29