Deployment process
To deploy/build infrastructure with Terraform on any cloud provider platform, you will need to follow the below key steps.
- Scope
- Author
- Initialize
- Plan
- Apply
Scope
Before you begin with your infrastructure project, you first have to identify two prime elements:
Selecting the Cloud Provider: The first step is to choose the most appropriate cloud provider that suits your needs. The most prominent clouds to choose from are AWS, Microsoft Azure, Google Cloud Platform, and many more. Factors in making those decisions include specific requirements, budget, current investments, and services.
Identifying Needed Infrastructure: In this next step, you need to identify the elements of the infrastructure that your project will specifically require. This may include the compute resource elements such as VMs, Containers and serverless, followed by the storage or object, block, databases, networking, or VPCs and load balancers, security through IAM and encryption, etc. And so forth with other services, like CDN, queues, and event-driven.
Author
Now, write down the configuration for your infrastructure using terraform code. The configurations described in these files, written in Hashicorp Configuration Language (HCL), tell Terraform what your infrastructure should look like and change or create resources as necessary.
Initialize
Plugins or providers play an important role in Terraform while creating cloud resources. Providers act as a middleman between Terraform and the cloud environment; this is how it becomes easier for the user to manage its resources using Terraform.
In order to manage resources on any given cloud platform with Terraform you'll need to install the respective plugin/provider first. If you want to manage AWS resources, for example, you'll need the AWS provider. With the provider installed, Terraform can call out to AWS's APIs,
creating
, updating
, or deleting
any resources that your Terraform configuration has described.
command
terraform init
The terraform init command is used to initialize the Terraform working directory. During this initialization process, Terraform will automatically download and configure the necessary plugins based on the requirements specified in your terraform.tf
Plan
Terraform allows you to preview what changes it is going to make in your infrastructure before you make the changes. Really, this is a major feature that can help understand what is going to happen with your Terraform configuration and that change is what you expected.
This allows you to catch potential issues or unintended consequences of the changes to be implemented before they are finalized. This may come in handy, especially with respect to complex and critical infrastructure, where there could be downtime, loss of data, and other issues if the change had been approved without proper scrutiny.
command
terraform plan
When you run terraform plan, it compares your current infrastructure state to the desired state defined in your Terraform configuration and then generates an output with a detailed plan of what changes will need to be enacted: creating new resources, modifying resources already present, or deleting existing resources. This plan output gives you a concise summary of changes proposed in that plan so you can review and validate them before application.
Apply
After you have viewed the plan, and confirmed that the changes are good, then you can apply those changes to the infrastructure. This is the final step of the Terraform workflow where Terraform will enact the changes listed in the plan and update your infrastructure accordingly.
command
terraform apply
Running terraform apply will actually update your infrastructure according to the changes as specified in your plan. It might create new resources, modify some existing ones, or remove unused resources as defined in your plan.
Related Pages
Feedback
Was this page helpful?