0

Have developed a common module to create azure app service plan and app service for projects. In azurerm version 2 setting kind variable in app service plan resource with value linux or windows.

But with azurerm 3 upgrade there is one app service plan resource and 2 app services resources. Is there anyway to decide which resource be created depending on value of input variable apart from using count like below . Script Used
resource "azurerm_service_plan" "app_service_plan" {
name = local.name
location = var.location
resource_group_name = var.resource_group_name
tags = var.tags
os_type = var.os_type}

for windows
resource "azurerm_windows_web_app" "app_service" {
name = local.name
location = var.location
resource_group_name = var.resource_group_name
service_plan_id = var.app_service_plan_id
count = var.kind == "Windows" ?1:0}

for linux
resource "azurerm_linux_web_app" "app_service" {
name = local.name
location = var.location
resource_group_name = var.resource_group_name
service_plan_id = var.app_service_plan_id
count = var.kind == "Linux" ?1:0}

simmyk
  • 26
  • 4
  • Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. – Community Jan 10 '23 at 18:13

1 Answers1

0

Is there any way to decide which resource be created depending on value of input variable apart from using count

Yes, there is another way to create a web app (resource) depends on the value of input variable (var:kind).

Using depends_on block:

depends_on = [var.kind == "windows" ? azurerm_windows_web_app : azurerm_linux_web_app]

Or you can also use terraform modules.

Reference: Sample terraform web app deployment module "app service" if required.

&

Refer SO worked by me in bicep for other approach.

Jahnavi
  • 3,076
  • 1
  • 3
  • 10