How to Update Secrets and References in Azure App Services Using Terraform?

0
1
Asked By TechieTraveler42 On

Hi everyone,

I've been working with Terraform to manage secrets in Azure Key Vault, and we're utilizing these secrets in our App Service with Key Vault references. Generally, it works well, but we've run into a significant issue: when we use versionless references, it can take up to 24 hours for the latest secret value to be fetched, which is actually a documented behavior. We managed to work around this by using versioned secrets, but that presents another problem: after updating a secret, I have to run Terraform apply twice—first to update the secret and then to update the App Service with the new secret reference.

I've read that we might be able to use versionless secrets and trigger a management API call to refresh the secrets in the App Service, but I'm unsure if this is a good practice. Is there a way to update both the secret and the reference in the App Service in a single Terraform run?

Thanks!

3 Answers

Answered By JavaNinja98 On

I ran into a similar issue before. A workaround I found was to stop and start the App Service, which oddly doesn't trigger a refresh on its own. Another method we used was flipping a dummy app setting from 0 to 1 to force a refresh. However, eventually, we went with a PowerShell script that made a REST call to refresh the secrets as needed.

Answered By CloudyWithAChance On

It sounds like you might be able to accomplish this in one run! If you share your code for how you're declaring the secrets and their references, we can take a closer look. Normally, I'd expect both to update with one apply if set up correctly.

Answered By APIEnthusiast On

There's actually an API available for this—check out the Azure Key Vault documentation for App Service references. Ideally, you should update secrets before they expire so that both versions are valid which helps avoid the refresh issue.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.