Deploy the Infrastructure

Before deploying the infrastructure, we need to create one more file named terraform/terraform.tfvars.

In the first section, we created the variables.tf file to declare all input variables, such as the project name, deployment environment, and email address, together with their default values. The terraform.tfvars file is where you provide the actual values that will be used for your deployment. Keeping these values separate makes the Terraform code more flexible and reusable. If you want to share the project with someone else or update the email address or project name, you only need to modify the terraform.tfvars file without changing the infrastructure configuration in the other Terraform files. Terraform automatically detects and loads values from the .tfvars file during execution.

# Required
aws_region          = "us-east-1" # AWS Region where the infrastructure will be deployed
environment         = "dev" # Deployment environment such as dev, test, or prod
project_name        = "[YOUR_PROJECT_NAME]"
alert_email         = "[EMAIL]" # Email address that will receive notifications
schedule_expression = "rate(1 day)" # Schedule expression for the automated task

After completing all of the files above, open a terminal, navigate to the project directory that contains the Terraform files, and run the following commands to deploy the infrastructure.

1. Preview the resources that Terraform will create.

terraform plan

Deploy Infrastructure

2. Deploy the infrastructure.

terraform apply

Deploy Infrastructure

  • Type yes to confirm the deployment.

Deploy Infrastructure

3. After the deployment is complete, Terraform displays the output values that were defined in outputs.tf.

Deploy Infrastructure

4. Verify the deployed resources and confirm the email subscription.

After the deployment is complete, verify that the following resources have been created successfully in the AWS Management Console.

  • S3 Bucket:

Deploy Infrastructure

  • SQS Queue:

Deploy Infrastructure

  • SNS Topic:

Deploy Infrastructure

  • EventBridge rule:

Deploy Infrastructure

  • Confirm the email subscription:

Deploy Infrastructure

Click Confirm subscription.

Deploy Infrastructure

Next Content