From 5d11f444ede00e14f4c9aece9ef8d6e1ee949af6 Mon Sep 17 00:00:00 2001 From: Craig Anderson <1877372+CDA0@users.noreply.github.com> Date: Thu, 4 Jan 2024 14:06:52 +0000 Subject: [PATCH] Add Data Factory module (#21) --- modules/data-factory/CHANGELOG.md | 1 + modules/data-factory/README.md | 30 ++++++++++++ modules/data-factory/VERSION | 1 + modules/data-factory/src/locals.tf | 14 ++++++ modules/data-factory/src/main.tf | 68 ++++++++++++++++++++++++++ modules/data-factory/src/outputs.tf | 11 +++++ modules/data-factory/src/variables.tf | 67 +++++++++++++++++++++++++ modules/data-factory/test/main.tf | 18 +++++++ modules/data-factory/test/terraform.tf | 10 ++++ 9 files changed, 220 insertions(+) create mode 100644 modules/data-factory/CHANGELOG.md create mode 100644 modules/data-factory/README.md create mode 100644 modules/data-factory/VERSION create mode 100644 modules/data-factory/src/locals.tf create mode 100644 modules/data-factory/src/main.tf create mode 100644 modules/data-factory/src/outputs.tf create mode 100644 modules/data-factory/src/variables.tf create mode 100644 modules/data-factory/test/main.tf create mode 100644 modules/data-factory/test/terraform.tf diff --git a/modules/data-factory/CHANGELOG.md b/modules/data-factory/CHANGELOG.md new file mode 100644 index 0000000..825c32f --- /dev/null +++ b/modules/data-factory/CHANGELOG.md @@ -0,0 +1 @@ +# Changelog diff --git a/modules/data-factory/README.md b/modules/data-factory/README.md new file mode 100644 index 0000000..b2acbc9 --- /dev/null +++ b/modules/data-factory/README.md @@ -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 . diff --git a/modules/data-factory/VERSION b/modules/data-factory/VERSION new file mode 100644 index 0000000..d3827e7 --- /dev/null +++ b/modules/data-factory/VERSION @@ -0,0 +1 @@ +1.0 diff --git a/modules/data-factory/src/locals.tf b/modules/data-factory/src/locals.tf new file mode 100644 index 0000000..6a78776 --- /dev/null +++ b/modules/data-factory/src/locals.tf @@ -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 + } +} diff --git a/modules/data-factory/src/main.tf b/modules/data-factory/src/main.tf new file mode 100644 index 0000000..e87cd78 --- /dev/null +++ b/modules/data-factory/src/main.tf @@ -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 + } + } + } +} diff --git a/modules/data-factory/src/outputs.tf b/modules/data-factory/src/outputs.tf new file mode 100644 index 0000000..ab0b25d --- /dev/null +++ b/modules/data-factory/src/outputs.tf @@ -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 +} diff --git a/modules/data-factory/src/variables.tf b/modules/data-factory/src/variables.tf new file mode 100644 index 0000000..64371a5 --- /dev/null +++ b/modules/data-factory/src/variables.tf @@ -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 +} diff --git a/modules/data-factory/test/main.tf b/modules/data-factory/test/main.tf new file mode 100644 index 0000000..5651511 --- /dev/null +++ b/modules/data-factory/test/main.tf @@ -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" + } +} diff --git a/modules/data-factory/test/terraform.tf b/modules/data-factory/test/terraform.tf new file mode 100644 index 0000000..762ef2e --- /dev/null +++ b/modules/data-factory/test/terraform.tf @@ -0,0 +1,10 @@ +terraform { + required_version = "~> 1.5" + + required_providers { + azurerm = { + source = "hashicorp/azurerm" + version = "~> 3.85" + } + } +}