2

Given an app_service:

resource "azurerm_resource_group" "example" {
  name     = "example-resources"
  location = "West Europe"
}

resource "azurerm_app_service_plan" "example" {
  name                = "example-appserviceplan"
  location            = azurerm_resource_group.example.location
  resource_group_name = azurerm_resource_group.example.name

  sku {
    tier = "Standard"
    size = "S1"
  }
}

resource "azurerm_app_service" "example" {
  name                = "example-app-service"
  location            = azurerm_resource_group.example.location
  resource_group_name = azurerm_resource_group.example.name
  app_service_plan_id = azurerm_app_service_plan.example.id

  site_config {
    dotnet_framework_version = "v4.0"
    scm_type                 = "LocalGit"
  }

  app_settings = {
    "AppConfig" = "some-value"
  }

  connection_string {
    name  = "Database"
    type  = "SQLServer"
    value = "Server=some-server.mydomain.com;Integrated Security=SSPI"
  }
}

In app_settings, section, how do I get the connection string for the app config and set it to the variable AppConfig?

I would like to do something like: azurerm_app_configuration.appconf.connection_string, but I do not think this works.

Is this value possible to know at terraform apply time?

  • May i know an example value of app config value that you want to set? what is app config connection string ? AFAIK you have already set that in connection string .. if you want others like storage and keyvault etc. you have to get the connection sting and store it there. please refer : [Configure common settings](https://learn.microsoft.com/en-us/azure/app-service/configure-common?tabs=portal) – Ansuman Bal Jan 24 '22 at 07:58
  • You need to dynamically get the app config connection string from Terraform because you only know it after you created the App Config which is also done from Terraform. This can be gotten by accessing the primary_read_key (if you need read access for example). – Frederick Ollinger Jan 24 '22 at 19:52

1 Answers1

1

Add the result to app_settings:

app_settings = {
  "AppConfig" = azurerm_app_configuration.example-app-service.primary_read_key[0].connection_string
}

Now you can read it out in C#. (Snipped the code for context.) config variable is passed in to webBuilder.ConfigureAppConfiguration(hostingContext, config).

var settings = config.Build();
Console.WriteLine(settings["AppConfig"]);