In this tutorial, we will be executing Terraform code to create a new Azure Resource Group.
Prerequisites
- Microsoft Visual Studio Code.
- Terraform extension for Microsoft Visual Studio Code.
Code for creating a Resource Group
resource "azurerm_resource_group" "web_server_rg" { name="web-rg" location="westus2" }
Apply Changes
Within Microsoft Visual Studio Code;
- Right-click our TF file. In this example, it is Main.TF.
- Click Open in Terminal.
- Within the bottom of Microsoft Visual Studio Code, we have now received a terminal.
- Type terraform init and Press Enter. This initialises a new or existing Terraform configuration.
- Now, we can pilot our Terraform code to determine the changes it will commit to our azure environment using the command terraform plan. Press Enter.
- You will receive output within terminal advising of changes determined;
- If you are satisfied with pilot results, we can commit our changes to production with the command terraform apply. Press Enter.
- It will prompt you with the changes to be implemented; Type yes and press Enter to commit changes to production.
- Our Terraform Apply code completed successfully!
- Upon checking Azure Portal, we can now validate that our new Resource Group was successfully created.
Revert Changes
Now if you wish to revert changes you have made, you can simply execute command terraform destroy within our Visual Studio Code terminal.
Now we can validate within Azure Portal that our resource group was successfully deleted.