Terraform one of the famous open source tool used for planning, deploying and maintaining infrastructure as a code and the beauty of this tool is that it works across various cloud service providers.
Even though I personally like the AWS Cloudformation, it is AWS only and most probably it will always remain limited to Amazon Web Services. It has few advantages over other tools when using with AWS and will be the first to have new AWS features incorporated before other tools and APIs catch up.
However if you are not limiting yourself to AWS only or have hybrid environment you may want to use a 3rd party tool compatible for all cloud infrastructures. Terraform being one of them is youngest client only tool and this article will help you setting up your desktop environment and give you understanding of how it works before you can start to code.
Downloads:
Download Terraform directly from the creator HashiCorpp
Download open source code editor - Visual Studio Code from Microsoft
You could also adopt the Chocolatey to install packages using Linux like commands.
c:\choco install terraform
Alternatively you download Terraform executable and place it in a folder such as C:\Terraform\Terraform.exe. Essentially the executable is all you need but you'll have to manually set up environment variable to execute it from anywhere in console by adding path to environment variable %path%. In order to add path you'll have to go to Control Panel to System and Security > System > Advanced System Settings > Environment Variables. You then open path for user only or system variables and add path to Terraform.exe to the list.
Code editing can be performed by any editor such as Notepad, Notepad++ or for better editor you could choose to install downloaded code editor from Microsoft called Visual Studio Code.
You then need to write a Terraform format file and using the executable you can plan, apply or destroy your infrastructure defined within your terraform file with .tf extension and variables in file named terraform.tfvars available within same folder.
So your project will look like below;
.ProjectName
└──mainproject.tf
└──terraform.tfvars
You need to go to Command Prompt or use terminal within Visual Studio Code which uses powershell and change your working directory to ProjectName.
cd c:\users\username\documents\projectname
Once you are in your working folder and have your first project with variables, providers and resources defined you need to get the provider api or executables downloaded which can be done simply by typing following command.
terraform.exe init
You can also check list of providers by using the command bellow.
terraform.exe providers
With your sample project ready you can see what the implementation will look like by using command below. This will tell you what terraform will do including number of resources to be added, changed or destroyed.
terraform.exe plan
If you are happy with the plan you can run the plan by executing command below.
terraform.exe apply
Changes to the original plan can be implemented by executing above command again after modifying your main project .tf file. However please ensure that you do not make any changes to other system generated files.
Please pay attention to the full output.
Once you have finished with your project you can destroy everything that was created using this project by executing below.
terraform.exe destroy
The sample project to create a single web server is available in this blog.
Even though I personally like the AWS Cloudformation, it is AWS only and most probably it will always remain limited to Amazon Web Services. It has few advantages over other tools when using with AWS and will be the first to have new AWS features incorporated before other tools and APIs catch up.
However if you are not limiting yourself to AWS only or have hybrid environment you may want to use a 3rd party tool compatible for all cloud infrastructures. Terraform being one of them is youngest client only tool and this article will help you setting up your desktop environment and give you understanding of how it works before you can start to code.
Prerequisites:
Computer running Windows, Linux, Solaris or MacOS operating system.Downloads:
Download Terraform directly from the creator HashiCorpp
Download open source code editor - Visual Studio Code from Microsoft
You could also adopt the Chocolatey to install packages using Linux like commands.
Setting up Windows desktop:
Using Chocolatey you can run following command to install Terraform and it will set environment variables for you automatically.c:\choco install terraform
Alternatively you download Terraform executable and place it in a folder such as C:\Terraform\Terraform.exe. Essentially the executable is all you need but you'll have to manually set up environment variable to execute it from anywhere in console by adding path to environment variable %path%. In order to add path you'll have to go to Control Panel to System and Security > System > Advanced System Settings > Environment Variables. You then open path for user only or system variables and add path to Terraform.exe to the list.
Code editing can be performed by any editor such as Notepad, Notepad++ or for better editor you could choose to install downloaded code editor from Microsoft called Visual Studio Code.
You then need to write a Terraform format file and using the executable you can plan, apply or destroy your infrastructure defined within your terraform file with .tf extension and variables in file named terraform.tfvars available within same folder.
So your project will look like below;
.ProjectName
└──mainproject.tf
└──terraform.tfvars
You need to go to Command Prompt or use terminal within Visual Studio Code which uses powershell and change your working directory to ProjectName.
cd c:\users\username\documents\projectname
Once you are in your working folder and have your first project with variables, providers and resources defined you need to get the provider api or executables downloaded which can be done simply by typing following command.
terraform.exe init
You can also check list of providers by using the command bellow.
terraform.exe providers
With your sample project ready you can see what the implementation will look like by using command below. This will tell you what terraform will do including number of resources to be added, changed or destroyed.
terraform.exe plan
If you are happy with the plan you can run the plan by executing command below.
terraform.exe apply
Changes to the original plan can be implemented by executing above command again after modifying your main project .tf file. However please ensure that you do not make any changes to other system generated files.
Please pay attention to the full output.
Once you have finished with your project you can destroy everything that was created using this project by executing below.
terraform.exe destroy
The sample project to create a single web server is available in this blog.