What's the best way to handle complex environment configurations in App Service?
Asked by
TechWhiz92
I'm working with an ASP.NET Core app that utilizes appsettings.json for its default values, which we then override using environment variables for different environments. Our Terraform deployment sets up over 30 environment variables at the app service level, and keeping track of these is becoming a bit overwhelming since environment variables lack the structure that YAML or JSON provides. Unlike Kubernetes, where we can use structured configmaps and mount them as files, we're limited with App Service to using just environment variables.
I've been considering a few options:
1. Have Terraform pull structured YAML or JSON from our config repo, then map it to a flat list of environment variables. This would certainly make the config easier to maintain in the repo, but we'll still have to deal with a long list of flat env vars in Terraform plans and App Service configurations.
2. Use Azure App Configuration to store our JSON config. However, I'm not convinced this offers much difference in terms of management.
3. During the deployment pipeline, we could mount appsettings.json from our config repo directly to the app service.
I'm leaning towards option 1 for the short term and considering option 3 for the long term, but that may require some testing and adjustments to our deployment pipeline. What are your thoughts?
Answers
In my previous company, we had a separate config repo that contained a large JSON file with all our static info. This was called from the Terraform source repo. It sounds a lot like what you propose in option 1โit could definitely be a solid approach.
Reply to this answer
I usually opt for the first option when dealing with repeatable values in Terraform. It works great! Just a tipโdonโt store secret values directly in there. Instead, you can reference Key Vault secret IDs in those JSON files, which can be integrated into your Terraform code as locals. This keeps your configuration clean and secure.
Reply to this answer
Why are you keeping such a hefty configuration outside of your main repo? I'd be curious to understand what drives that decision.
Reply to this answer
Actually, .NET supports hierarchical configuration through environment variables, but there are some quirks to be aware of. For instance, while a colon ':' is the delimiter in the Configuration API, you might have issues on different platforms. A double underscore '__' works universally and will convert to a colon automatically. However, I get your point about structureโit can get messy with deeper nesting.
Reply to this answer
Add your answer
Answers are reviewed before publication.
Related Discussions