From 5e3e95a1b54949cfd9847cff8624e4e229a0e886 Mon Sep 17 00:00:00 2001 From: Daniel Tomlinson Date: Thu, 16 Jul 2020 00:06:21 +0100 Subject: [PATCH] Updating documentation --- .gitignore | 2 ++ .vscode/settings.json | 4 ++- terraform.md | 60 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 terraform.md diff --git a/.gitignore b/.gitignore index dd3d655..521b971 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,5 @@ blog/static test/ .DS_Store +# terraform +.terraform/ diff --git a/.vscode/settings.json b/.vscode/settings.json index 46ef36a..ab8fe81 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,5 +1,4 @@ { - "editor.defaultFormatter": "akmittal.hugofy", "editor.formatOnPaste": false, "[html]": { "editor.defaultFormatter": "HookyQR.beautify" @@ -11,5 +10,8 @@ "twig-language-2.endComma": "always", "[scss]": { "editor.defaultFormatter": "HookyQR.beautify" + }, + "[tfvars]": { + "editor.defaultFormatter": "hashicorp.terraform" } } diff --git a/terraform.md b/terraform.md new file mode 100644 index 0000000..cd462ff --- /dev/null +++ b/terraform.md @@ -0,0 +1,60 @@ +# Terraform + +## Structure + +The following should go in the root of your project - this is for the LS VSCode which needs the terraform in the root of the project. + +Place the `Makefile` in the root of this folder. + +Create a `Makefile.env` file + +Create a `./variables` folder and create `.tfvars` files in here with the naming convention `stage-environment.tfvars` e.g `prod-us-east-2.tfvars`. + +You can then create a `main.tf`, `outputs.tf` and `variables.tf` file in the root of your folder. + +## Makefile + +Using the makefile from . + +`wget https://raw.githubusercontent.com/pgporada/terraform-makefile/master/Makefile`. + +Current version has a pull request pending that fixes a dynamo db issue: + +`wget https://raw.githubusercontent.com/geftactics/terraform-makefile/geftactics-dynamodb-check/Makefile`. + +- Add `-include Makefile.env` after the `.PHONY` entry to the `Makefile`. +- Change the `S3_BUCKET` and `DYNAMODB_TABLE` to: + +```env +S3_BUCKET="$(ENV)-$(REGION)-$(PROJECT)-terraform" +DYNAMODB_TABLE="$(ENV)-$(REGION)-$(PROJECT)-terraform" +``` + +In the `Makefile.env` add the environment variables needed for the `Makfile`: + +```env +ENV="prod" +REGION="eu-west-1" +PROJECT="panaetius-blog" +AWS_PROFILE="admin" +``` + +### Options + +```text +$ make +apply Have terraform do the things. This will cost money. +destroy-backend Destroy S3 bucket and DynamoDB table +destroy Destroy the things +destroy-target Destroy a specific resource. Caution though, this destroys chained resources. +plan-destroy Creates a destruction plan. +plan Show what terraform thinks it will do +plan-target Shows what a plan looks like for applying a specific resource +prep Prepare a new workspace (environment) if needed, configure the tfstate backend, update any modules, and switch to the workspace +``` + +## Commands + +### New project + +`gmake prep` - this will create an S3 bucket for tfstate and a DynamoDB table for the lock state.