다음을 통해 공유


Azure: Deploy Bastion Host using Terraform

Before we see how we can deploy Azure Bastion using Terraform, it would be nice to read a couple of useful information about it.

The last years introduced to the IT/DevOps world, the IaC (Infrastructure as a Code). A new way that allows us to manage and provision cloud resources via configuration files. There are several IaC in the market like Azure ARM templates, chef, puppet, Terraform etc. In this post, we will talk about Terraform on Azure.

Terraform is an open-source tool provided by Hashicorp. This tool helps us to provision and manage cloud infrastructure resources.

Note

Before we begin with Terraform Installation/configuration, we must make sure that we have a valid Azure subscription. If we don't, then we must create one.

How to Install Terraform

To install Terraform on a Windows 10 OS we need to follow the steps below:

  1. Download Terraform
  2. Extract the  terraform.exe file to a location on the OS, e.g. C:\Terraform
  3. Create a New environment variable on Path system variables, e.g.

To verify the installation we must run the command terraform -version on a PowerShell tab.

Since we've got an Azure Subscription and we did the appropriate installation and configuration as the steps above explained,  we have to download Visual Studio Code, and then install the Azure Terraform extension from the marketplace.

Azure Terraform Sample

By following the instructions below, we can deploy a Virtual Network, a VM, and an Azure Bastion host to the target Virtual Network.

Download the deployment files

After completing the steps above, we need to create two new files in the C:\Terraform folder

Info: The Terraform files have the .tf extension.

We can download the main.tf and variables.tf from my GitHub repo, in this link.

Deploying The Resources

Launch an elevated Windows terminal and start executing the commands as the images below shows.

  1. terraform init: This command initializes the working directory (D:\Terraform\ and downloads the latest version. For more details click here
  2. terraform plan: This command locates the configuration files in the folder (D:\Terraform\, evaluates the configuration and determines what changes need to be done in the file in order by valid for execution. For more details click here
  3. terraform apply: This command will start to deploy the resources on the Azure tenant. For more details click here

            

Before the deployment starts we must approve it by typing "yes".

            

The final step is to find the VM into the Resource Group (mytest-resources) and, select Operations - Bastion, and click the button Create.

            

         

A few minutes later the Azure Bastion Host is ready to use.

          

See Also