Skip to content

Commit ed26e8d

Browse files
authored
Merge pull request #41 from MicrosoftCloudEssentials-LearningHub/data-factory
Data factory
2 parents a3ed88b + 1e4d3db commit ed26e8d

8 files changed

Lines changed: 268 additions & 0 deletions

File tree

5_analytics-bigdata/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ Last updated: 2026-02-09
1212
> [!IMPORTANT]
1313
> This folder contains sample Terraform templates for Azure analytics and big data services. These templates are starting points and should be customized based on your application needs.
1414
15+
## Templates available
16+
17+
- [Azure Data Factory](./data-factory)
18+
1519
<!-- START BADGE -->
1620
<div align="center">
1721
<img src="https://img.shields.io/badge/Total%20views-1706-limegreen" alt="Total views">
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# Terraform Template - Azure Data Factory
2+
3+
Costa Rica
4+
5+
[![GitHub](https://img.shields.io/badge/--181717?logo=github&logoColor=ffffff)](https://github.com/)
6+
[brown9804](https://github.com/brown9804)
7+
8+
Last updated: 2026-02-11
9+
10+
------------------------------------------
11+
12+
> This template contains Terraform configurations to create an Azure Data Factory instance with a system-assigned managed identity.
13+
14+
> [!NOTE]
15+
>
16+
> - This template creates the Resource Group for you.
17+
> - Azure Data Factory names are globally unique. If you disable `append_random_suffix`, you may hit `DataFactoryNameInUse` and need to change `data_factory_name`.
18+
19+
<div align="center">
20+
<img width="650" alt="image" src="https://github.com/user-attachments/assets/49954b0e-348c-4b6f-bb84-c5939452ae17" style="border: 2px solid #4CAF50; border-radius: 5px; padding: 5px;"/>
21+
</div>
22+
23+
<div align="center">
24+
<img width="650" alt="image" src="https://github.com/user-attachments/assets/6106e50d-0c7e-4eab-8845-12bc6ee10069" style="border: 2px solid #4CAF50; border-radius: 5px; padding: 5px;"/>
25+
</div>
26+
27+
<div align="center">
28+
<img width="650" alt="image" src="https://github.com/user-attachments/assets/966f05b9-3a25-467c-9ca8-659c15a1cf3b" style="border: 2px solid #4CAF50; border-radius: 5px; padding: 5px;"/>
29+
</div>
30+
31+
## File Descriptions
32+
33+
- **main.tf**: Creates the Resource Group and Azure Data Factory.
34+
- **variables.tf**: Defines the input variables used in the Terraform configuration.
35+
- **provider.tf**: Configures the Azure provider to interact with Azure resources.
36+
- **terraform.tfvars**: Provides example values for the variables defined in `variables.tf`.
37+
- **outputs.tf**: Defines outputs such as the Data Factory ID and managed identity principal ID.
38+
39+
## Variables
40+
41+
| Variable Name | Description | Type | Example Value |
42+
| --- | --- | --- | --- |
43+
| `resource_group_name` | Resource Group name to create/deploy into. | string | `"rg-analytics-dev"` |
44+
| `location` | Azure region for the deployment. | string | `"eastus"` |
45+
| `data_factory_name` | Base Azure Data Factory name. If random suffix is enabled, final name is `<base>-<suffix>`. | string | `"adf-analytics-dev"` |
46+
| `append_random_suffix` | Append a random suffix to avoid global name collisions. | bool | `true` |
47+
| `random_suffix_length` | Length of the random suffix when enabled. | number | `6` |
48+
| `public_network_enabled` | Enable/disable public network access for Data Factory. | bool | `true` |
49+
| `tags` | Tags applied to resources. | map(string) | `{ "env": "dev" }` |
50+
51+
## Usage
52+
53+
1. Authenticate:
54+
55+
```sh
56+
az login
57+
````
58+
59+
```sh
60+
az account show
61+
# If needed:
62+
az account set --subscription "<subscription-id-or-name>"
63+
```
64+
65+
3. Initialize:
66+
67+
```sh
68+
terraform init -upgrade
69+
```
70+
71+
4. Validate and plan:
72+
73+
```sh
74+
terraform validate
75+
terraform plan
76+
```
77+
78+
5. Apply:
79+
80+
```sh
81+
terraform apply -auto-approve
82+
```
83+
84+
<!-- START BADGE -->
85+
<div align="center">
86+
<img src="https://img.shields.io/badge/Total%20views-1706-limegreen" alt="Total views">
87+
<p>Refresh Date: 2026-02-11</p>
88+
</div>
89+
<!-- END BADGE -->
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# main.tf
2+
# This file contains the main configuration for creating an Azure Data Factory.
3+
# It creates a Resource Group and an Azure Data Factory with a system-assigned managed identity.
4+
5+
resource "azurerm_resource_group" "example" {
6+
name = var.resource_group_name
7+
location = var.location
8+
9+
tags = var.tags
10+
}
11+
12+
resource "random_string" "suffix" {
13+
length = var.random_suffix_length
14+
upper = false
15+
special = false
16+
numeric = true
17+
18+
keepers = {
19+
resource_group_name = var.resource_group_name
20+
location = var.location
21+
base_name = var.data_factory_name
22+
}
23+
}
24+
25+
locals {
26+
data_factory_name_final = var.append_random_suffix ? "${var.data_factory_name}-${random_string.suffix.result}" : var.data_factory_name
27+
}
28+
29+
resource "azurerm_data_factory" "example" {
30+
name = local.data_factory_name_final
31+
location = azurerm_resource_group.example.location
32+
resource_group_name = azurerm_resource_group.example.name
33+
34+
public_network_enabled = var.public_network_enabled
35+
36+
identity {
37+
type = "SystemAssigned"
38+
}
39+
40+
tags = var.tags
41+
42+
depends_on = [
43+
azurerm_resource_group.example
44+
]
45+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# outputs.tf
2+
3+
output "resource_group_id" {
4+
description = "The ID of the resource group."
5+
value = azurerm_resource_group.example.id
6+
}
7+
8+
output "data_factory_id" {
9+
description = "The resource ID of the Azure Data Factory."
10+
value = azurerm_data_factory.example.id
11+
}
12+
13+
output "data_factory_name" {
14+
description = "The name of the Azure Data Factory."
15+
value = azurerm_data_factory.example.name
16+
}
17+
18+
output "data_factory_principal_id" {
19+
description = "The system-assigned managed identity principalId for the Data Factory."
20+
value = azurerm_data_factory.example.identity[0].principal_id
21+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# provider.tf
2+
# This file configures the Azure provider to interact with Azure resources.
3+
# It specifies the required provider and its version, along with provider-specific configurations.
4+
5+
terraform {
6+
required_version = ">= 1.8, < 2.0"
7+
8+
required_providers {
9+
azurerm = {
10+
source = "hashicorp/azurerm"
11+
version = "~> 3.116"
12+
}
13+
14+
random = {
15+
source = "hashicorp/random"
16+
version = "~> 3.6"
17+
}
18+
}
19+
}
20+
21+
provider "azurerm" {
22+
features {
23+
resource_group {
24+
prevent_deletion_if_contains_resources = false
25+
}
26+
}
27+
28+
# Uses the current Azure CLI context (az login + az account set)
29+
skip_provider_registration = false
30+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
resource_group_name = "rg-analytics-dev"
2+
location = "eastus"
3+
4+
# Data Factory name must be globally unique.
5+
# This template appends a random suffix by default to reduce collisions.
6+
data_factory_name = "adf-analytics-dev"
7+
8+
append_random_suffix = true
9+
random_suffix_length = 6
10+
11+
public_network_enabled = true
12+
13+
tags = {
14+
env = "dev"
15+
area = "analytics-bigdata"
16+
iac = "terraform"
17+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# variables.tf
2+
# This file defines the input variables used in the Terraform configuration.
3+
4+
variable "resource_group_name" {
5+
description = "The name of the Azure Resource Group to create and deploy the Data Factory into."
6+
type = string
7+
8+
validation {
9+
condition = length(trimspace(var.resource_group_name)) > 0
10+
error_message = "resource_group_name must not be empty."
11+
}
12+
}
13+
14+
variable "location" {
15+
description = "The Azure region where the Resource Group and Data Factory will be created."
16+
type = string
17+
18+
validation {
19+
condition = length(trimspace(var.location)) > 0
20+
error_message = "location must not be empty."
21+
}
22+
}
23+
24+
variable "data_factory_name" {
25+
description = "The base name of the Azure Data Factory instance. If append_random_suffix is true, the final name will be '<base>-<suffix>'."
26+
type = string
27+
28+
validation {
29+
condition = length(trimspace(var.data_factory_name)) > 0
30+
error_message = "data_factory_name must not be empty."
31+
}
32+
}
33+
34+
variable "append_random_suffix" {
35+
description = "Whether to append a random suffix to the Data Factory name to avoid global name collisions."
36+
type = bool
37+
default = true
38+
}
39+
40+
variable "random_suffix_length" {
41+
description = "Length of the random suffix appended to the Data Factory name when append_random_suffix is true."
42+
type = number
43+
default = 6
44+
45+
validation {
46+
condition = var.random_suffix_length >= 4 && var.random_suffix_length <= 16
47+
error_message = "random_suffix_length must be between 4 and 16."
48+
}
49+
}
50+
51+
variable "public_network_enabled" {
52+
description = "Whether public network access is enabled for the Data Factory."
53+
type = bool
54+
default = true
55+
}
56+
57+
variable "tags" {
58+
description = "A map of tags to assign to the resources."
59+
type = map(string)
60+
default = {}
61+
}

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ Last updated: 2026-02-11
105105
<summary><b> Analytics and Big Data </b> (Click to expand) </summary>
106106

107107
- [Analytics and Big Data](./5_analytics-bigdata)
108+
- [Azure Data Factory](./5_analytics-bigdata/data-factory)
108109

109110
</details>
110111

0 commit comments

Comments
 (0)