This is a Terraspace project. It contains code to provision Cloud infrastructure built with Terraform and the Terraspace Framework.
- Install Terraform version
1.0.5
or newer and Terraspace versionv0.6.18
or newer. I recommend to use docker, and mount the repository on it! Suggestion: try TFSWITCH - In this file
terraspace/infrastructure/config/terraform/backend.tf
. We use S3 as a Terraform backend to store your Terraform state, and S3 bucket names must be globally unique. The name currently in the file is already taken, so you'll have to specify your own. - Configure your AWS credentials in
accounts/dev-account.hcl
andaccounts/test-account.hcl
if you want both - Take a look to the makefile!
In the terraspace folder there is a Makefile
used to avoid errors given by copy-paste or wrong shell configuration. With this Makefile
you can initialize and then deploy everything or a single stack in the following way.
From the root folder:
cd terraspace
make dev-init
- this command is used to initialize the s3 bucket and dynamo db table used by terraform. It also configure properly the project. WARNING: Not override the files that already exists
Deploy full:
make dev-run
: create everything with a single commandmake dev-destroy
: destroy everything in the correct order
Deploy single:
make dev-vpc-plan
: let's see what we are going to createmake dev-vpc-run
: apply itmake dev-vpc-destroy
: destroy the stack
Remember: before deploy the EC2, you need to apply before the VPC!
In the make file there are multiple command. The makefile can be improved without too much effort!
The code in this repo uses the following folder hierarchy:
terraspace
└ infrastructure
└ app
| └ modules
| └ stacks
└ config
└ args
└ terraform
Where:
-
Infrastructure: Is the project name. The folder has been created by the
make dev-init
command. -
app: Refer to
terraspace cheat sheet
article in Medium -
config:
- args: custom flag that we can pass to
terraform
binary - terraform: here we configure the backend used by TF. Here you can configure variables shared across all the modules!
- args: custom flag that we can pass to
In the Makefile
in each command there is an export like TS_ENV="qa"
.
With this syntax, we are going to configure terraspace
to merge two files that exist in this folder terraspace/infrastructure/app/stacks/ec2-service/tfvars
:
base.tfvars
qa.tfvars
Do you want to configure in a different way the test
environment?
Simply configure TS_ENV="test"
that will merge:
base.tfvars
test.tfvars
This mechanism is applied everywhere, also for the tfvars
shared across all the modules and defined here terraspace/infrastructure/config/terraform/tfvars
In the Makefile
the only thing to do is to configure the correct credentials to use.
source ./../accounts/dev-account.sh
is the command to load the environment variables stored in that script.
The multi region is given with the method described here: https://terraspace.cloud/docs/tfvars/multi-region-layering/
The env variable is configured in the accounts/env-account.sh
. I suggest to move the env variable away from this file, and configure it in the makefile.