Skip to content

Commit 7f70143

Browse files
committed
Refactor prevent_destroy logic to use local variable
Moved the prevent_destroy logic into a local variable in locals.tf and updated resource lifecycle blocks in web-app.tf to reference local.prevent_destroy. This centralizes environment-based lifecycle configuration for easier maintenance.
1 parent 63a2860 commit 7f70143

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

infra/locals.tf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,7 @@ locals {
1414

1515
# Log level based on environment
1616
log_level = var.environment == "prod" ? "Warning" : "Verbose"
17+
18+
# Prevent destroy for production environment
19+
prevent_destroy = var.environment == "prod"
1720
}

infra/web-app.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ resource "azurerm_service_plan" "service_plan" {
88
tags = local.common_tags
99

1010
lifecycle {
11-
prevent_destroy = var.environment == "prod" ? true : false
11+
prevent_destroy = local.prevent_destroy
1212
}
1313
}
1414

@@ -48,6 +48,6 @@ resource "azurerm_linux_web_app" "web-app" {
4848
tags = local.common_tags
4949

5050
lifecycle {
51-
prevent_destroy = var.environment == "prod" ? true : false
51+
prevent_destroy = local.prevent_destroy
5252
}
5353
}

0 commit comments

Comments
 (0)