From 9d2c460d00a2e0ec9e7a4abe62cad0b88937012a Mon Sep 17 00:00:00 2001 From: christian-calabrese Date: Wed, 16 Oct 2024 11:28:23 +0200 Subject: [PATCH] fix: changed folder structure and ran pre-commit --- .../data_factory_storage_account/data.tf | 2 +- .../data_factory_storage_account/locals.tf | 2 +- .../data_factory_storage_account/outputs.tf | 14 ++--- .../data_factory_storage_account/variables.tf | 23 +++----- src/migration/_modules/datafactory/main.tf | 19 ------ .../_modules/datafactory/variables.tf | 19 ------ src/migration/prod/README.md | 37 ++++++++++++ src/migration/prod/italynorth.tf | 58 +++++++++++++++++-- 8 files changed, 109 insertions(+), 65 deletions(-) delete mode 100644 src/migration/_modules/datafactory/main.tf delete mode 100644 src/migration/_modules/datafactory/variables.tf create mode 100644 src/migration/prod/README.md diff --git a/src/_modules/data_factory_storage_account/data.tf b/src/_modules/data_factory_storage_account/data.tf index 4c64f1b9a..0de9bf352 100644 --- a/src/_modules/data_factory_storage_account/data.tf +++ b/src/_modules/data_factory_storage_account/data.tf @@ -9,6 +9,6 @@ data "azurerm_storage_account" "target" { } data "azurerm_storage_containers" "this" { - for_each = var.what_to_migrate.blob.enabled && length(var.what_to_migrate.blob.containers) == 0 ? [1] : [] + for_each = var.what_to_migrate.blob.enabled && length(var.what_to_migrate.blob.containers) == 0 ? [1] : [] storage_account_id = data.azurerm_storage_account.source.id } \ No newline at end of file diff --git a/src/_modules/data_factory_storage_account/locals.tf b/src/_modules/data_factory_storage_account/locals.tf index 181f0aa08..db6f13ac2 100644 --- a/src/_modules/data_factory_storage_account/locals.tf +++ b/src/_modules/data_factory_storage_account/locals.tf @@ -1,4 +1,4 @@ locals { containers = var.what_to_migrate.blob.enabled ? length(var.what_to_migrate.blob.containers) > 0 ? var.what_to_migrate.blob.containers : [for container in data.azurerm_storage_containers.this[0].containers : container.name] : [] - tables = var.what_to_migrate.table.enabled ? var.what_to_migrate.table.tables : [] + tables = var.what_to_migrate.table.enabled ? var.what_to_migrate.table.tables : [] } \ No newline at end of file diff --git a/src/_modules/data_factory_storage_account/outputs.tf b/src/_modules/data_factory_storage_account/outputs.tf index cc37a5ca2..22c1d86d8 100644 --- a/src/_modules/data_factory_storage_account/outputs.tf +++ b/src/_modules/data_factory_storage_account/outputs.tf @@ -1,10 +1,10 @@ output "pipelines" { - value = { - for pipeline in concat(azurerm_data_factory_pipeline.pipeline_container, azurerm_data_factory_pipeline.pipeline_table) - : pipeline.name => { - id = pipeline.id - name = pipeline.name - url = "https://adf.azure.com/en/authoring/pipeline/${pipeline.name}?factory=${pipeline.data_factory_id}" - } + value = { + for pipeline in concat(azurerm_data_factory_pipeline.pipeline_container, azurerm_data_factory_pipeline.pipeline_table) + : pipeline.name => { + id = pipeline.id + name = pipeline.name + url = "https://adf.azure.com/en/authoring/pipeline/${pipeline.name}?factory=${pipeline.data_factory_id}" } + } } \ No newline at end of file diff --git a/src/_modules/data_factory_storage_account/variables.tf b/src/_modules/data_factory_storage_account/variables.tf index 6d988c7b6..c6dca9a79 100644 --- a/src/_modules/data_factory_storage_account/variables.tf +++ b/src/_modules/data_factory_storage_account/variables.tf @@ -11,25 +11,20 @@ variable "environment" { description = "Values which are used to generate resource names and location short names. They are all mandatory except for domain, which should not be used only in the case of a resource used by multiple domains." } -variable "data_factory" { - description = "Data Factory information." - type = map(object({ - id = string - name = string - location = string - resource_group_name = string - })) +variable "data_factory_id" { + description = "Data Factory id where to create resources." + type = string } variable "storage_accounts" { type = object({ source = object({ - name = string + name = string resource_group_name = string }) target = object({ - name = string + name = string resource_group_name = string }) }) @@ -39,16 +34,16 @@ variable "what_to_migrate" { type = object({ blob = optional(object( { - enabled = bool + enabled = bool containers = optional(list(string), []) - }), + }), { enabled = false } ) table = optional(object( { enabled = bool - tables = list(string) - }), + tables = list(string) + }), { enabled = false } ) }) diff --git a/src/migration/_modules/datafactory/main.tf b/src/migration/_modules/datafactory/main.tf deleted file mode 100644 index 0d85af6a0..000000000 --- a/src/migration/_modules/datafactory/main.tf +++ /dev/null @@ -1,19 +0,0 @@ -# Create Azure Data Factory instances -# Enables system-assigned managed identity for secure access to resources -resource "azurerm_data_factory" "this" { - name = "${var.project}-migration-adf-01" - location = var.location - resource_group_name = var.resource_group_name - - identity { - type = "SystemAssigned" - } - - tags = var.tags -} - -resource "azurerm_data_factory_integration_runtime_azure" "azure_runtime" { - name = "${var.project}-adfir-${module.naming_convention.suffix}" - data_factory_id = azurerm_data_factory.this.id - location = var.location -} diff --git a/src/migration/_modules/datafactory/variables.tf b/src/migration/_modules/datafactory/variables.tf deleted file mode 100644 index e1bab3ba3..000000000 --- a/src/migration/_modules/datafactory/variables.tf +++ /dev/null @@ -1,19 +0,0 @@ -variable "project" { - type = string - description = "IO prefix, short environment and short location" -} - -variable "location" { - type = string - description = "Azure region" -} - -variable "tags" { - type = map(any) - description = "Resource tags" -} - -variable "resource_group_name" { - type = string - description = "Resource group where create resources" -} diff --git a/src/migration/prod/README.md b/src/migration/prod/README.md new file mode 100644 index 000000000..ec20557ab --- /dev/null +++ b/src/migration/prod/README.md @@ -0,0 +1,37 @@ +# prod + + +## Requirements + +| Name | Version | +|------|---------| +| [azurerm](#requirement\_azurerm) | <= 3.112.0 | + +## Providers + +| Name | Version | +|------|---------| +| [azurerm](#provider\_azurerm) | <= 3.112.0 | + +## Modules + +| Name | Source | Version | +|------|--------|---------| +| [migrate\_storage\_accounts](#module\_migrate\_storage\_accounts) | ../../_modules/data_factory_storage_account | n/a | + +## Resources + +| Name | Type | +|------|------| +| [azurerm_data_factory.this](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/data_factory) | resource | +| [azurerm_data_factory_integration_runtime_azure.azure_runtime](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/data_factory_integration_runtime_azure) | resource | +| [azurerm_resource_group.migration](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group) | resource | + +## Inputs + +No inputs. + +## Outputs + +No outputs. + diff --git a/src/migration/prod/italynorth.tf b/src/migration/prod/italynorth.tf index 11753776b..bf8384b0e 100644 --- a/src/migration/prod/italynorth.tf +++ b/src/migration/prod/italynorth.tf @@ -1,9 +1,59 @@ -module "adf" { - source = "../_modules/datafactory" +resource "azurerm_resource_group" "migration" { + name = "${local.project_itn}-migration-rg-01" + location = "italynorth" - project = local.project_itn + tags = local.tags +} + +# Create Azure Data Factory instances +# Enables system-assigned managed identity for secure access to resources +resource "azurerm_data_factory" "this" { + name = "${local.project_itn}-migration-adf-01" location = "italynorth" - resource_group_name = azurerm_resource_group.github_runner.name + resource_group_name = azurerm_resource_group.migration.name + + identity { + type = "SystemAssigned" + } tags = local.tags +} + +resource "azurerm_data_factory_integration_runtime_azure" "azure_runtime" { + name = "${local.project_itn}-migration-adfir-01" + location = "italynorth" + data_factory_id = azurerm_data_factory.this.id +} + +module "migrate_storage_accounts" { + for_each = local.storage_accounts + source = "../../_modules/data_factory_storage_account" + + environment = { + prefix = local.prefix + env_short = local.env_short + location = "italynorth" + domain = "eng" + app_name = "mig" + instance_number = "01" + } + + data_factory_id = azurerm_data_factory.this.id + + storage_accounts = { + source = each.value.source + target = each.value.target + } + + what_to_migrate = { + blob = { + enabled = each.value.blob.enabled + containers = each.value.blob.containers + } + + table = { + enabled = each.value.table.enabled + tables = each.value.table.tables + } + } } \ No newline at end of file