Introduction

Terraform scripts are used to create, manage, and delete resources.

Prerequisites

Obtain the Terraform scripts from the public-cloud-automation project. These scripts are applicable to Terraform version v0.12.16.

Installing Terraform

  1. Download Terraform: Terraform Download Site.
  2. Install Terraform.
  3. Set the Terraform path in the environmental variables.

To verify that Terraform is installed, type terraform at the command line to display an options list.

Creating and managing resources

To create and manage the resources:

  • Ensure that the Terraform scripts are in place.
  • Add the access key and secret key for the service account to the variable_params.tf file.
  • Ensure that the provider.tf file has access to the project.
  • Place all of the required .tf files into the same folder.

Commands

The following Terraform commands are used to create, manage, and delete resources:

terraform init  - Initializes Terraform.
terraform plan  - Shows the list of actions.
terraform plan -out=plan_store - Stores and directly applies the plan.
terraform apply plan_store - Stores a plan in the plan_store.
terraform apply - Shows the list of actions and asks for permission to apply the plan's actions. 
terraform destroy - Destroys all the resources created with Terraform.

To execute a single type file, use the following commands:

terraform init
terraform plan -out=plan_store -target="resource_name.logical_name"

For example, to create only instances, use the following commands:

terraform plan -out=plan_store -target="amazon_compute_instance.instanceTest"
terraform apply plan_store

Resource list

Amazon API Gateway
Amazon AppSync
Amazon Athena
Amazon CodeDeploy
Amazon Cognito
Amazon Direct Connect
Amazon DocumentDB
Amazon DynamoDB
Amazon Elastic Block Store
Amazon EC2
Amazon Elastic File System
Amazon Elastic Transcoder
Amazon ElastiCache
Amazon Elastic Beanstalk
Amazon Firehose
Amazon Glue
AWS GuardDuty
Amazon Internet of Things
Amazon Kinesis
Amazon Key Management Service
Amazon Lambda
Amazon Elemental MediaConvert
Amazon Elemental MediaPackage
Amazon MQ
Amazon Managed Streaming for Kafka
Amazon Neptune
Amazon NAT Gateway
Amazon RDS
Amazon Redshift
Amazon Route 53
Amazon S3
Amazon SNS
Amazon SQS	
Amazon Step Functions
Amazon Simple Workflow Service
Amazon VPC
Amazon Web Application Firewall
AWS WAF
AWS Code Commit (Repository)

External reference