You already got an idea of the use case of Terraform and also about how we can connect to Azure using terraform. If not, please refer to my first two articles:So far we are able to connect to Azure and now, we will deploy some serious entities inside Azure using terraform. In this article, I thought to proceed with an Azure virtual machine deployment. We are expected to get the below entities inside Azure after this proposed Terraform deployment.
- A Windows 2016 server
- VNet with a dynamic public IP, Subnet, NSG, NIC etc...
- Connection ports open for HTTPS, WinRM and RDP. Able to connect using both RDP and WinRM
- VMAgent to run automatically
Terraform configuration(azurevm.tf) for this deployment has been uploaded here and only use that version for your reference. Below, I have explained the sections of interest so that you can refer to the configuration with a better understanding, rather than just following it.
Verification of this deployment includes the below steps. I am not mentioning about how to run a terraform configuration file as it has been mentioned in my previous articles.
- Successful Deployment
Please verify that you got something like below on command prompt before anything else.
- Verify Azure Portal
You should see something like the below image,
- Test RDP
You should be able to login with uid/pwd inside the configuration file. Below is the screenshot from my side after login using the IP showing in the Azure portal
- Verify WinRM
After your successful login above, open a command prompt as Admin in the same logged machine. Then run the below command to get the details of an HTTP listener for WinRM connection, as mentioned in our configuration.
- Verify Running VMAgent
In the same logged machine, open task manager and click more details option on the bottom left side of the task manager window. Then make sure that the below task is running.
- Verify Remote WinRM Connection
We should be able to connect to our new VM using WinRM remotely. So, again come back to your local machine from where you are running terraform. Open PowershellISE as Admin. Then try the below 4 commands. The first three commands are to establish a WinRM connection to our new VM and the fourth command is a normal command to make sure that the connected machine is our new VM.
That's all there is to show here. Please refer to the attached configuration file. In this series, next, I will show how to run certain bootstrap scripts during this VM deployment as part of Terraform. Until then, cheers.