Skip to content

Terraform Tutorial on AWS

  • Available for Hire: Mentorship, On-the-Job Support, Consulting – me@antonputra.com
  • Source Code: GitHub Repo.

Commands from the Tutorial

  • Initialize Terraform and download providers.
terraform init
  • Create a plan with changes Terraform would perform.
terraform plan
  • Create a local AWS profile.
aws configure --profile my-user
  • Retrieve the current user from AWS and verify authentication.
aws sts get-caller-identity --profile my-user
  • Add a local AWS profile.
vim ~/.aws/config
  • Verify that the user can assume the IAM role.
aws sts assume-role \
 --role-arn arn:aws:iam::424432388155:role/terraform-admin \
 --role-session-name terraform \
 --profile my-user
  • Apply infrastructure changes to your AWS account.
terraform apply
  • Automatically apply changes, used mostly in CI/CD.
terraform apply --auto-approve
  • Apply changes specific to a single resource.
terraform apply -target aws_instance.ubuntu
  • Import infrastructure component to Terraform.
terraform import aws_instance.ubuntu i-0ed0b68051adae5b4
  • Remove infrastructure component from Terraform management.
terraform state rm aws_instance.ubuntu