Skip to content

Commit

Permalink
Add Data Factory module (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
CDA0 authored Jan 4, 2024
1 parent 760c098 commit 5d11f44
Show file tree
Hide file tree
Showing 9 changed files with 220 additions and 0 deletions.
1 change: 1 addition & 0 deletions modules/data-factory/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Changelog
30 changes: 30 additions & 0 deletions modules/data-factory/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Data Factory

This module creates a [Data Factory](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/data_factory) and associated [Diagnostic Setting](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/monitor_diagnostic_setting).

## Usage

```hcl
module "data_factory" {
source = "https://github.com/gofrontier-com/azurerm-terraform-modules/releases/download/data-factory/[VERSION]/module.tar.gz//src"
environment = "dev"
identifier = "mortgages"
location = "uksouth"
log_analytics_workspace_id = data.azurerm_log_analytics_workspace.main.id
resource_group_name = module.resource_group.name
zone = "mtg"
tags = {
WorkloadType = "MortgagesLZ/data-platform"
}
}
```

## Known issues

_None._

## Contributing

See <https://github.com/gofrontier-com/azurerm-terraform-modules/blob/main/README.rst#contributing>.
1 change: 1 addition & 0 deletions modules/data-factory/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.0
14 changes: 14 additions & 0 deletions modules/data-factory/src/locals.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
locals {
identifier = replace(lower(var.identifier), "/[^a-z1-9]/", "")

short_locations = {
"uksouth" = "uks"
"ukwest" = "ukw"
}

tags = {
Environment = var.environment
Location = var.location
Zone = var.zone
}
}
68 changes: 68 additions & 0 deletions modules/data-factory/src/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@

resource "azurerm_data_factory" "main" {
name = "df-${var.zone}-${var.environment}-${lookup(local.short_locations, var.location)}-${local.identifier}"
location = var.location
resource_group_name = var.resource_group_name

managed_virtual_network_enabled = var.managed_virtual_network_enabled
public_network_enabled = var.public_network_enabled

identity {
type = length(var.identity_ids) > 0 ? "SystemAssigned, UserAssigned" : "SystemAssigned"
identity_ids = var.identity_ids
}

dynamic "vsts_configuration" {
for_each = can(var.vsts_configuration["account_name"]) ? [{}] : []

content {
account_name = var.vsts_configuration.account_name
branch_name = var.vsts_configuration.branch_name
project_name = var.vsts_configuration.project_name
repository_name = var.vsts_configuration.repository_name
root_folder = var.vsts_configuration.root_folder
tenant_id = var.vsts_configuration.tenant_id
}
}

tags = merge(var.tags, local.tags)

lifecycle {
ignore_changes = [
global_parameter
]
}
}

resource "azurerm_monitor_diagnostic_setting" "main" {
name = "log-analytics"
target_resource_id = azurerm_data_factory.main.id
log_analytics_workspace_id = var.log_analytics_workspace_id
log_analytics_destination_type = "AzureDiagnostics"

dynamic "enabled_log" {
for_each = var.log_categories

content {
category = enabled_log.value

retention_policy {
days = 0
enabled = false
}
}
}

dynamic "metric" {
for_each = var.metric_categories

content {
category = metric.value

retention_policy {
days = 0
enabled = false
}
}
}
}
11 changes: 11 additions & 0 deletions modules/data-factory/src/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
output "id" {
value = azurerm_data_factory.main.id
}

output "name" {
value = azurerm_data_factory.main.name
}

output "identity" {
value = azurerm_data_factory.main.identity
}
67 changes: 67 additions & 0 deletions modules/data-factory/src/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
variable "environment" {
type = string
}

variable "identifier" {
type = string
}

variable "identity_ids" {
type = list(string)
default = []
}

variable "location" {
type = string
}

variable "log_analytics_workspace_id" {
type = string
}

# https://learn.microsoft.com/en-us/azure/azure-monitor/essentials/resource-logs-categories#microsoftdatafactoryfactories
variable "log_categories" {
type = list(string)
default = [
"ActivityRuns",
"PipelineRuns",
"TriggerRuns",
"SandboxPipelineRuns",
"SandboxActivityRuns"
]
}

variable "managed_virtual_network_enabled" {
type = bool
default = false
}

variable "metric_categories" {
type = list(string)
default = [
"AllMetrics"
]
}

variable "public_network_enabled" {
type = bool
default = true
}

variable "resource_group_name" {
type = string
}

variable "tags" {
type = map(string)
default = {}
}

variable "vsts_configuration" {
type = map(string)
default = {}
}

variable "zone" {
type = string
}
18 changes: 18 additions & 0 deletions modules/data-factory/test/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
provider "azurerm" {
features {}
}

module "data_factory" {
source = "../src"

environment = "baz"
identifier = "qux"
location = "uksouth"
log_analytics_workspace_id = "quux"
resource_group_name = "grault"
zone = "waldo"

tags = {
Foo = "Bar"
}
}
10 changes: 10 additions & 0 deletions modules/data-factory/test/terraform.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
terraform {
required_version = "~> 1.5"

required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "~> 3.85"
}
}
}

0 comments on commit 5d11f44

Please sign in to comment.