Skip to content
Snippets Groups Projects
Commit b437f06c authored by nimrod's avatar nimrod
Browse files

Terraform structure and an empty example.

parent 113046d8
No related branches found
No related tags found
No related merge requests found
# Terraform modules
This directory contains Terraform modules and a library of reusable modules
under `library`. Each module deploys a complete service. Although services will
be interconnected and there will be dependencies between services, the goal is
to keep the modules whole so that applying the module deploys the entire
service.
## A word on environments
Each module has a Terraform variables files (`.tfvars`) and a workspace for each
environment that service is deployed to. This puts the emphasis on keeping the
services the same across different environments with little changes, mainly for
scale (eg. 2 instances instead of 5).
## Common workflow
In this example, deploying to the dev environment. A convention is used for the
default workflow (have it be prod or dev or just not used).
```
terraform init
terraform workspace new dev
# Or if the workspace is already present:
terraform workspace select dev
terraform plan -var-file=dev.tfvars -out=tfplan
# Review the changes to be applied.
terraform apply tfplan
```
## Some more information here (like different providers, other conventions)
instance_count = 2
terraform {
backend "s3" {
bucket = "tf-states"
key = "foo.tfstate"
region = "us-east-1"
encrypt = true
dynamodb_table = "tf-locks"
}
}
locals {
env = terraform.workspace == "default" ? "prod" : terraform.workspace
module = basename(abspath(path.root))
}
provider "aws" {
default_tags {
tags = {
Environment = local.env
# Easy to track down which module created a resource.
Module = local.module
}
}
}
instance_count = 3
variable "instance_count" {
type = number
description = "The number of instances to deploy."
# If the convention is not to use the default workspace, delete the default
# value.
default = 5
}
# Terraform module library
A library of reusable modules (not to deployed by themselves).
# Auto scaling group
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment