Creating an Instance using Terraform
Table of contents
As we know Terraform is an Infrastructure as a code, and it is useful for automating the infrastructure.
In this article, we will learn to automate the instance using Terraform.
Procedure:
1) Write instance.tf file
Here, we are providing the configuration for the instance like in what region we want to launch the instance, here we are launching the instance in us-east-1 region
In this we have also specified the ami type, instance type, availability-zone
We have also named the key-pair name and also the security group, we have also provided the tags like Dove-Instance and Dove
When our instance would be launched the name of the instance will appear as ‘Dove-Instance’
Note: Here we have already created the security group before launching the instance, that’s why we are providing security-group-id while launching the instance
2) Launch instance using terraform commands
→ After writing the instance.tf file, now apply commands to launch the instance.
→ Apply ‘terraform init’ command
→ Then apply ‘terraform validate’ command
→ Then apply ‘terraform fmt’
→ Then apply ‘terraform plan’
→ At last execute ‘terraform apply’ command