The routing module that you are going to implement has the following folder structure:
routing/
│
├── main.tf
│
├── outputs.tf
│
├── providers.tf
│
├── state.tf
│
├── terraform.tfvars
│
├── variables.tf
│
└── versions.tf
You then start building the configuration files required for the routing module and triggering the first Terraform Cloud run for the module manually.
1. Do the following instructions to create Terraform configurations for the module.
Fill the following lines of code to routing/versions.tf:
terraform {
required_version = ">= 1.0.0, < 2.0.0"
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 4.5"
}
}
}
Fill the following lines of code to routing/state.tf:
terraform {
cloud {
organization = "aws-first-cloud-journey"
workspaces {
project = "workshop-1"
name = "dev-routing"
}
}
}
Fill the following lines of code to routing/variables.tf:
variable "region" {
description = "The AWS region of the project"
type = string
}
variable "environment" {
description = "The environment to which the project delploys"
type = string
default = "dev"
}
variable "project_name" {
description = "The name of the project"
type = string
}
variable "hosted_zone_name" {
description = "The name of the hosted zone"
type = string
}
Fill the following lines of code to routing/terraform.tfvars. Replace <your-domain-name> to yours, mine is tulna07.site for example. You can buy one with Route53 or other domain main registrars.
region = "us-east-1"
environment = "dev"
project_name = "workshop-1"
hosted_zone_name = <your-domain-name>
Fill the following lines of code to routing/providers.tf:
provider "aws" {
region = var.region
}
Fill the following lines of code to routing/main.tf. Remember to replace <your-github-username> with your GitHub username:
module "routing" {
source = "git::https://github.com/<your-github-username>/workshop-1-tf-modules.git//modules/routing?ref=v1.0.0"
environment = var.environment
project_name = var.project_name
hosted_zone_name = var.hosted_zone_name
}
Fill the following lines of code to routing/outputs.tf:
output "hosted_zone_name_servers" {
description = "The name servers for the hosted zone"
value = module.routing.hosted_zone_name_servers
}
output "hosted_zone_id" {
description = "The name servers for the hosted zone"
value = module.routing.hosted_zone_id
}
2. Commit and push the module to the GitHub repository.
git add . && \
git commit -m "add routing module" && \
git push
3. Navigate to your dev-routing Terraform Cloud workspace interface. Click Settings.
4. Scroll down to Remote state sharing section. Select Share with specific workspaces. Click the Select workspaces to share with dropdown, choose dev-app and dev-web. Click Save settings.
5. Back to dev-routing Terraform Cloud workspace interface. Click New run.
6. Click Start.
7. Wait until the plan is finished. After that, review the plan.
8. If everything is fine, scroll down to the bottom and click Confirm & apply.
9. Optionally, add a comment Look good to me!
. Click Confirm plan, Terraform will run apply and provision AWS resources for you.
10. After Terraform has done the applying process, you need to get some module’s ouputs in the next step.
11. Click the Outputs dropdown. Get the name servers that the routing module generates.
12. Add your Route53 name servers from step 11 to your registrar where you buy your domain name. Mine is GoDaddy, for example.
13. Go to AWS Route53 console.
14. In the left sidebar, click Hosted zones to check out your newly created hosted zone.