How to Install Terraform on CentOS?
Install steps for terraform:
Step1: Install yum-config-manager to manage your repositories.
$ sudo yum install -y yum-utils
Step2: Use yum-config-manager to add the official HashiCorp Linux repository.
$ sudo yum-config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo
Install Terraform from the new repository.
$ sudo yum -y install terraform
Step3: Then install the autocomplete package.
$ terraform -install-autocomplete
Step4: Create a directory named learn-terraform-docker-container.
$ mkdir learn-terraform-docker-container
Step5: Next, cd into the learn-terraform-docker-container directory
$ cd learn-terraform-docker-container
Step6: In the working directory, create a file called main.tf and paste the following Terraform configuration into it.
$ vi main.tf
terraform {
required_providers {
docker = {
source = "kreuzwerker/docker"
version = "~> 3.0.1"
}
}
}
provider "docker" {}
resource "docker_image" "nginx" {
name = "nginx"
keep_locally = false
}
resource "docker_container" "nginx" {
image = docker_image.nginx.image_id name = "tutorial"
ports {
internal = 80
external = 8000
}
}
Step7: Initialize the project, which downloads a plugin called a provider that lets Terraform interact with Docker.
$ terraform init
Step8: Provision the NGINX server container with apply. When Terraform asks you to confirm type yes and press ENTER.
$ terraform apply
Verify the existence of the NGINX container by visiting
Step9: in your web browser or running docker ps to see the container.Dash will be displayed.To stop the container, run terraform destroy.
$terraform destroy.
Thanks to our interns who participated in this initiative.
Thank you for reading this article. We are happy to prepare articles as per your request. Please comment on which tool you want installation process. Also please comment in any issues with above installation.