Closed mm-supernice closed 5 months ago
@rcskosir if there are any further information required, please let me know, i'am here to help
there is a comment by @jackofallops in internal/services/appservice/linux_web_app_resource.go:806
// (@jackofallops) - App Settings can clobber logs configuration so must be updated before we send any Log updates
followed by no implementation to mitigate the clobbing.
In the now deprecated resource for the webapp internal/services/web/app_service_resource.go:555 there is (or was) actually a implementation to mitigate this condition. It seems that this functionality was never ported when refactoring
// the logging configuration has a dependency on the app settings in Azure
// e.g. configuring logging to blob storage will add the DIAGNOSTICS_AZUREBLOBCONTAINERSASURL
// and DIAGNOSTICS_AZUREBLOBRETENTIONINDAYS app settings to the app service.
// If the app settings are updated, also update the logging configuration if it exists, otherwise
// updating the former will clobber the log settings
hasLogs := len(d.Get("logs").([]interface{})) > 0
if d.HasChange("logs") || (hasLogs && d.HasChange("app_settings")) {
logs := expandAppServiceLogs(d.Get("logs"))
logsResource := web.SiteLogsConfig{
ID: utils.String(d.Id()),
SiteLogsConfigProperties: &logs,
}
if _, err := client.UpdateDiagnosticLogsConfig(ctx, id.ResourceGroup, id.SiteName, logsResource); err != nil {
return fmt.Errorf("updating Diagnostics Logs for App Service %q: %+v", id.SiteName, err)
}
}
So i worked out two possible fix but i'am unable to test it, may someone implement it and open a PR <3
Fix 1
At linux_web_app_resource.go#L898
Change the if condition to:
if metadata.ResourceData.HasChange("logs") || updateLogs || metadata.ResourceData.HasChange("app_settings") {
//
}
Or
Fix 2
At linux_web_app_resource.go#L807
Add a block to update "logs" too
// (@jackofallops) - App Settings can clobber logs configuration so must be updated before we send any Log updates
if metadata.ResourceData.HasChange("app_settings") || metadata.ResourceData.HasChange("site_config.0.health_check_eviction_time_in_min") {
appSettingsUpdate := helpers.ExpandAppSettingsForUpdate(state.AppSettings)
appSettingsUpdate.Properties["WEBSITE_HEALTHCHECK_MAXPINGFAILURES"] = pointer.To(strconv.Itoa(state.SiteConfig[0].HealthCheckEvictionTime))
logsUpdate := helpers.ExpandLogsConfig(state.LogsConfig)
if logsUpdate.SiteLogsConfigProperties == nil {
logsUpdate = helpers.DisabledLogsConfig() // The API is update only, so we need to send an update with everything switched of when a user removes the "logs" block
}
if _, err := client.UpdateDiagnosticLogsConfig(ctx, id.ResourceGroup, id.SiteName, *logsUpdate); err != nil {
return fmt.Errorf("updating Logs Config for Linux %s: %+v", id, err)
}
if _, err := client.UpdateApplicationSettings(ctx, id.ResourceGroup, id.SiteName, *appSettingsUpdate); err != nil {
return fmt.Errorf("updating App Settings for Linux %s: %+v", id, err)
}
}
@mm-supernice thanks for raising this issue, are you still experiencing this issue after the mentioned fix was merged?
@mm-supernice thanks for raising this issue, are you still experiencing this issue after the mentioned fix was merged?
Hi, thanks for checking.
Unfortunately the PR does not fix the issue (tested with 3.87.0).
after a quick review of the PR the issue seems to be that at Line 858 now not only app_settings is considered but also site_config which is great. however "logs" is also separated from them and not within site_config. that might be the reason why the fix doesn't affect this issue.
@mm-supernice Thanks for the update, let me check.
any progress on this?
Also bumping this issue.
Drift detection doesn't work, and we have resources in a state of thrash due to this bug.
Setting an ignore_changes
is harmful, since we need to ensure that we have proper log retention set at all times.
Same here, still not fixed and super annoying.
for everyone facing this issue, don't forget to vote, raise awareness on this one. Version 3.94.0 and it's still there. This kind of issue seems to be recurrent. Faced a similar thing with docker configuration.
fix would be appreciated from here too :)
For what its worth: I reported this as a bug through our Enterprise support plan and was told a fix is expected between August and October.
Thanks, for that
A quinta, 2/05/2024, 12:49, Sven Grunewaldt @.***> escreveu:
For what its worth: I reported this as a bug through our Enterprise support plan and was told a fix is expected between August and October.
— Reply to this email directly, view it on GitHub https://github.com/hashicorp/terraform-provider-azurerm/issues/23713#issuecomment-2090305299, or unsubscribe https://github.com/notifications/unsubscribe-auth/AM6OPV5STTS2HICPSUB5ULDZAIR3LAVCNFSM6AAAAAA6SZKYNWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAOJQGMYDKMRZHE . You are receiving this because you commented.Message ID: @.***>
a fix is expected between August and October.
this year?
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.
Is there an existing issue for this?
Community Note
Terraform is deleting the "retention_in_days" on "any" (or most) changes you apply to that resource without notifying. The reason for this behaviour is:
however, setting "retention_in_days" is the proper way to do and of course also present in the state On Azure itself, it does not matter if you add/set the environment variable or the explicit setting, if you change one of them, it alters the other automatically.
In our case it causes the following:
on the next run, terraform plan detects the missing "retention_in_days" setting and updates it, which is what you actually see as the unwanted change.
Voting
Terraform Version
1.6.2
AzureRM Provider Version
v3.78.0
Affected Resource(s)/Data Source(s)
azurerm_linux_web_app
Terraform Configuration Files
Debug Output/Panic Output
on any change in the azurerm_linux_web_app resource, the JSON which is PUT' to the API is lacking the WEBSITE_HTTPLOGGING_RETENTION_DAYS setting which causes a removal of that environment variable. unfortunately this then let the Azure setting to remove the setting "retention_in_days" since the Env variable and that setting are hard-linked.
Additionally, there is no second PUT which makes sure the retention_in_days setting is set again, after removal of the "WEBSITE_HTTPLOGGING_RETENTION_DAYS" environment variable.
The only PUT request sent to the API removes the "WEBSITE_HTTPLOGGING_RETENTION_DAYS" by not explicitly having it in the json. this change is not shown by the terraform plan, since the WEBSITE_HTTPLOGGING_RETENTION_DAYS is not covered by the provider and even actively removed since the proper place to configure is the "retention_in_days" setting.
Expected Behaviour
Expected API Request
on any change in the azurerm_linux_web_app resource, the JSON which is PUT' to the API is lacking the WEBSITE_HTTPLOGGING_RETENTION_DAYS setting which causes a removal of that environment variable. unfortunately this then let the Azure setting to remove the setting "retention_in_days" since the Env variable and that setting are hard-linked.
Additionally, there is no second PUT which makes sure the retention_in_days setting is set again, after removal of the "WEBSITE_HTTPLOGGING_RETENTION_DAYS" environment variable.
The only PUT request sent to the API removes the "WEBSITE_HTTPLOGGING_RETENTION_DAYS" by not explicitly having it in the json. this change is not shown by the terraform plan, since the WEBSITE_HTTPLOGGING_RETENTION_DAYS is not covered by the provider and even actively removed since the proper place to configure is the "retention_in_days" setting.
Would cause the following resource object
Actual Behaviour
But retentionInDays gets removed entirely
Steps to Reproduce
create any azurerm_linux_web_app resource
make sure to set the following setting in the resource definition:
and
apply your setting
in the portal, check the following settings:
change a setting, in my case, add a whitelist rule.
apply again
you will see: just the whitelist will be and was added
check the following settings:
apply again
you will see:
Important Factoids
No response
References
No response