Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Change database from nosql to mongodb #1349

Merged
merged 11 commits into from
Dec 23, 2024
23 changes: 23 additions & 0 deletions src/domains/rtp-app/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

74 changes: 74 additions & 0 deletions src/domains/rtp-common/03_database.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# ------------------------------------------------------------------------------
# CosmosDB NoSQL account.
# ------------------------------------------------------------------------------
resource "azurerm_cosmosdb_account" "rtp" {
name = "${local.project}-cosmos"
resource_group_name = azurerm_resource_group.data.name
location = azurerm_resource_group.data.location
kind = var.cosmos_mongo_db_params.kind
offer_type = var.cosmos_mongo_db_params.offer_type

mongo_server_version = var.cosmos_mongo_db_params.server_version
enable_free_tier = var.cosmos_mongo_db_params.enable_free_tier
tags = var.tags
public_network_access_enabled = var.cosmos_mongo_db_params.public_network_access_enabled

consistency_policy {
consistency_level = var.cosmos_mongo_db_params.consistency_policy.consistency_level
max_interval_in_seconds = var.cosmos_mongo_db_params.consistency_policy.max_interval_in_seconds
max_staleness_prefix = var.cosmos_mongo_db_params.consistency_policy.max_staleness_prefix
}

dynamic "capabilities" {
for_each = var.cosmos_mongo_db_params.capabilities

content {
name = capabilities.value
}
}

geo_location {
failover_priority = 0
location = var.location
}
}

# ------------------------------------------------------------------------------
# Storing CosmosDB primary mongo connection string in the rtp key vault.
# ------------------------------------------------------------------------------
resource "azurerm_key_vault_secret" "cosmosdb_account_rtp_connection_string" {
name = "cosmosdb-account-rtp-connection-string"
value = azurerm_cosmosdb_account.rtp.primary_mongodb_connection_string
key_vault_id = data.azurerm_key_vault.kv_domain.id
tags = var.tags
}

# ------------------------------------------------------------------------------
# Create a CosmosDB sql database.
# ------------------------------------------------------------------------------
resource "azurerm_cosmosdb_mongo_database" "db_rtp" {
name = "rtp"
resource_group_name = azurerm_resource_group.data.name
account_name = azurerm_cosmosdb_account.rtp.name
}


# ------------------------------------------------------------------------------
# Create a collection for the activations inside the db.
# ------------------------------------------------------------------------------
resource "azurerm_cosmosdb_mongo_collection" "activations" {
name = "activations"
resource_group_name = azurerm_resource_group.data.name
account_name = azurerm_cosmosdb_account.rtp.name
database_name = azurerm_cosmosdb_mongo_database.db_rtp.name

index {
keys = ["_id"]
unique = true
}

index {
keys = ["fiscalCode"]
unique = true
}
}
28 changes: 28 additions & 0 deletions src/domains/rtp-common/99_variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,31 @@ variable "cdn_rtp" {
advanced_threat_protection_enabled = bool
})
}


# Cosmos DB
variable "cosmos_mongo_db_params" {
type = object({
enabled = bool
capabilities = list(string)
offer_type = string
server_version = string
kind = string
consistency_policy = object({
consistency_level = string
max_interval_in_seconds = number
max_staleness_prefix = number
})
main_geo_location_zone_redundant = bool
enable_free_tier = bool
additional_geo_locations = list(object({
location = string
failover_priority = number
zone_redundant = bool
}))
private_endpoint_enabled = bool
public_network_access_enabled = bool
is_virtual_network_filter_enabled = bool
backup_continuous_enabled = bool
})
}
16 changes: 7 additions & 9 deletions src/domains/rtp-common/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,12 @@
| Name | Type |
|------|------|
| [azurerm_cosmosdb_account.rtp](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/cosmosdb_account) | resource |
| [azurerm_cosmosdb_sql_container.activations](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/cosmosdb_sql_container) | resource |
| [azurerm_cosmosdb_sql_container.beta_tester](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/cosmosdb_sql_container) | resource |
| [azurerm_cosmosdb_sql_database.db_rtp](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/cosmosdb_sql_database) | resource |
| [azurerm_cosmosdb_mongo_collection.activations](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/cosmosdb_mongo_collection) | resource |
| [azurerm_cosmosdb_mongo_database.db_rtp](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/cosmosdb_mongo_database) | resource |
| [azurerm_key_vault_secret.appinisights_connection_string_kv](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/key_vault_secret) | resource |
| [azurerm_key_vault_secret.cosmosdb_account_rtp_endpoint](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/key_vault_secret) | resource |
| [azurerm_private_dns_zone.cosmos_nosql](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/private_dns_zone) | resource |
| [azurerm_private_dns_zone_virtual_network_link.cosmos_nosql_to_core](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/private_dns_zone_virtual_network_link) | resource |
| [azurerm_private_dns_zone_virtual_network_link.cosmos_nosql_to_intern](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/private_dns_zone_virtual_network_link) | resource |
| [azurerm_private_endpoint.cosmos_nosql](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/private_endpoint) | resource |
| [azurerm_private_endpoint.cosmos_nosql_vpn](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/private_endpoint) | resource |
| [azurerm_key_vault_secret.cosmosdb_account_rtp_connection_string](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/key_vault_secret) | resource |
| [azurerm_private_endpoint.cosmos_mongo](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/private_endpoint) | resource |
| [azurerm_private_endpoint.cosmos_mongo_vpn](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/private_endpoint) | resource |
| [azurerm_resource_group.data](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group) | resource |
| [azurerm_resource_group.network](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group) | resource |
| [azurerm_resource_group.rtp_frontend_rg](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group) | resource |
Expand All @@ -37,6 +33,7 @@
| [azurerm_dns_zone.cstar_public_dns_zone](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/dns_zone) | data source |
| [azurerm_key_vault.kv_domain](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/key_vault) | data source |
| [azurerm_log_analytics_workspace.log_analytics](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/log_analytics_workspace) | data source |
| [azurerm_private_dns_zone.cosmos_mongo](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/private_dns_zone) | data source |
| [azurerm_subnet.aca](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/subnet) | data source |
| [azurerm_subnet.private_endpoints](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/subnet) | data source |
| [azurerm_subscription.current](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/subscription) | data source |
Expand All @@ -59,6 +56,7 @@
| <a name="input_core_private_endpoints_subnet_name"></a> [core\_private\_endpoints\_subnet\_name](#input\_core\_private\_endpoints\_subnet\_name) | ------------------------------------------------------------------------------ Private endpoints subnet. ------------------------------------------------------------------------------ | `string` | `"private-endpoint-snet"` | no |
| <a name="input_core_virtual_network_name"></a> [core\_virtual\_network\_name](#input\_core\_virtual\_network\_name) | ------------------------------------------------------------------------------ Virtual network which hosts VPN gateway. ------------------------------------------------------------------------------ | `string` | n/a | yes |
| <a name="input_core_virtual_network_resource_group_name"></a> [core\_virtual\_network\_resource\_group\_name](#input\_core\_virtual\_network\_resource\_group\_name) | n/a | `string` | n/a | yes |
| <a name="input_cosmos_mongo_db_params"></a> [cosmos\_mongo\_db\_params](#input\_cosmos\_mongo\_db\_params) | Cosmos DB | <pre>object({<br/> enabled = bool<br/> capabilities = list(string)<br/> offer_type = string<br/> server_version = string<br/> kind = string<br/> consistency_policy = object({<br/> consistency_level = string<br/> max_interval_in_seconds = number<br/> max_staleness_prefix = number<br/> })<br/> main_geo_location_zone_redundant = bool<br/> enable_free_tier = bool<br/> additional_geo_locations = list(object({<br/> location = string<br/> failover_priority = number<br/> zone_redundant = bool<br/> }))<br/> private_endpoint_enabled = bool<br/> public_network_access_enabled = bool<br/> is_virtual_network_filter_enabled = bool<br/> backup_continuous_enabled = bool<br/> })</pre> | n/a | yes |
| <a name="input_dns_zone_prefix"></a> [dns\_zone\_prefix](#input\_dns\_zone\_prefix) | The dns zone prefix e.g. dev.rtp | `string` | n/a | yes |
| <a name="input_domain"></a> [domain](#input\_domain) | n/a | `string` | n/a | yes |
| <a name="input_env"></a> [env](#input\_env) | n/a | `string` | n/a | yes |
Expand Down
118 changes: 0 additions & 118 deletions src/domains/rtp-common/cosmosdb_accounts.tf

This file was deleted.

25 changes: 24 additions & 1 deletion src/domains/rtp-common/env/dev/terraform.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,27 @@ core_virtual_network_name = "cstar-d-vnet"
core_virtual_network_resource_group_name = "cstar-d-vnet-rg"
aca_subnet_name = "cstar-d-mcshared-aca-snet"
aca_subnet_resource_group_name = "cstar-d-weu-dev01-vnet-rg"
aca_virtual_network_name = "cstar-d-weu-dev01-vnet"
aca_virtual_network_name = "cstar-d-weu-dev01-vnet"

## Cosmos DB
cosmos_mongo_db_params = {
enabled = true
kind = "MongoDB"
capabilities = ["EnableMongo", "DisableRateLimitingResponses"]
offer_type = "Standard"
consistency_policy = {
consistency_level = "BoundedStaleness"
max_interval_in_seconds = 300
max_staleness_prefix = 100000
}
server_version = "4.2"
main_geo_location_zone_redundant = false
enable_free_tier = false

private_endpoint_enabled = false
public_network_access_enabled = false
additional_geo_locations = []
is_virtual_network_filter_enabled = true

backup_continuous_enabled = false
}
32 changes: 32 additions & 0 deletions src/domains/rtp-common/env/prod/terraform.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,35 @@ core_virtual_network_resource_group_name = "cstar-p-vnet-rg"
aca_subnet_name = "cstar-p-mcshared-aca-snet"
aca_subnet_resource_group_name = "cstar-p-weu-prod01-vnet-rg"
aca_virtual_network_name = "cstar-p-weu-prod01-vnet"



## Cosmos DB
cosmos_mongo_db_params = {
enabled = true
kind = "MongoDB"
capabilities = ["EnableMongo"]
offer_type = "Standard"
consistency_policy = {
consistency_level = "Strong"
max_interval_in_seconds = 5
max_staleness_prefix = 100
}
server_version = "4.2"
main_geo_location_zone_redundant = true
enable_free_tier = false

private_endpoint_enabled = true
public_network_access_enabled = false
additional_geo_locations = [
{
location = "northeurope"
failover_priority = 1
zone_redundant = true
}
]

is_virtual_network_filter_enabled = true

backup_continuous_enabled = true
}
32 changes: 32 additions & 0 deletions src/domains/rtp-common/env/uat/terraform.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,35 @@ core_virtual_network_resource_group_name = "cstar-u-vnet-rg"
aca_subnet_name = "cstar-u-mcshared-aca-snet"
aca_subnet_resource_group_name = "cstar-u-weu-uat01-vnet-rg"
aca_virtual_network_name = "cstar-u-weu-uat01-vnet"



## Cosmos DB
cosmos_mongo_db_params = {
enabled = true
kind = "MongoDB"
# Enable Mongo API and Server Side Retry
capabilities = ["EnableMongo", "DisableRateLimitingResponses"]
offer_type = "Standard"
consistency_policy = {
consistency_level = "BoundedStaleness"
max_interval_in_seconds = 300
max_staleness_prefix = 100000
}
server_version = "4.2"
main_geo_location_zone_redundant = false
enable_free_tier = false

private_endpoint_enabled = true
public_network_access_enabled = false
additional_geo_locations = []
# additional_geo_locations = [{
# location = "northeurope"
# failover_priority = 1
# zone_redundant = false
# }]

is_virtual_network_filter_enabled = true

backup_continuous_enabled = false
}
Loading
Loading