Skip to content

Move Log Analytics Reader role to ai-project.bicep#60

Open
pamelafox wants to merge 1 commit intoAzure-Samples:mainfrom
pamelafox:fix/move-log-analytics-reader-role
Open

Move Log Analytics Reader role to ai-project.bicep#60
pamelafox wants to merge 1 commit intoAzure-Samples:mainfrom
pamelafox:fix/move-log-analytics-reader-role

Conversation

@pamelafox
Copy link
Copy Markdown

The Log Analytics Reader role assignment needs to be created for both new and existing App Insights resources. Currently (added in #57), it's inside the applicationInsights module, which is gated on shouldCreateAppInsights. That condition is false whenever an existing App Insights connection string is provided — including on re-provisions, since azd saves the first deploy's outputs as env vars that flow back as "existing" parameters.

This means the role assignment is only created on a completely fresh first-time deploy. On any subsequent provision — or when using a pre-existing App Insights — continuous evaluation fails with:

Unable to query Application Insights due to insufficient permissions. Ensure the project's managed identity has the Log Analytics Reader role on the connected Application Insights resource.

Fix: Move the role assignment from applicationinsights.bicep to ai-project.bicep, gated on enableMonitoring instead of shouldCreateAppInsights. This ensures the project managed identity gets Log Analytics Reader regardless of whether App Insights is newly created or pre-existing.

The role assignment was inside the applicationInsights module, which is
gated on shouldCreateAppInsights. After the first azd up, the App Insights
connection string output gets saved as an azd env var, which flows back
into existingApplicationInsightsConnectionString on subsequent provisions.
This makes shouldCreateAppInsights=false, so the entire module--including
the role assignment--is skipped on re-provision.

Move the role assignment to ai-project.bicep conditioned on
enableMonitoring, which is always true when monitoring is active
regardless of whether App Insights was freshly created or pre-existing.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant