Skip to content

Commit 42d9616

Browse files
authored
Merge pull request #17 from mongodb-partners/terraform
Add suffix to resources and remove spaces from Fabric workspace name
2 parents 7ac39ff + 5936c9d commit 42d9616

File tree

8 files changed

+52
-45
lines changed

8 files changed

+52
-45
lines changed

.DS_Store

-6 KB
Binary file not shown.

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@ data_files/
77
*.log
88
*.log.1
99
*.log.*
10-
*.ipynb
10+
*.ipynb
11+
.DS_Store
12+
*.tfvars

terraform/README.md

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,21 @@ MS Fabric provides a 60 days trial for the service. After this period, a [Fabric
2626

2727
The required variables required for the solution deployment are the following:
2828
```
29-
mongodbatlas_public_key = "<Valid_Public_API_Key>"
30-
mongodbatlas_private_key = "<Valid_Private_API_Key>"
31-
mongodbatlas_group_id = "<MongoDB_Atlas_Project_ID>"
32-
mongodbatlas_clustername = "<MongoDB_Atlas_ClusterName>"
33-
mongodbatlas_dbName = "<MongoDB+Atlas_Database_name>"
34-
mongodbatlas_userpass = "<DBUser>:<Password>"
35-
owner_tag = "<MongoDB_Username.Lastname>"
36-
subscription_id = "<MongoDB_Azure_Subscrition_ID>"
37-
azure_region = "australiacentral"
29+
mongodbatlas_public_key = "<mongodb_atlas_public_key>"
30+
mongodbatlas_private_key = "<mongodb_atlas_private_key>"
31+
mongodbatlas_group_id = "<mongodb_atlas_project_id>"
32+
mongodbatlas_clustername = "<mongodb_atlas_cluster_name>"
33+
mongodbatlas_dbName = "<mongodb_atlas_collection_name>"
34+
mongodbatlas_collectionName = "all"
35+
mongodbatlas_userpass = "<mongodb_atlas_database_username>:<mongodb_atlas_database_password>"
36+
owner_tag = "<user_identification>"
37+
subscription_id = "<azure_subscription_id>"
38+
azure_region = "<azure_region_name>"
3839
azure_vault_name = ""
3940
fabric_capacity_sku = "<MS-Fabric-Capacity-SKU>"
41+
initSyncBatchSize = "100000"
42+
incrementalSyncBatchSize = "1000"
43+
incrementalSyncMaxTimeInterval = "180"
4044
```
4145

4246
- MongoDB Atlas authentication keys as requested in the pre-requisites section
@@ -49,8 +53,9 @@ fabric_capacity_sku = "<MS-Fabric-Capacity-SKU>"
4953
- Subscription ID can be obtained by running the `az login` command
5054
- `azure_vault_name`is optional and uses a random value by default
5155
- The Fabric Capacity SKU String can be found in Fabric's [Admin portal](https://app.fabric.microsoft.com/admin-portal/capacities/capacitiesList/trial?experience=fabric-developer) page.
56+
- The values for `initSyncBatchSize`, `incrementalSyncBatchSize` and `incrementalSyncMaxTimeInterval` can be teaked through these parameters.
5257

53-
Variables can be stored on the `terraform.tfvars` file, or provided when `terraform plan` is executed.
58+
Variables can be stored on the `terraform.tfvars` file, or provided when `terraform plan` is executed. You can copy the file `terraform_tfvars.example` as `terraform.tfvars` and update the values.
5459

5560
### Deploying without Secure network communication ###
5661

@@ -108,7 +113,7 @@ Run `terraform plan --out plan_name.tfplan`, then `terraform apply "plan_name.tf
108113
|Microsoft Azure|vault-\[randomid\]|Key vault|
109114
|Microsoft Azure|mongodb-atlas-fabric-service-plan|App Service plan|
110115
|Microsoft Azure|mongodbatlasfabricmirrordbsynch|App Service|
111-
|Microsoft Fabric|MongoDB Atlas Azure Fabric Mirrored Database Integration|Workspace|
116+
|Microsoft Fabric|MongoDB_Atlas_Azure_Fabric_Mirrored_Database_Integration|Workspace|
112117
|Microsoft Fabric|MongoDB Atlas - Fabric Mirrored Database|Mirrored Database|
113118
|Microsoft Fabric|MongoDB Atlas - Fabric Mirrored Database|Semantic model (default)|
114119
|Microsoft Fabric|MongoDB Atlas - Fabric Mirrored Database|SQL analytics endpoint|
@@ -122,11 +127,13 @@ Run `terraform plan --out plan_name.tfplan`, then `terraform apply "plan_name.tf
122127
|Microsoft Azure|mongodb-atlas-fabric-resourceGroup|Resource Group|
123128
|Microsoft Azure|mongodb-atlas-fabric-service-plan|App Service plan|
124129
|Microsoft Azure|mongodbatlasfabricmirrordbsynch|App Service|
125-
|Microsoft Fabric|MongoDB Atlas Azure Fabric Mirrored Database Integration|Workspace|
130+
|Microsoft Fabric|MongoDB_Atlas_Azure_Fabric_Mirrored_Database_Integration|Workspace|
126131
|Microsoft Fabric|MongoDB Atlas - Fabric Mirrored Database|Mirrored Database|
127132
|Microsoft Fabric|MongoDB Atlas - Fabric Mirrored Database|Semantic model (default)|
128133
|Microsoft Fabric|MongoDB Atlas - Fabric Mirrored Database|SQL analytics endpoint|
129134
135+
Most of the resources will have the `-[random-value]` suffix to avoid conflict in case the solution is deployed in more than one region on Azure.
136+
130137
# Deleting the deployed resources #
131138
132139
The deployed solution can be deleted using the Terraform CLI ```terraform destroy``` command, which will remove all resources from Fabric, Azure and MongoDB Atlas. The database will not be affected by this action.

terraform/azureResources.tf

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
1+
resource "random_string" "random_suffix" {
2+
length = 5
3+
lower = true
4+
numeric = true
5+
special = false
6+
upper = false
7+
}
18
resource "azurerm_resource_group" "mongodb-atlas-fabric-resourceGroup" {
2-
name = "mongodb-atlas-fabric-resourceGroup"
9+
name = "mongodb-atlas-fabric-resourceGroup-${random_string.random_suffix.result}"
310
location = var.azure_region
411
tags = {
512
owner = var.owner_tag
@@ -10,7 +17,7 @@ resource "azurerm_resource_group" "mongodb-atlas-fabric-resourceGroup" {
1017
}
1118

1219
resource "azurerm_virtual_network" "mongodb-atlas-fabric-vNet" {
13-
name = "mongodb-atlas-fabric-vNet"
20+
name = "mongodb-atlas-fabric-vNet-${random_string.random_suffix.result}"
1421
location = azurerm_resource_group.mongodb-atlas-fabric-resourceGroup.location
1522
resource_group_name = azurerm_resource_group.mongodb-atlas-fabric-resourceGroup.name
1623
address_space = ["10.0.0.0/16"]
@@ -67,7 +74,7 @@ resource "azurerm_subnet" "mongodb-atlas-fabric-webAppSubnet" {
6774
}
6875

6976
resource "azurerm_app_service_environment_v3" "mongodb-atlas-fabric-appServiceEnv" {
70-
name = "mongodb-atlas-fabric-asev3"
77+
name = "mongodb-atlas-fabric-asev3-${random_string.random_suffix.result}"
7178
resource_group_name = azurerm_resource_group.mongodb-atlas-fabric-resourceGroup.name
7279
subnet_id = azurerm_subnet.mongodb-atlas-fabric-subnet1[0].id
7380
tags = {
@@ -81,7 +88,7 @@ resource "azurerm_app_service_environment_v3" "mongodb-atlas-fabric-appServiceEn
8188
}
8289
//Service plan for App Service Environment and Private Endpoint deployment
8390
resource "azurerm_service_plan" "mongodb-atlas-fabric-service-plan" {
84-
name = "mongodb-atlas-fabric-service-plan"
91+
name = "mongodb-atlas-fabric-service-plan-${random_string.random_suffix.result}"
8592
location = azurerm_resource_group.mongodb-atlas-fabric-resourceGroup.location
8693
resource_group_name = azurerm_resource_group.mongodb-atlas-fabric-resourceGroup.name
8794
os_type = "Linux"
@@ -99,7 +106,7 @@ resource "azurerm_service_plan" "mongodb-atlas-fabric-service-plan" {
99106

100107
//Service plan for simple deployment without private endpoint
101108
resource "azurerm_service_plan" "mongodb-atlas-fabric-service-simple-plan" {
102-
name = "mongodb-atlas-fabric-service-plan"
109+
name = "mongodb-atlas-fabric-service-plan-${random_string.random_suffix.result}"
103110
location = azurerm_resource_group.mongodb-atlas-fabric-resourceGroup.location
104111
resource_group_name = azurerm_resource_group.mongodb-atlas-fabric-resourceGroup.name
105112
os_type = "Linux"
@@ -114,17 +121,8 @@ resource "azurerm_service_plan" "mongodb-atlas-fabric-service-simple-plan" {
114121
count = try(var.deployPrivateEnvironment ? 0 : 1, 0)
115122
}
116123

117-
resource "random_string" "azurerm_key_vault_name" {
118-
length = 13
119-
lower = true
120-
numeric = false
121-
special = false
122-
upper = false
123-
}
124-
125124
resource "azurerm_key_vault" "mongodb-atlas-fabric-mirrordb-vault" {
126-
# name = "mongodbatlasfabricvault3"
127-
name = coalesce(var.azure_vault_name, "vault-${random_string.azurerm_key_vault_name.result}")
125+
name = coalesce(var.azure_vault_name, "vault-${random_string.random_suffix.result}")
128126
resource_group_name = azurerm_resource_group.mongodb-atlas-fabric-resourceGroup.name
129127
sku_name = var.azure_vault_sku_name
130128
tenant_id = data.azuread_client_config.current.tenant_id
@@ -163,21 +161,21 @@ resource "azurerm_key_vault" "mongodb-atlas-fabric-mirrordb-vault" {
163161
}
164162

165163
resource "azuread_application_registration" "mongodb-atlas-fabric-mirrordb-integration" {
166-
display_name = "mongodb-atlas-fabric-mirrordb-integration"
164+
display_name = "mongodb-atlas-fabric-mirrordb-integration-${random_string.random_suffix.result}"
167165
}
168166

169167
resource "azuread_application_password" "mongodb-atlas-fabric-mirrordb-integration-secret" {
170168
application_id = azuread_application_registration.mongodb-atlas-fabric-mirrordb-integration.id
171169
}
172170

173171
resource "azurerm_key_vault_secret" "mongodb-atlas-fabric-mirrordb-integration-secretValue" {
174-
name = "mongodb-atlas-fabric-app-secret-v2"
172+
name = "mongodb-atlas-fabric-app-secret-v2-${random_string.random_suffix.result}"
175173
value = azuread_application_password.mongodb-atlas-fabric-mirrordb-integration-secret.value
176174
key_vault_id = azurerm_key_vault.mongodb-atlas-fabric-mirrordb-vault.id
177175
}
178176

179177
resource "azurerm_private_endpoint" "mongodb-atlas-fabric-mirrordb-integration-privateEndpoint" {
180-
name = "${var.project_name}-private-endpoint"
178+
name = "${var.project_name}-private-endpoint-${random_string.random_suffix.result}"
181179
location = azurerm_resource_group.mongodb-atlas-fabric-resourceGroup.location
182180
resource_group_name = azurerm_resource_group.mongodb-atlas-fabric-resourceGroup.name
183181
subnet_id = azurerm_subnet.mongodb-atlas-fabric-PrivateLinkSubnet[0].id
@@ -200,11 +198,10 @@ resource "azurerm_private_endpoint" "mongodb-atlas-fabric-mirrordb-integration-p
200198

201199
# https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/linux_web_app
202200
resource "azurerm_linux_web_app" "mongodb-atlas-fabric-mirrordb-integration-webapp" {
203-
name = "mongodbatlasfabricmirrordbsynch"
201+
name = "mongodbatlasfabricmirrordbsynch-${random_string.random_suffix.result}"
204202
resource_group_name = azurerm_resource_group.mongodb-atlas-fabric-resourceGroup.name
205203
location = azurerm_service_plan.mongodb-atlas-fabric-service-plan[0].location
206204
service_plan_id = azurerm_service_plan.mongodb-atlas-fabric-service-plan[0].id
207-
# virtual_network_subnet_id = azurerm_subnet.mongodb-atlas-fabric-webAppSubnet.id
208205
site_config {
209206
application_stack {
210207
python_version = "3.12"
@@ -215,7 +212,7 @@ resource "azurerm_linux_web_app" "mongodb-atlas-fabric-mirrordb-integration-weba
215212
}
216213
app_settings = {
217214
"APP_LOG_LEVEL" = var.applicationLogLevel
218-
"MONGO_CONN_STR" = replace(data.mongodbatlas_advanced_cluster.mongodb-atlas-fabric-integration-connectData.connection_strings[0].private_endpoint[0].srv_connection_string,"mongodb+srv://","mongodb+srv://${var.mongodbatlas_userpass}@")
215+
"MONGO_CONN_STR" = replace(data.mongodbatlas_advanced_cluster.mongodb-atlas-fabric-integration-connectData[0].connection_strings[0].private_endpoint[0].srv_connection_string,"mongodb+srv://","mongodb+srv://${var.mongodbatlas_userpass}@")
219216
"MONGO_DB_NAME" = var.mongodbatlas_dbName
220217
"MONGO_COLLECTION" = var.mongodbatlas_collectionName
221218
"LZ_URL" = replace(fabric_mirrored_database.mongodb-atlas-mirrored-database.properties.onelake_tables_path,"/Tables","/Files/LandingZone/")
@@ -239,7 +236,7 @@ resource "azurerm_linux_web_app" "mongodb-atlas-fabric-mirrordb-integration-weba
239236

240237
resource "azurerm_linux_web_app" "mongodb-atlas-fabric-mirrordb-integration-simple-webapp" {
241238
count = try(var.deployPrivateEnvironment ? 0 : 1, 0)
242-
name = "mongodbatlasfabricmirrordbsynch"
239+
name = "mongodbatlasfabricmirrordbsynch-${random_string.random_suffix.result}"
243240
resource_group_name = azurerm_resource_group.mongodb-atlas-fabric-resourceGroup.name
244241
location = azurerm_service_plan.mongodb-atlas-fabric-service-simple-plan[0].location
245242
service_plan_id = azurerm_service_plan.mongodb-atlas-fabric-service-simple-plan[0].id
@@ -254,7 +251,7 @@ resource "azurerm_linux_web_app" "mongodb-atlas-fabric-mirrordb-integration-simp
254251
}
255252
app_settings = {
256253
"APP_LOG_LEVEL" = var.applicationLogLevel
257-
"MONGO_CONN_STR" = replace(data.mongodbatlas_advanced_cluster.mongodb-atlas-fabric-integration-connectData.connection_strings[0].standard_srv,"mongodb+srv://","mongodb+srv://${var.mongodbatlas_userpass}@")
254+
"MONGO_CONN_STR" = replace(data.mongodbatlas_advanced_cluster.mongodb-atlas-fabric-integration-connectData-noEndpoint.connection_strings[0].standard_srv,"mongodb+srv://","mongodb+srv://${var.mongodbatlas_userpass}@")
258255
"MONGO_DB_NAME" = var.mongodbatlas_dbName
259256
"MONGO_COLLECTION" = var.mongodbatlas_collectionName
260257
"LZ_URL" = replace(fabric_mirrored_database.mongodb-atlas-mirrored-database.properties.onelake_tables_path,"/Tables","/Files/LandingZone/")

terraform/data.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ data "fabric_capacity" "mongodb-fabric-capacity" {
66
data "mongodbatlas_advanced_cluster" "mongodb-atlas-fabric-integration-connectData" {
77
project_id = var.mongodbatlas_group_id
88
name = var.mongodbatlas_clustername
9-
depends_on = [ azurerm_private_endpoint.mongodb-atlas-fabric-mirrordb-integration-privateEndpoint ]
9+
depends_on = [ azurerm_app_service_environment_v3.mongodb-atlas-fabric-appServiceEnv[0] ]
10+
count = try(var.deployPrivateEnvironment ? 1 : 0, 0)
1011
}
1112

1213
data "mongodbatlas_advanced_cluster" "mongodb-atlas-fabric-integration-connectData-noEndpoint" {

terraform/fabricResources.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
resource "fabric_workspace" "mongodb-atlas-mirrored-db-workspace" {
2-
display_name = "MongoDB Atlas Azure Fabric Mirrored Database Integration"
2+
display_name = "MongoDB_Atlas_Azure_Fabric_Mirrored_Database_Integration-${random_string.random_suffix.result}"
33
identity = {
44
type = "SystemAssigned"
55
}

terraform/terraform_tfvars.example

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1-
mongodbatlas_public_key = "<mongodb_atlas_public>key>"
1+
mongodbatlas_public_key = "<mongodb_atlas_public_key>"
22
mongodbatlas_private_key = "<mongodb_atlas_private_key>"
33
mongodbatlas_group_id = "<mongodb_atlas_project_id>"
44
mongodbatlas_clustername = "<mongodb_atlas_cluster_name>"
55
mongodbatlas_dbName = "<mongodb_atlas_collection_name>"
6+
mongodbatlas_collectionName = "all"
67
mongodbatlas_userpass = "<mongodb_atlas_database_username>:<mongodb_atlas_database_password>"
78
owner_tag = "<user_identification>"
89
subscription_id = "<azure_subscription_id>"
910
azure_region = "<azure_region_name>"
1011
azure_vault_name = ""
11-
fabric_capacity_sku = "<fabric_sku_id>"
12+
fabric_capacity_sku = "<MS-Fabric-Capacity-SKU>"
13+
initSyncBatchSize = "100000"
14+
incrementalSyncBatchSize = "1000"
15+
incrementalSyncMaxTimeInterval = "180"
1216
# deployPrivateEnvironment = false
1317
# azure_sku_name = "F1"

terraform/variables.tf

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ variable "mongodbatlas_dbName" {
1717

1818
}
1919
variable "mongodbatlas_collectionName" {
20-
default = "all"
20+
2121
}
2222
variable "mongodbatlas_userpass"{
2323
//MongoDB database username:password
@@ -26,7 +26,6 @@ variable "mongodbatlas_userpass"{
2626
variable "owner_tag" {
2727

2828
}
29-
3029
variable "subscription_id" {
3130

3231
}
@@ -58,17 +57,14 @@ variable "applicationLogLevel" {
5857
variable "initSyncBatchSize" {
5958
//Batch size (rows) used for initial sync
6059
type = string
61-
default ="100000"
6260
}
6361
variable "incrementalSyncBatchSize" {
6462
//Batch size (rows) used for incremental sync
6563
type = string
66-
default = "1000"
6764
}
6865
variable "incrementalSyncMaxTimeInterval" {
6966
//Time interval (in secs), incremental sync waits before replicating accumulated changes when next event occurs
7067
type = string
71-
default = "180"
7268
}
7369

7470
variable "deployPrivateEnvironment" {

0 commit comments

Comments
 (0)