-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into IOPID-1969-ioweb-kv-monorepo-ap
- Loading branch information
Showing
18 changed files
with
273 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
data "azurerm_subscription" "current" { | ||
} | ||
|
||
data "azurerm_cosmosdb_account" "source" { | ||
name = var.cosmos_accounts.source.name | ||
resource_group_name = var.cosmos_accounts.source.resource_group_name | ||
} | ||
|
||
data "azurerm_cosmosdb_account" "target" { | ||
name = var.cosmos_accounts.target.name | ||
resource_group_name = var.cosmos_accounts.target.resource_group_name | ||
} | ||
|
||
data "azapi_resource_list" "databases" { | ||
type = "Microsoft.DocumentDB/databaseAccounts/sqlDatabases@2024-05-15" | ||
parent_id = data.azurerm_cosmosdb_account.source.id | ||
response_export_values = ["*"] | ||
} | ||
|
||
data "azapi_resource_list" "containers" { | ||
for_each = local.databases | ||
type = "Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers@2024-05-15" | ||
parent_id = each.key | ||
response_export_values = ["*"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
resource "azurerm_data_factory_dataset_cosmosdb_sqlapi" "source_dataset" { | ||
for_each = local.containers_per_database | ||
name = replace(each.value.container.name, "/[$-]/", "_") | ||
data_factory_id = var.data_factory_id | ||
folder = "cosmos/account=${var.cosmos_accounts.source.name}/db=${each.value.container.database_name}/source" | ||
linked_service_name = azurerm_data_factory_linked_service_cosmosdb.source_linked_service_cosmos[each.value.container.database_id].name | ||
collection_name = each.value.container.name | ||
} | ||
|
||
resource "azurerm_data_factory_dataset_cosmosdb_sqlapi" "target_dataset" { | ||
for_each = local.containers_per_database | ||
name = replace(each.value.container.name, "/[$-]/", "_") | ||
data_factory_id = var.data_factory_id | ||
folder = "cosmos/account=${var.cosmos_accounts.target.name}/db=${each.value.container.database_name}/target" | ||
linked_service_name = azurerm_data_factory_linked_service_cosmosdb.target_linked_service_cosmos[each.value.container.database_id].name | ||
collection_name = each.value.container.name | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module "roles" { | ||
source = "github.com/pagopa/dx//infra/modules/azure_role_assignments?ref=main" | ||
principal_id = var.data_factory_principal_id | ||
|
||
cosmos = [ | ||
{ | ||
account_name = var.cosmos_accounts.source.name | ||
resource_group_name = var.cosmos_accounts.source.resource_group_name | ||
role = "reader" | ||
}, | ||
{ | ||
account_name = var.cosmos_accounts.target.name | ||
resource_group_name = var.cosmos_accounts.target.resource_group_name | ||
role = "writer" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
resource "azurerm_data_factory_linked_service_cosmosdb" "source_linked_service_cosmos" { | ||
for_each = local.databases | ||
name = "${var.cosmos_accounts.source.name}-${each.value}-cosmos" | ||
data_factory_id = var.data_factory_id | ||
account_endpoint = data.azurerm_cosmosdb_account.source.endpoint | ||
account_key = data.azurerm_cosmosdb_account.source.primary_key | ||
database = each.value | ||
} | ||
|
||
resource "azurerm_data_factory_linked_service_cosmosdb" "target_linked_service_cosmos" { | ||
for_each = local.databases | ||
name = "${var.cosmos_accounts.target.name}-${each.value}-cosmos" | ||
data_factory_id = var.data_factory_id | ||
account_endpoint = data.azurerm_cosmosdb_account.target.endpoint | ||
account_key = data.azurerm_cosmosdb_account.target.primary_key | ||
database = each.value | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
locals { | ||
azapi_databases = jsondecode(data.azapi_resource_list.databases.output) | ||
databases = length(var.what_to_migrate.databases) > 0 ? { for database in var.what_to_migrate.databases : "${data.azurerm_cosmosdb_account.source.id}/sqlDatabases/${database}" => database } : { for database in local.azapi_databases.value : database.id => reverse(split("/", database.id))[0] } | ||
|
||
containers = { for id, name in local.databases : name => [for container in jsondecode(data.azapi_resource_list.containers[id].output).value : { name = container.name, database_id = id, database_name = name }] } | ||
|
||
containers_per_database = { | ||
for pair in flatten([ | ||
for database, containers in local.containers : | ||
[for container in containers : { database = database, container = container }] | ||
]) : | ||
"${pair.database}|${pair.container.name}" => pair | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
terraform { | ||
required_providers { | ||
azapi = { | ||
source = "Azure/azapi" | ||
version = "<= 1.15.0" | ||
} | ||
} | ||
} | ||
|
||
module "naming_convention" { | ||
source = "github.com/pagopa/dx//infra/modules/azure_naming_convention/?ref=main" | ||
|
||
environment = { | ||
prefix = var.environment.prefix | ||
env_short = var.environment.env_short | ||
location = var.environment.location | ||
domain = var.environment.domain | ||
app_name = var.environment.app_name | ||
instance_number = var.environment.instance_number | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
resource "azurerm_data_factory_managed_private_endpoint" "cosmos_source" { | ||
name = "${module.naming_convention.prefix}-adf-${var.cosmos_accounts.source.name}-cosmos-${module.naming_convention.suffix}" | ||
data_factory_id = var.data_factory_id | ||
target_resource_id = data.azurerm_cosmosdb_account.source.id | ||
subresource_name = "Sql" | ||
} | ||
|
||
resource "azurerm_data_factory_managed_private_endpoint" "cosmos_target" { | ||
name = "${module.naming_convention.prefix}-adf-${var.cosmos_accounts.target.name}-cosmos-${module.naming_convention.suffix}" | ||
data_factory_id = var.data_factory_id | ||
target_resource_id = data.azurerm_cosmosdb_account.target.id | ||
subresource_name = "Sql" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
output "pipelines" { | ||
value = { | ||
for pipeline in azurerm_data_factory_pipeline.pipeline | ||
: pipeline.name => { | ||
id = pipeline.id | ||
name = pipeline.name | ||
url = "https://adf.azure.com/en/authoring/pipeline/${pipeline.name}?factory=${pipeline.data_factory_id}" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
resource "azurerm_data_factory_pipeline" "pipeline" { | ||
for_each = local.containers_per_database | ||
name = replace(each.value.container.name, "/[$-]/", "_") | ||
data_factory_id = var.data_factory_id | ||
description = "Copy data from Cosmos (${var.cosmos_accounts.source.name}) to (${var.cosmos_accounts.target.name})" | ||
folder = "cosmos/account=${var.cosmos_accounts.source.name}/db=${each.value.container.database_name}" | ||
|
||
activities_json = jsonencode([ | ||
{ | ||
name = "CopyFromCosmosToCosmos" | ||
type = "Copy" | ||
inputs = [ | ||
{ | ||
referenceName = azurerm_data_factory_dataset_cosmosdb_sqlapi.source_dataset[each.key].name | ||
type = "DatasetReference" | ||
} | ||
] | ||
outputs = [ | ||
{ | ||
referenceName = azurerm_data_factory_dataset_cosmosdb_sqlapi.target_dataset[each.key].name | ||
type = "DatasetReference" | ||
} | ||
] | ||
typeProperties = { | ||
source = { | ||
type = "CosmosDbSqlApiSource" | ||
} | ||
sink = { | ||
type = "CosmosDbSqlApiSink" | ||
writeBehavior = var.cosmos_accounts.target.write_behavior | ||
} | ||
} | ||
} | ||
]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
variable "environment" { | ||
type = object({ | ||
prefix = string | ||
env_short = string | ||
location = string | ||
domain = optional(string) | ||
app_name = string | ||
instance_number = string | ||
}) | ||
|
||
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_id" { | ||
description = "Data Factory id where to create resources." | ||
type = string | ||
} | ||
|
||
variable "data_factory_principal_id" { | ||
description = "Data Factory principal id to grant access to." | ||
type = string | ||
} | ||
|
||
variable "cosmos_accounts" { | ||
type = object({ | ||
source = object({ | ||
name = string | ||
resource_group_name = string | ||
}) | ||
|
||
target = object({ | ||
name = string | ||
resource_group_name = string | ||
write_behavior = optional(string, "upsert") | ||
}) | ||
}) | ||
|
||
description = "Cosmos accounts to migrate. The target account must have a write_behavior defined. The write_behavior must be one of the following values: insert, upsert." | ||
|
||
validation { | ||
condition = contains(["insert", "upsert"], var.cosmos_accounts.target.write_behavior) | ||
error_message = "The write_behavior must be one of the following values: insert or upsert." | ||
} | ||
} | ||
|
||
variable "what_to_migrate" { | ||
type = object({ | ||
databases = optional(list(string), []) | ||
}) | ||
|
||
description = "List of database names of the source cosmos db account to migrate. If no database names are provided, all of them are migrated." | ||
} |
4 changes: 2 additions & 2 deletions
4
src/_modules/data_factory_storage_account/datasets_containers.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
src/_modules/data_factory_storage_account/pipeline_containers.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters