Introduction
Terraform scripts are used to create, manage, and delete resources.
Note
Resources are deleted after use.Prerequisites
Obtain the Terraform scripts from the public-cloud-automation
project.
These scripts are applicable to Terraform version v0.12.16.
Installing Terraform
- Download Terraform: https://www.terraform.io/downloads.html.
- Install Terraform.
- 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 subscription id, client id, client secret, tenant id, and Azure version for the service account
to the
terraform.tfvars
file. - Ensure that the
provider.tf
file has access to the project. - Place all of the required
.tf
files into the same folder.
Tip
If you need to create a set of resources, then put all those resources.tf
files
in the same folder as the provider.tf
, variables.tf
, and terraform.tfvars
files.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.
Notes
- By storing a plan in the
plan_store
, the permission query is bypassed when applying the plan. - When a folder contains all types of
.tf
files, only a particular type of.tf
file should be executed.
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 an app service, use the following commands:
terraform plan -out=plan_store -target="azurerm_app_service.app_service"
terraform apply plan_store
Resource list
Application Service
App Service Plan
Application Gateway
Automation account
Automation credentials
Automation Schedule
Batch Account
Cognito
Data Factory
Data Lake
DocumentDB
Event Grid
Express Route
IOT Hub
Maria DB
Mysql DB
Mysql Server
Network Interface
Postgrsdb
Public IP
Virtual Machine
Virtua Network