Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Retain existing settings during deployment - avm/res/web/site #3311

Merged
merged 5 commits into from
Sep 20, 2024

Conversation

peterbud
Copy link
Contributor

@peterbud peterbud commented Sep 16, 2024

Description

This commit changes the app settings deployment in order to retain existing app settings that are not defined in the Bicep file. This change allows for updating only the app settings that are defined in the Bicep file, while leaving the rest unchanged.

As this is a change in behavior, version number has been increased.

Fixes #949

Pipeline Reference

Pipeline
avm.res.web.site

Type of Change

  • Update to CI Environment or utilities (Non-module affecting changes)
  • Azure Verified Module updates:
    • Bugfix containing backwards-compatible bug fixes, and I have NOT bumped the MAJOR or MINOR version in version.json:
      • Someone has opened a bug report issue, and I have included "Closes #{bug_report_issue_number}" in the PR description.
      • The bug was found by the module author, and no one has opened an issue to report it yet.
    • Feature update backwards compatible feature updates, and I have bumped the MINOR version in version.json.
    • Breaking changes and I have bumped the MAJOR version in version.json.
    • Update to documentation

Checklist

  • I'm sure there are no other open Pull Requests for the same update/change
  • I have run Set-AVMModule locally to generate the supporting module files.
  • My corresponding pipelines / checks run clean and green without any errors or warnings

This commit adds the retainExistingSettings parameter to the app settings deployment in order to retain existing app settings that are not defined in the Bicep file. This parameter allows for updating only the app settings that are defined in the Bicep file, while leaving the rest unchanged.

Fixes Azure#949
@peterbud peterbud requested review from a team as code owners September 16, 2024 13:08
@microsoft-github-policy-service microsoft-github-policy-service bot added the Needs: Triage 🔍 Maintainers need to triage still label Sep 16, 2024

Important

The "Needs: Triage 🔍" label must be removed once the triage process is complete!

Tip

For additional guidance on how to triage this issue/PR, see the BRM Issue Triage documentation.

@microsoft-github-policy-service microsoft-github-policy-service bot added the Type: AVM 🅰️ ✌️ Ⓜ️ This is an AVM related issue label Sep 16, 2024

Important

If this is a module-related PR, being submitted by the sole owner of the module, the AVM core team must review and approve it (as module owners can't approve their own PRs).

To indicate this PR needs the core team''s attention, apply the "Needs: Core Team 🧞" label!

The core team will only review and approve PRs that have this label applied!

@avm-team-linter avm-team-linter bot added the Needs: Module Owner 📣 This module needs an owner to develop or maintain it label Sep 16, 2024
Copy link
Contributor

@pankajagrawal16 pankajagrawal16 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not think it makes sense to add a new variable to control this, module should do this by deafult.

avm/res/web/site/README.md Outdated Show resolved Hide resolved
@matebarabas matebarabas changed the title feat: Add retainExistingSettings parameter to app settings deployment feat: Add retainExistingSettings parameter to app settings deployment - avm/res/web/site Sep 18, 2024
@peterbud peterbud changed the title feat: Add retainExistingSettings parameter to app settings deployment - avm/res/web/site feat: Retain existing settings during deployment - avm/res/web/site Sep 19, 2024
Copy link
Contributor

@pankajagrawal16 pankajagrawal16 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@krbar krbar merged commit 07a0593 into Azure:main Sep 20, 2024
5 checks passed
@peterbud peterbud deleted the 949 branch September 21, 2024 16:11
@@ -294,6 +294,7 @@ module app_appsettings 'config--appsettings/main.bicep' = if (!empty(appSettings
storageAccountUseIdentityAuthentication: storageAccountUseIdentityAuthentication
appInsightResourceId: appInsightResourceId
appSettingsKeyValuePairs: appSettingsKeyValuePairs
currentAppSettings: !empty(app.id) ? list('${app.id}/config/appsettings', '2023-12-01').properties : {}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What kind of deployment would have an empty app.id?

@@ -294,6 +294,7 @@ module app_appsettings 'config--appsettings/main.bicep' = if (!empty(appSettings
storageAccountUseIdentityAuthentication: storageAccountUseIdentityAuthentication
appInsightResourceId: appInsightResourceId
appSettingsKeyValuePairs: appSettingsKeyValuePairs
currentAppSettings: !empty(app.id) ? list('${app.id}/config/appsettings', '2023-12-01').properties : {}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be configurable? I fear that someone will open a ticket at some point to have full idempotency.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jikuja Certainly yes. IaC is about desired state and full update not incremental.
But I'm more concerned with a potential race condition.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jikuja Can you elaborate on what do you think when you say race condition ?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jikuja Can you elaborate on what do you think when you say race condition ?

@pankajagrawal16 It seems the deployment is doing a fetch, then merge the properties. It is not an atomic operation. Two concurrent deployments (with different name) will fetch the same old values and only pushes its new properties. The last one to push will wins.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@scrocquesel-ml150 Are you talking about multiple concurrent deployments of avm/res/web/site/main.bicep or concurrent deployment of avm/res/web/site/main.bicep main module and avm/res/web/site/config--appsettings/main.bicep?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@scrocquesel-ml150 Are you talking about multiple concurrent deployments of avm/res/web/site/main.bicep or concurrent deployment of avm/res/web/site/main.bicep main module and avm/res/web/site/config--appsettings/main.bicep?

two avm/res/web/site/main.bicep will fetch the same existing values, then, after resource app is completed, each one will create a new avm/res/web/site/config--appsettings/main.bicep deployment with the same existing values and maybe different new values as appSettingsKeyValuePairs. I think if you want to be sure no race condition can occur, you can make an atomic deployment with the exact same deployment name because Azure will not permit to create a deployment of the same name if one exists and is not completed and will fail the deployment. So if you fetch the existing value and update the properties inside such a deployment, you have kind of a poor-man semaphore/lock.
I admit this is a race condition that is difficult to produce and everyone is using more or less this pattern without even knowing it exists. I guess it is a matter of complexity vs reliability.

Copy link
Contributor Author

@peterbud peterbud Sep 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see the issue you are describing here.

In case one is running the same deployments concurrently (it's already an anti pattern AFAIK) they will get the same appSettingsKeyValuePairs (i.e.: keeping values NOT defined in the bicep file, and merging them with the defined values from the bicep file) - so I don't see an issue or race condition: both deployment will result the same result even running concurrently.

In case somebody is running different deployments concurrently, then the last will win, aka the latest deployment will take precedence - which is normal. Also note, that was the behavior before this change already.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs: Module Owner 📣 This module needs an owner to develop or maintain it Needs: Triage 🔍 Maintainers need to triage still Type: AVM 🅰️ ✌️ Ⓜ️ This is an AVM related issue
Projects
None yet
5 participants