Provision a Storage Account with Terraform
Task Details
- Create a Terraform template in Visual Studio Code to provision an Azure Storage Account.
- Install the Terraform CLI on your local machine.
- Upload and deploy the Terraform template using the Bash CLI to create the Storage Account in Azure.
- Bonus: Use the Azure Storage Account module from the Terraform Registry to create a storage account.
*
Steps
1. Launch Visual Studio Code on your computer.
- Create a new file by selecting File → New File from the menu.
Note: Download Visual Studio Code from here: https://code.visualstudio.com/Download

*
2. Name the file main.tf and press Enter. This file will serve as the primary Terraform configuration where we define our infrastructure setup.

*
3. Save the main.tf file to your computer.

*
4. Let’s define the Terraform configuration. In the main.tf file, specify the Azure provider and the required version as shown below:
Note: If your Terraform code appears in plain white text, you need to install the Terraform extension in Visual Studio Code.

*
5. Look in the bottom-right corner of VS Code, it should say “Terraform.”
- If it says Plain Text or something else:
- Click it.

*
6. Select Terraform from the list. If it is not available, download the Windows (x64) version from the following link: https://developer.hashicorp.com/terraform/install?utm_source=chatgpt.com
*
Install Terraform CLI
1. You need the Terraform command-line tool first:
- Go to Terraform Downloads.(above link)
- Unzip it to a folder, e.g., C:\Terraform. (make sure the terraform.exe in folder named Terraform)
- Add the folder to your PATH environment variable:
- Search Environment Variables → Edit → Path → Add C:\Terraform.

*
2. Click on Environment Variables… to open the system environment settings.

*
3. Click on “Path” and add the folder location of terraform.exe (in this case, C:\Terraform)

*
4. Click “New,” enter C:\Terraform, and then click “OK.”

*
5. Open a new PowerShell/Command Prompt and run:
Copy Command: terraform -v
You should see the Terraform version printed.

*
Install the Terraform VS Code extension and create a Terraform template to provision a Storage Account.
1. Open VS Code.
- Press Ctrl+Shift+X (or click Extensions icon).
- Search for “HashiCorp Terraform”.
- Click Install.
Note: This gives you syntax highlighting, IntelliSense, and snippets for .tf files.

*
2. Reference an Existing Resource Group. Replace <resource-group-name> with the name of your resource group, which can be found in your Azure credentials section.




















