I had a recent discussion and mentioned that ChatGPT can certainly create Infrastructure as Code (IaC) scripts – specifically Terraform. I was not 100% sure if it would really work. Hence, I just played around to test it and the result is insane!
First of all, I asked ChatGPT what Terraform is:

The explanation and answer is fantastic.
Then, I decided to let ChatGPT do the work. Since this is AI, I thought to make it little more complex to see whether it can handle such a request.
Focus is on the following parameters that need to be considered in the Terraform script:
- Virtual Network name: VNet-ChatGPT
- Location: West EU (ChatGPT needs to translate into “West Europe”, otherwise this value will be incorrect)
- VNet address range: 10.123.0.0/16
- Two custom subnets named SN01 and SN02 that need to be part of the VNet’s address range
- Each subnet to be protected by an individual Network Security Group

The parameters have been identified successfully by ChatGPT. Even the correct name parameter has been used and set (for VNet, not for the resource group). The abbreviation NSG has been successfully understood and translated into Network Security Group and both subnets belong to the VNet’s address range.
All resources will be deployed in location “West Europe” as per Terraform script.
After we now have the complete script, we also need to test if it works!
First, I copy&pasted the code into a main.tf file and performed terraform init. No issues so far.

Next step is to validate the script by executing terraform validate. No issues so far! Looks good!

Now, the most interesting part will begin – the deployment to Azure.
The snippet has been shortened and you do not see the resources that have been deployed in detail, however, you can see the different steps and realize that there is no error! Terraform apply completed successfully and we can have a look at the Azure Portal.

It looks perfectly fine and ChatGPT delivered a fully functional terraform script based on the input.
It is insane!

I am looking forward to test more complex scenarios.
Potentially, I will let ChatGPT write a low level design concept document. Let’s see if it will work 😉