Understanding Terraform Resources and Data Sources on Azure
Create Azure resources with Terraform, query existing infrastructure using data sources, and combine both patterns in a single configuration.

Lab overview
Terraform manages cloud infrastructure through two complementary mechanisms - resources and data sources. A resource block declares infrastructure that Terraform creates, updates, and destroys as part of its lifecycle, while a data source queries existing infrastructure that was provisioned outside of the current configuration. Combining both patterns in a single project lets you deploy new components that reference pre-existing resources, such as attaching a network security group to a subnet that was created by a different team or an ARM template deployment.
In this lab, you will create Azure resources using Terraform resource blocks, query a pre-provisioned virtual network and subnet using data sources, and then combine both patterns by deploying a network security group that references the existing subnet through a data source. The lab environment provides a resource group with a VNet and subnet already provisioned, so you can focus on the Terraform workflow of creating new resources alongside existing ones.
Objectives
Upon completion of this beginner level lab, you will be able to:
- Configure the AzureRM Terraform provider and initialize a project
- Create Azure resources such as storage accounts using Terraform resource blocks
- Query existing Azure infrastructure using data source blocks for virtual networks and subnets
- Reference data source attributes in resource definitions to link new and existing infrastructure
- Deploy a network security group associated with a pre-existing subnet using terraform apply
Who is this lab for?
This lab is designed for:
- Cloud engineers learning how Terraform differentiates between managed and read-only infrastructure
- DevOps practitioners who need to integrate Terraform with environments that contain pre-existing resources
- Terraform Associate candidates preparing for exam objectives covering resources and data sources
Verified against your live environment
An automated validation engine inspects your actual resources and configurations as you work. Completion means the task was performed — not multiple choice, real-world proficiency.
More labs like this
Deploy a Full Azure Environment Using Bicep Infrastructure as Code
Write modular Bicep templates to deploy a VNet, App Service, SQL Database, and Key Vault, then deploy the full environment using Azure CLI.
Azure CLI Essentials: Managing Azure Resources with Command Line Tools
Master Azure CLI essentials by managing resource groups, deploying container apps and VMs, and managing resource states in this hands-on lab.
Introduction to Infrastructure as Code with Terraform on AWS
Write your first HCL configuration and deploy a DynamoDB table to AWS using Terraform's init, plan, and apply workflow.
Related reading
Environment
Every lab includes
- Real environment, pre-credentialed
- Automated checks on every step
- Isolated sandbox, auto cleanup
- AI-recommended next steps
Lab curriculum
- 01
Logging into Azure CLI
- 02
Creating Azure Resources with Terraform Resource Blocks
1 automated check
- 03
Querying Existing Infrastructure with Data Sources
1 automated check
- 04
Combining Resources and Data Sources Together
1 automated check
Skills validated
Not the lab you were looking for?
Browse 150+ hands-on labs across AWS, Azure, Kubernetes, Docker, and cloud security.