'In Terraform Azure azurerm, How to get App Config Connection String?

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?



Solution 1:[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"]);

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Frederick Ollinger