Skip to content

Commit 8c8fa1f

Browse files
committed
Fix Redis public access, staging slot config, teardown, retention consistency
- Add public_network_access_enabled=false to Redis in AI and API-first (TF+Bicep) - Add appSettings to staging slot in API-first Bicep (Cosmos, Redis, AppInsights) - Teardown script: check terraform.tfvars exists before destroy - Standardize Log Analytics retention to 30 days across all examples - Update Application Insights API version from 2020-02-02 to 2020-11-20
1 parent fea8822 commit 8c8fa1f

File tree

5 files changed

+55
-23
lines changed

5 files changed

+55
-23
lines changed

examples/ai-startup/main.bicep

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ resource redis 'Microsoft.Cache/redis@2024-03-01' = {
269269
}
270270
enableNonSslPort: false
271271
minimumTlsVersion: '1.2'
272+
publicNetworkAccess: 'Disabled'
272273
}
273274
}
274275

examples/ai-startup/terraform/main.tf

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -324,15 +324,16 @@ resource "azurerm_storage_container" "datasets" {
324324
# ==============================================================================
325325

326326
resource "azurerm_redis_cache" "this" {
327-
name = "redis-${var.app_name}-${var.environment}"
328-
location = var.location
329-
resource_group_name = data.azurerm_resource_group.this.name
330-
capacity = var.environment == "prod" ? 1 : 0
331-
family = "C"
332-
sku_name = var.environment == "prod" ? "Standard" : "Basic"
333-
non_ssl_port_enabled = false
334-
minimum_tls_version = "1.2"
335-
tags = local.tags
327+
name = "redis-${var.app_name}-${var.environment}"
328+
location = var.location
329+
resource_group_name = data.azurerm_resource_group.this.name
330+
capacity = var.environment == "prod" ? 1 : 0
331+
family = "C"
332+
sku_name = var.environment == "prod" ? "Standard" : "Basic"
333+
non_ssl_port_enabled = false
334+
minimum_tls_version = "1.2"
335+
public_network_access_enabled = false
336+
tags = local.tags
336337
}
337338

338339
# ==============================================================================

examples/api-first-startup/main.bicep

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,13 @@ resource law 'Microsoft.OperationalInsights/workspaces@2023-09-01' = {
4141
tags: tags
4242
properties: {
4343
sku: { name: 'PerGB2018' }
44-
retentionInDays: 90
44+
// 30-day retention keeps costs low for startup workloads. Increase to 90 days
45+
// for compliance or if you need longer investigative windows.
46+
retentionInDays: 30
4547
}
4648
}
4749

48-
resource appInsights 'Microsoft.Insights/components@2020-02-02' = {
50+
resource appInsights 'Microsoft.Insights/components@2020-11-20' = {
4951
name: 'ai-${appName}-${environment}'
5052
location: location
5153
tags: tags
@@ -120,6 +122,20 @@ resource stagingSlot 'Microsoft.Web/sites/slots@2023-12-01' = if (environment ==
120122
minTlsVersion: '1.2'
121123
ftpsState: 'Disabled'
122124
alwaysOn: false
125+
appSettings: [
126+
{
127+
name: 'APPLICATIONINSIGHTS_CONNECTION_STRING'
128+
value: appInsights.properties.ConnectionString
129+
}
130+
{
131+
name: 'COSMOS_ENDPOINT'
132+
value: cosmos.properties.documentEndpoint
133+
}
134+
{
135+
name: 'REDIS_HOSTNAME'
136+
value: redis.properties.hostName
137+
}
138+
]
123139
}
124140
}
125141
}
@@ -231,6 +247,7 @@ resource redis 'Microsoft.Cache/redis@2024-03-01' = {
231247
}
232248
enableNonSslPort: false
233249
minimumTlsVersion: '1.2'
250+
publicNetworkAccess: 'Disabled'
234251
}
235252
}
236253

examples/api-first-startup/terraform/main.tf

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,10 @@ resource "azurerm_log_analytics_workspace" "this" {
115115
location = var.location
116116
resource_group_name = data.azurerm_resource_group.this.name
117117
sku = "PerGB2018"
118-
retention_in_days = 90
119-
tags = local.tags
118+
# 30-day retention keeps costs low for startup workloads. Increase to 90 days
119+
# for compliance or if you need longer investigative windows.
120+
retention_in_days = 30
121+
tags = local.tags
120122
}
121123

122124
resource "azurerm_application_insights" "this" {
@@ -125,7 +127,7 @@ resource "azurerm_application_insights" "this" {
125127
resource_group_name = data.azurerm_resource_group.this.name
126128
workspace_id = azurerm_log_analytics_workspace.this.id
127129
application_type = "web"
128-
retention_in_days = 90
130+
retention_in_days = 30
129131
tags = local.tags
130132
}
131133

@@ -285,15 +287,16 @@ resource "azurerm_cosmosdb_sql_role_assignment" "app_cosmos" {
285287
# ==============================================================================
286288

287289
resource "azurerm_redis_cache" "this" {
288-
name = "redis-${var.app_name}-${var.environment}"
289-
location = var.location
290-
resource_group_name = data.azurerm_resource_group.this.name
291-
capacity = var.environment == "prod" ? 1 : 0
292-
family = "C"
293-
sku_name = var.environment == "prod" ? "Standard" : "Basic"
294-
non_ssl_port_enabled = false
295-
minimum_tls_version = "1.2"
296-
tags = local.tags
290+
name = "redis-${var.app_name}-${var.environment}"
291+
location = var.location
292+
resource_group_name = data.azurerm_resource_group.this.name
293+
capacity = var.environment == "prod" ? 1 : 0
294+
family = "C"
295+
sku_name = var.environment == "prod" ? "Standard" : "Basic"
296+
non_ssl_port_enabled = false
297+
minimum_tls_version = "1.2"
298+
public_network_access_enabled = false
299+
tags = local.tags
297300
}
298301

299302
# ==============================================================================

scripts/teardown.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,16 @@ if [[ "$TOOL" == "terraform" ]]; then
104104
TF_VAR_budget_start_date="$(date -u +%Y-%m-01T00:00:00Z)"
105105

106106
cd "$TF_DIR"
107+
108+
# terraform.tfvars must exist — it provides required variables
109+
# (subscription_id, company_name, budget_alert_emails, security_contact_email).
110+
if [[ ! -f "terraform.tfvars" ]]; then
111+
echo "Error: terraform.tfvars not found in $TF_DIR."
112+
echo "This file is required for destroy — it provides subscription_id, company_name, and other required variables."
113+
echo "Create it from the example: cp terraform.tfvars.example terraform.tfvars"
114+
exit 1
115+
fi
116+
107117
terraform init
108118
terraform destroy \
109119
-var="environment=$ENV" \

0 commit comments

Comments
 (0)