Managing Resources with Terraform

Overview

In this section, we will execute Terraform commands to create and manage resources on AWS.

Execution

First, open a terminal and navigate to the directory containing your Terraform configuration files.

cd path/to/terraform/files

Next, run the following commands:

terraform init

This command initializes Terraform and downloads necessary plugins for the providers declared in the configuration files.

terraform plan

This command examines the configuration and displays the expected changes to be applied when running terraform apply.

terraform apply -auto-approve

This command applies the changes to the AWS infrastructure automatically without requiring user confirmation.

Check the Results

After running the terraform apply command successfully, verify on the AWS interface to ensure that the resources have been created and configured as expected.

Successful Apply command:

Alt text

Check S3:

Alt text

Check CodeCommit:

Alt text

Check CodeBuild:

Alt text

Check CodePipeline:

Alt text

Access the website via S3 Static Web URL:

Alt text

Cleanup

Once you have completed your work and want to delete the created resources, you can run the following command:

terraform destroy -auto-approve

This command will automatically delete all resources created by Terraform without requiring user confirmation.