Infrastructure deployments
Infrastructure is split to two repositories - Infra for portal and infra for sandbox instances.
Currently CICD is not yet used for deployments of infrastructure due security issues with it.
Infrastructure is written with Terraform modules and they are managed and deployed with a wrapper called Terragrunt. Terragrunt treats terraform files as modules and is designed to keep them DRY and reusable.
We use environment specific S3 buckets as a backend to our terraform state.
Usage
Environments are described in the live/
folder, currently playgorund, dev, QA and prod according to AWS Accounts document. For new environment, you can just copy a folder of one environment and change the values. In the live/<environment/env.hcl
.
Tools you need
Use cases
NOTE: remember to have needed credentials in place for the environment you are deploying
1. Deployment with terragrunt
Navigate to
live/<env>/<module>
When first time using this module or just not sure, run
terragrunt init
S3 backend should be on place. If it asks if you shall create one, check that you have your aws credentials in place and role assumed to correct environment.
Validate your configuration with
terragrunt validate
. Fix what is neededSay
terragrunt plan
to see what changes it will do. Check that it looks correctLastly, if everything is fine, apply your changes with
terragrunt apply
. It will run plan again and asks if you want to apply itCheck that your configuration works
NOTE: Terragrunt also has option for terragrunt run-all apply
. It propably won’t work.
2. Writing new module
Checkout the repository and create a new branch
Make a new folder for your module to
modules/
Write your code. Use variables, they are treated as inputs for the module in terragrunt side.
After it is working, create a Pull Request.
3. Terragrunt for a new module
For the corresponding environment(dev, qa, prod) create a folder for your module like
live/<env>/<your_module>
and createterragrunt.hcl
for that.This is where the input values are the same as variables in the terraform module
You can look for other modules as an example for it.
Navigate to
live/common
and createyour_module.hcl
for settings that apply all environments.Path to where the module will be found is described here
As before, others can be used as example
Extract the inputs from the env.hcl. and map them to module variables. You can do that like in the other files.
live/<environment>/env.hcl
contains variables for environment specific values.It is good place for i.e. version numbers
4. Completely new setting of all three envs
Fork the repo for your own use
Replace the values on every
live/<environment/env.hcl
for your corresponding ones. You should propably start with the dev.Navigate to
live/common
and change the values for your use also.Navigate to
live/dev/<module>
and runterragrunt init
If init is run succesfully, run
terragrunt plan
and review the resultsIf results seems to be good, you can run
terragrunt apply
. It runs plan again and asks you if you want to create them. Say yes.Repeat from step 4 to to all
live/<env>/<module>
foldersCongratulations, you now have your own environment
5. Just one new environment
Add a corresponding environment folder like
live/<your environment>
Copy files from an already running
live/<environment>
Follow the instructions from the previous case from step 2.