0
votes

I want to create azure app service using terraform.

resource "azurerm_app_service" "one-app-sts" {
  name                = "${var.environment}-one-app-sts"
  location            = "${var.location}"
  resource_group_name = "${azurerm_resource_group.one.name}"
  app_service_plan_id = "${azurerm_app_service_plan.one.id}"

  app_settings {
    "Serilog:WriteTo:0:Args:workspaceId" = "${azurerm_log_analytics_workspace.one.workspace_id}"
  }

  tags {
    environment = "${var.environment}"
    source      = "terraform"
  }
}

For testing it should be named test-one-app-sts, for production prod-one-app-sts. I tried to inject variables with tfvar file, however terrafrom plans to rename services instead of creating new one.

How would I make a script in a way so I can create/destroy as many different environemnts as a want (dev,test,prev,uat,prod)?

PS> Example is for service, but I also have service bus, databases, functions as part of an environment, that should be recreated/destroyed.

1
Are you opposed to using slots? Here is a sample terraform.io/docs/providers/azurerm/r/app_service_slot.htmlKen W MSFT

1 Answers

0
votes

Well, figured it out: workspace is an answer https://www.terraform.io/docs/state/workspaces.html

I can deploy any number of copies of my environment =)

terraform workspace new test

will create new state, only for test.