From 2767119fd8d31bc8f46baebb54435885ef8bbe37 Mon Sep 17 00:00:00 2001 From: Chris Wilding Date: Wed, 7 Jul 2021 18:25:40 +0100 Subject: [PATCH] Add terragrunt --- .gitignore | 3 ++- backend/{backend.tf => default.tf} | 2 +- backend/main.tf | 8 -------- backend/terragrunt.hcl | 3 +++ budget/budget.tf | 2 +- budget/main.tf | 11 +++++------ budget/terragrunt.hcl | 3 +++ iam/main.tf | 8 -------- iam/terragrunt.hcl | 3 +++ terragrunt.hcl | 16 ++++++++++++++++ 10 files changed, 34 insertions(+), 25 deletions(-) rename backend/{backend.tf => default.tf} (97%) create mode 100644 backend/terragrunt.hcl create mode 100644 budget/terragrunt.hcl create mode 100644 iam/terragrunt.hcl create mode 100644 terragrunt.hcl diff --git a/.gitignore b/.gitignore index 7a3e2fd..f3acdf7 100644 --- a/.gitignore +++ b/.gitignore @@ -16,6 +16,7 @@ crash.log # Ignore override files as they are usually used to override resources locally and so # are not checked in +**/backend.tf override.tf override.tf.json *_override.tf @@ -26,4 +27,4 @@ override.tf.json # !example_override.tf # Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan -# example: *tfplan* +*tfplan* diff --git a/backend/backend.tf b/backend/default.tf similarity index 97% rename from backend/backend.tf rename to backend/default.tf index dc55426..9157db1 100644 --- a/backend/backend.tf +++ b/backend/default.tf @@ -18,7 +18,7 @@ resource "aws_s3_bucket" "terraform" { } versioning { - enabled = true + enabled = true } } diff --git a/backend/main.tf b/backend/main.tf index 5342283..f0a5a46 100644 --- a/backend/main.tf +++ b/backend/main.tf @@ -1,12 +1,4 @@ terraform { - backend "s3" { - bucket = "terraform-nu2dp3915g" - key = "backend/state.tf" - region = "eu-west-1" - - dynamodb_table = "terraform" - } - required_providers { aws = { source = "hashicorp/aws" diff --git a/backend/terragrunt.hcl b/backend/terragrunt.hcl new file mode 100644 index 0000000..3e1f65a --- /dev/null +++ b/backend/terragrunt.hcl @@ -0,0 +1,3 @@ +include { + path = find_in_parent_folders() +} diff --git a/budget/budget.tf b/budget/budget.tf index f7f4642..b392899 100644 --- a/budget/budget.tf +++ b/budget/budget.tf @@ -35,7 +35,7 @@ resource "aws_sns_topic_subscription" "budget" { resource "aws_budgets_budget" "budget" { name = "budget" budget_type = "COST" - limit_amount = "25" + limit_amount = "25.0" limit_unit = "USD" time_unit = "MONTHLY" time_period_start = "2021-07-01_00:00" diff --git a/budget/main.tf b/budget/main.tf index 8963e47..2780ea4 100644 --- a/budget/main.tf +++ b/budget/main.tf @@ -1,10 +1,9 @@ terraform { - backend "s3" { - bucket = "terraform-nu2dp3915g" - key = "budget/state.tf" - region = "eu-west-1" - - dynamodb_table = "terraform" + required_providers { + aws = { + source = "hashicorp/aws" + version = "> 3.0" + } } } diff --git a/budget/terragrunt.hcl b/budget/terragrunt.hcl new file mode 100644 index 0000000..3e1f65a --- /dev/null +++ b/budget/terragrunt.hcl @@ -0,0 +1,3 @@ +include { + path = find_in_parent_folders() +} diff --git a/iam/main.tf b/iam/main.tf index 019b70c..2780ea4 100644 --- a/iam/main.tf +++ b/iam/main.tf @@ -1,12 +1,4 @@ terraform { - backend "s3" { - bucket = "terraform-nu2dp3915g" - key = "iam/state.tf" - region = "eu-west-1" - - dynamodb_table = "terraform" - } - required_providers { aws = { source = "hashicorp/aws" diff --git a/iam/terragrunt.hcl b/iam/terragrunt.hcl new file mode 100644 index 0000000..3e1f65a --- /dev/null +++ b/iam/terragrunt.hcl @@ -0,0 +1,3 @@ +include { + path = find_in_parent_folders() +} diff --git a/terragrunt.hcl b/terragrunt.hcl new file mode 100644 index 0000000..4dcaac4 --- /dev/null +++ b/terragrunt.hcl @@ -0,0 +1,16 @@ +remote_state { + backend = "s3" + + config = { + bucket = "terraform-nu2dp3915g" + dynamodb_table = "terraform" + encrypt = true + key = "${path_relative_to_include()}/state.tf" + region = "eu-west-1" + } + + generate = { + path = "override.tf" + if_exists = "overwrite_terragrunt" + } +}