Programmatically set Azure App Service application settings / environment variables - azure

I have an ASP.NET Core (RC1) app running on Azure App Service. The app takes its configuration from environment variables. I currently use the Azure Portal's 'Application Settings' page to set these environment variables. The app is deployed with Kudu (if this is relevant?)
I would like a way to programmatically set these environment variables so that I don't have to go through the Azure Portal every time I want to create a new environment variable or modify an existing environment variable. Ideally I would like to do this by calling a REST API. Is this possible, and if so, how?

Instead of setting environment variables in the Azure Portal, you could deploy an appsettings.json file along with your app with the desired settings. If you have a build server or deployment server, you could transform the config file with the correct settings for your environment.
If you i.e. are using Octopus Deploy for deployments, you could use the JSON Configuration variables feature to handle this.
http://docs.octopusdeploy.com/display/OD/JSON+Configuration+Variables+Feature

Related

Public environment variables from Next.js not working in Azure Static Web App

I had my app previously deployed on Vercel, but since I'm using Azure AD and MongoDB on Azure, I'm moving the hosting of my app to Azure as well for decreased networking delays.
I set all my environment variables under Configuration -> Application Settings in the Production environment. The private variables (e.g. client secrets) are perfectly readable by my Next.js back-end, but my front-end cannot read the environment variables prefixed by NEXT_PUBLIC, even though this previously worked in my other projects on Vercel and Google Cloud Platform.
Printing the public environment variables (NEXT_PUBLIC_*) to the console returns undefined.
How do I make a distinction between full-stack and server-side environment variables? Because NEXT_PUBLIC does not seem to work.
I found a workaround. Under the build_and_deploy_job -> steps, add a field named env. Under this, you can place your environment variables like this:
env:
NEXT_PUBLIC_VARIABLE: "value1"
NEXT_PUBLIC_ANOTHER_VARIABLE: "value2"
You can find my full .yml file here.
I want to express the fact that this is a suboptimal solution and for the multi-billion dollar company that Microsoft is, you should be able to place public/client-side environment variables directly in your Static Web App via the Azure web portal.

Azure Web API set Environment Variables

I'm trying to authenticate to Firebase Firestore on a C# WebAPi 2 hosted in Azure.
According to the docs, it's as easy as:
Otherwise, the simplest way of authenticating your API calls is to
download a service account JSON file then set the
GOOGLE_APPLICATION_CREDENTIALS environment variable to refer to it.
The credentials will automatically be used to authenticate. See the
Getting Started With Authentication guide for more details.
This works locally on my machine but I can't seem to find a way how to set this environment variable in a Azure WebApp?
As Junnas mentioned you can set the App settings, which will act as environment variables.
(source: windows.net)
In Asp.Net 5 there is a build in
Configuration = new Configuration()
.AddJsonFile("config.json")
.AddEnvironmentVariables();
Read this blog and this SO
You can find all the predefined environment variables at below link,
https://<yoursitename>.scm.azurewebsites.net/Env.cshtml

upload json config file with azure functions?

I have Azure functions with configs (database connection strings, active directory, etc) set up for dev and live environments, right now I have everything in a class and I comment in/out the bits I'm using or not using.
Is there a way to upload a json file with the azure functions that will guide its config?
You mention "upload a json file" so I'm assuming that you're referring to some sort of release management activity. My suggestion is to simply use the built in AppSettings. Your use case is essentially what they are built for. Generally speaking if you store your settings within the appsettings of a function app and you have separate environments for your functions (dev & live) then you don't need to manage a separate json configuration file. The environment owns the configuration and your code will get the settings from the current environment.
If you have a more complex deployment and configuration management scenario I would consider using a release management tool such as VSTS to manage those configuration settings as part of the release pipeline so each environment has the correct settings at deployment time. Most CI\CD tools have functionality to update json configuration and\or update Azure App configuration directly.
Yes. You need to add connection strings as Application Settings. Azure Functions Core Tools uses local.settings.json file to read your connection strings when running locally and these settings are not pushed to Azure when published.

Is there a way to update Application Settings from a Web.Config file in an Azure App Service

I am using the Application Setting in an Azure App Service to inject some config variables into the Web.Config, but when I add a new variable into the web.config I need to manually add it into the Application Settings in order to be able to inject against this new variable.
Is there a way to have these Application Settings automatically update in Azure when a new Web.config file is deployed, or is it a manual step specifically to reduce the number of variables which are editable?

Azure App Settings not added to website when using virtual applications

According to the following screenshoot that shows all environment variables for an application and the configured app settings in the azure portal, i get the impression that app settings do not work with virtual applications. Is this intented?
I'm not exactly sure what your left pane image is showing, but App Settings should apply to both the roo app and any virtual apps under it. They are based on environment variables (e.g. foo becomes APPSETTING_foo), which are available throughout the environment.

Resources