Examine the evolution of virtualization technologies from bare metal, virtual machines, and containers and the tradeoffs between them.
Install terraform and configure it to work with AWS
Learn the common terraform commands and how to use them
ā¢Terraform Plan, Apply, Destroy
Use Terraform variables and outputs to improve make our configurations more flexible
Explore HCL language features in Terraform to create more expressive and modular infrastructure code.
Learn to break your code into modules to make it flexible and reuseable
Overview of two primary methods for managing multiple Terraform environments
Techniques for testing and validating Terraform code
Covers how teams generally work with Terraform, including automated deployment with CI/CD
In this lesson, we will demonstrate how to use subdirectories to manage multiple environments for our sample web application.
We will create two environments, production and staging, and deploy the web application to both environments using a directory layout approach.
Create a three new subdirectories: global
, production
, and staging
.
The global
directory will contain resources shared across multiple environments, such as the Route 53 Zone. Add a main.tf
file in the global
directory with the Terraform block and the resource for the Route 53 Zone.
# Route53 zone is shared across staging and production
resource "aws_route53_zone" "primary" {
name = "MY_DOMAIN.com"
}
production
and staging
directories, create a main.tf
file defining the options for the module being deployed.These files will be similar to the previous examples, but set the create_dns_zone
variable to false
since the DNS zone is managed in the global
directory.
āÆ tree ./
.
āāā global/
ā āāā main.tf
āāā production/
ā āāā main.tf
āāā staging/
āāā main.tf
3 directories, 4 files
Navigate to the global
directory, initialize Terraform using terraform init
, and apply the configuration using terraform apply
. This step will create the shared Route 53 Zone.
Navigate to the production
directory, initialize Terraform using terraform init
, and apply the configuration using terraform apply
. This will deploy the production environment.
Navigate to the staging
directory, initialize Terraform using terraform init
, and apply the configuration using terraform apply
. This will deploy the staging environment.
In this lesson, we demonstrated how to use subdirectories to manage multiple environments for our sample web application.
We created two environments, production and staging, and deployed the web application to both environments using a directory layout approach.
This method offers clear organization and is easy to understand, but has some downsides such as code repetition and limitations in templating the backend provider.