Skip to content

Commit

Permalink
Add Data Factory Content Deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
marvinbuss committed Apr 24, 2024
1 parent ca2b5f9 commit d5169a4
Show file tree
Hide file tree
Showing 10 changed files with 93 additions and 44 deletions.
15 changes: 15 additions & 0 deletions code/datafactory/ARMTemplateForFactory.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"factoryName": {
"type": "string",
"metadata": "Data Factory name",
"defaultValue": ""
}
},
"variables": {
"factoryId": "[concat('Microsoft.DataFactory/factories/', parameters('factoryName'))]"
},
"resources": []
}
9 changes: 9 additions & 0 deletions code/datafactory/ARMTemplateParametersForFactory.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"factoryName": {
"value": "${data_factory_name}"
}
}
}
12 changes: 0 additions & 12 deletions code/infra/data.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,6 @@ data "azurerm_location" "current" {
location = var.location
}

data "local_file" "data_factory_parameters_file" {
count = var.data_factory_published_content != {} ? [1] : []

filename = var.data_factory_published_content.parameters_file
}

data "local_file" "data_factory_template_file" {
count = var.data_factory_published_content != {} ? [1] : []

filename = var.data_factory_published_content.template_file
}

# data "azurerm_virtual_network" "virtual_network" {
# name = local.virtual_network.name
# resource_group_name = local.virtual_network.resource_group_name
Expand Down
28 changes: 19 additions & 9 deletions code/infra/datafactory.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,30 @@ resource "azurerm_data_factory" "data_factory" {
dynamic "global_parameter" {
for_each = var.data_factory_global_parameters
content {
name = each.key
type = each.value.type
value = each.value.value
name = global_parameter.key
type = global_parameter.value.type
value = global_parameter.value.value
}
}
dynamic "github_configuration" {
for_each = length(compact(values(var.data_factory_github_repo))) == 5 ? [var.data_factory_github_repo] : []
content {
account_name = github_configuration.value["account_name"]
branch_name = github_configuration.value["branch_name"]
git_url = github_configuration.value["git_url"]
repository_name = github_configuration.value["repository_name"]
root_folder = github_configuration.value["root_folder"]
}
}
dynamic "vsts_configuration" {
for_each = length(compact(values(var.data_factory_azure_devops_repo))) == 6 ? [var.data_factory_azure_devops_repo] : []
content {
account_name = azure_devops_repo.value["account_name"]
branch_name = azure_devops_repo.value["branch_name"]
project_name = azure_devops_repo.value["project_name"]
repository_name = azure_devops_repo.value["repository_name"]
root_folder = azure_devops_repo.value["root_folder"]
tenant_id = azure_devops_repo.value["tenant_id"]
account_name = vsts_configuration.value["account_name"]
branch_name = vsts_configuration.value["branch_name"]
project_name = vsts_configuration.value["project_name"]
repository_name = vsts_configuration.value["repository_name"]
root_folder = vsts_configuration.value["root_folder"]
tenant_id = vsts_configuration.value["tenant_id"]
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions code/infra/datafactory_content.tf
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
resource "azurerm_resource_group_template_deployment" "data_factory_content_deployment" {
count = var.data_factory_published_content != {} ? [1] : []
count = var.data_factory_published_content.parameters_file != "" && var.data_factory_published_content.template_file != "" ? 1 : 0

name = "dataFactoryContentDeployment"
resource_group_name = azurerm_data_factory.data_factory.resource_group_name
tags = var.tags

debug_level = "none"
deployment_mode = "Incremental"
parameters_content = data.local_file.data_factory_parameters_file
template_content = data.local_file.data_factory_template_file
parameters_content = jsonencode(jsondecode(templatefile(var.data_factory_published_content.parameters_file, local.data_factory_published_content_template_variables)).parameters)
template_content = file(var.data_factory_published_content.template_file)
}
20 changes: 10 additions & 10 deletions code/infra/datafactory_managed_private_endpoints.tf
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ resource "azurerm_data_factory_managed_private_endpoint" "data_factory_managed_p
target_resource_id = azurerm_kusto_cluster.kusto_cluster.id
}

resource "null_resource" "data_factory_managed_private_endpoint_kusto_cluster_approval" {
triggers = {
run_once = "true"
}
provisioner "local-exec" {
working_dir = "${path.module}/../scripts/"
interpreter = ["pwsh", "-Command"]
command = "./Approve-ManagedPrivateEndpoint.ps1 -ResourceId '${azurerm_kusto_cluster.kusto_cluster.id}' -WorkspaceName '${azurerm_data_factory.data_factory.name}' -ManagedPrivateEndpointName '${azurerm_data_factory_managed_private_endpoint.data_factory_managed_private_endpoint_kusto_cluster.name}'"
}
}
# resource "null_resource" "data_factory_managed_private_endpoint_kusto_cluster_approval" {
# triggers = {
# run_once = "true"
# }
# provisioner "local-exec" {
# working_dir = "${path.module}/../scripts/"
# interpreter = ["pwsh", "-Command"]
# command = "./Approve-ManagedPrivateEndpoint.ps1 -ResourceId '${azurerm_kusto_cluster.kusto_cluster.id}' -WorkspaceName '${azurerm_data_factory.data_factory.name}' -ManagedPrivateEndpointName '${azurerm_data_factory_managed_private_endpoint.data_factory_managed_private_endpoint_kusto_cluster.name}'"
# }
# }
7 changes: 7 additions & 0 deletions code/infra/locals.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
locals {
prefix = "${lower(var.prefix)}-${var.environment}"

default_template_variables = {
data_factory_name = azurerm_data_factory.data_factory.name
key_vault_uri = azurerm_key_vault.key_vault.vault_uri
datalake_primary_blob_endpoint = azurerm_storage_account.storage.primary_blob_endpoint
}
data_factory_published_content_template_variables = merge(local.default_template_variables, var.data_factory_published_content_template_variables)

# virtual_network = {
# resource_group_name = split("/", var.vnet_id)[4]
# name = split("/", var.vnet_id)[8]
Expand Down
4 changes: 0 additions & 4 deletions code/infra/terraform.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ terraform {
source = "hashicorp/null"
version = "3.2.2"
}
local = {
source = "hashicorp/local"
version = "2.5.1"
}
}

backend "azurerm" {
Expand Down
31 changes: 27 additions & 4 deletions code/infra/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,22 @@ variable "data_factory_azure_devops_repo" {
default = {}
}

variable "data_factory_github_repo" {
description = "Specifies the Github repository configuration."
type = object(
{
account_name = optional(string, "")
branch_name = optional(string, "")
git_url = optional(string, "")
repository_name = optional(string, "")
root_folder = optional(string, "")
}
)
sensitive = false
nullable = false
default = {}
}

variable "data_factory_global_parameters" {
description = "Specifies the Azure Data Factory global parameters."
type = map(object({
Expand All @@ -70,17 +86,24 @@ variable "data_factory_global_parameters" {

variable "data_factory_published_content" {
description = "Specifies the Azure Devops repository configuration."
type = optional(object(
type = object(
{
parameters_file = string
template_file = string
parameters_file = optional(string, "")
template_file = optional(string, "")
}
), {})
)
sensitive = false
nullable = false
default = {}
}

variable "data_factory_published_content_template_variables" {
description = "Specifies custom template variables to use for the deployment templates from ADF."
type = map(string)
sensitive = false
default = {}
}

variable "kusto_cluster_sku" {
description = "Specifies the kusto cluster sku name."
type = object({
Expand Down
5 changes: 3 additions & 2 deletions config/SharedTenant/vars.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ tags = {}
data_factory_azure_devops_repo = {}
data_factory_global_parameters = {}
data_factory_published_content = {
# parameters_file = ""
# template_file = ""
parameters_file = "../datafactory/ARMTemplateParametersForFactory.json"
template_file = "../datafactory/ARMTemplateForFactory.json"
}
data_factory_published_content_template_variables = {}
kusto_cluster_sku = {
name = "Standard_E2ads_v5",
capacity = 2
Expand Down

0 comments on commit d5169a4

Please sign in to comment.