I'm trying to figure out how to update the JSON config files in my .NET Core web service, based on the deployed resources using Terraform.
I have an existing Azure DevOps pipeline, which builds/deploys a .NET Core web service to an Azure App Service.
In moving to Terraform, I'll be creating a CosmosDb database, Azure Search service, Event Grid, etc. for dev/test/prod environments.
I have a handle on creating these in Terraform, but I'm not clear how to take the outputs from these resources (like the CosmosDb location, key, and database id) and inject these into my JSON config files in my deployed web service.
Has anyone done this sort of thing, and can show a Terraform example? Thanks!
You don't actually inject those into your config file, you set those as app settings in your App Service and that will override those keys in your config file.
So if you have:
{
CosmosDb: {
Key: ""
}
}
In your terraform you would do the following.
resource "azurerm_app_service" "test" {
name = "example-app-service"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
app_service_plan_id = "${azurerm_app_service_plan.test.id}"
app_settings = {
"CosmosDb:Key" = "${azurerm_cosmosdb_account.db.primary_master_key}"
}
}
So you would reference your other Terraform resources to pull out the values you need and put those in the app settings section of your App Service in Terraform.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With