Skip to content

Commit 95b16b6

Browse files
Add random suffix to resources with name conflict
1 parent ca2c4c1 commit 95b16b6

File tree

6 files changed

+22
-19
lines changed

6 files changed

+22
-19
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/azureResources.tf

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
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" {
29
name = "mongodb-atlas-fabric-resourceGroup"
310
location = var.azure_region
@@ -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,9 @@ 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" {
126125
# name = "mongodbatlasfabricvault3"
127-
name = coalesce(var.azure_vault_name, "vault-${random_string.azurerm_key_vault_name.result}")
126+
name = coalesce(var.azure_vault_name, "vault-${random_string.random_suffix.result}")
128127
resource_group_name = azurerm_resource_group.mongodb-atlas-fabric-resourceGroup.name
129128
sku_name = var.azure_vault_sku_name
130129
tenant_id = data.azuread_client_config.current.tenant_id
@@ -204,7 +203,6 @@ resource "azurerm_linux_web_app" "mongodb-atlas-fabric-mirrordb-integration-weba
204203
resource_group_name = azurerm_resource_group.mongodb-atlas-fabric-resourceGroup.name
205204
location = azurerm_service_plan.mongodb-atlas-fabric-service-plan[0].location
206205
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
208206
site_config {
209207
application_stack {
210208
python_version = "3.12"
@@ -215,7 +213,7 @@ resource "azurerm_linux_web_app" "mongodb-atlas-fabric-mirrordb-integration-weba
215213
}
216214
app_settings = {
217215
"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}@")
216+
"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}@")
219217
"MONGO_DB_NAME" = var.mongodbatlas_dbName
220218
"MONGO_COLLECTION" = var.mongodbatlas_collectionName
221219
"LZ_URL" = replace(fabric_mirrored_database.mongodb-atlas-mirrored-database.properties.onelake_tables_path,"/Tables","/Files/LandingZone/")
@@ -254,7 +252,7 @@ resource "azurerm_linux_web_app" "mongodb-atlas-fabric-mirrordb-integration-simp
254252
}
255253
app_settings = {
256254
"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}@")
255+
"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}@")
258256
"MONGO_DB_NAME" = var.mongodbatlas_dbName
259257
"MONGO_COLLECTION" = var.mongodbatlas_collectionName
260258
"LZ_URL" = replace(fabric_mirrored_database.mongodb-atlas-mirrored-database.properties.onelake_tables_path,"/Tables","/Files/LandingZone/")
@@ -291,4 +289,4 @@ resource "azurerm_app_service_source_control" "mongodb-atlas-fabric-mirrordb-int
291289
depends_on = [ azurerm_linux_web_app.mongodb-atlas-fabric-mirrordb-integration-simple-webapp[0] ]
292290
//
293291
count = try(var.deployPrivateEnvironment ? 0 : 1, 0)
294-
}
292+
}

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/variables.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ variable "mongodbatlas_userpass"{
2626
variable "owner_tag" {
2727

2828
}
29+
variable "keep_until" {
2930

31+
}
3032
variable "subscription_id" {
3133

3234
}

0 commit comments

Comments
 (0)