-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Feature Request: Attach azurerm_application_insights to a azurerm_app_service #1303
Comments
hey @CryptonZylog Thanks for opening this issue :) Would it be possible to show the Terraform Configuration that you've attempted to use? From what I can see above it should be possible to set a tag on the
Thanks! |
Actually, you got it. That's what I've tried anyway (setting that tag). |
@CryptonZylog
👍 as far as I'm aware there's no API for this at the moment - but I've reached out to Microsoft to confirm :) |
I am not sure I understand what the Terraform integration of App Insights is buying us right now. I have created an AI instance and stored its key as an output. When I create an App I want to attach to the AI instance, I add the
These two settings get added to my app but I am not sure what the first one even does because I still have to go into the portal, select Web App > Application Insights and enable it by selecting the recently created AI instance that was created by Terraform. When I do this, I do not see any additional app settings on the Web App. Where would I go to see the hidden tag mentioned above? |
@Phydeauxman unfortunately the hidden tag needs to be applied on the I've requested that Microsoft investigate adding an API for attaching/detaching Application Insights to things rather than use tags - so it's possible to make this attachment independently; but I'm unsure of the status of that feature request, unfortunately. |
@tombuildsstuff so, I would use the property below under my
I am assuming I can use variables in that |
So I've just completed a project where we are doing this using terraform. The way I accomplish this is as below: Create Application Insights resourceresource "azurerm_application_insights" "webappai" { output "webapp_key" { output "webapp_id" { Create Webappresource "azurerm_app_service" "webapp" { site_config { app_settings { depends_on = [ The only catch in above is "${var.logstore}" needs to be specified before. I do this by means of a copied connection string of a previously working App Insights. Also, the above does not install the Application Insights extension for the app (webapp) so I take care of this after using a local-exec powershell script. Hope this helps? |
did they ever come back with an api for this? the docs are still having you modify everything with app settings, seems like most the gui is a thin layer on top of that https://docs.microsoft.com/en-us/azure/azure-monitor/app/azure-web-apps#automate-monitoring would it fit in terraform to have the options in their own stanza, but in the end they just end up being appsettings? or is that a no-no cause it would cause conflicts with app settings |
@test-in-prod where did you see that hidden tag? in resource explorer? |
i might be missing it, but i don't see that tag anymore. maybe they stopped using it. It appears the only thing that triggers the Portal GUI to show app insights is needed is if the app has various settings on the slot. Here's what i ended up doc'ing
|
fwiw, this is similar to how the log configuration settings work. The app settings generated by the API are ignored by the provider (though I'm not sure if there's a separate API yet for app insights). |
with MS now contributing to the azurerm provider is there any plan to resolve this issue. |
Not sure if this has changed in the Ms side but it now seems to add a app_settings when you enable App insights, something along the lines of:
|
So it seems setting this value hooks up app insights correctly now. This is what I did:
not too sure about the |
@sonic1981 Your solution helped me, but the ingestion endpoint has "-1" instead for me (westeurope). I do not know where this number comes from. |
Closing as appears to be resolved by 8699 but wasn't linked successfully to this issue. |
This has been released in version 2.31.0 of the provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. As an example: provider "azurerm" {
version = "~> 2.31.0"
}
# ... other configuration ... |
@jackofallops isn't this request for more native support, IE an app_insights attribute or more likely block within app_service? so we do NOT have to hack through the property namings? in such a case this should stay open i'd think |
I agree
This needs to be fully integrated as config
…On Thu, 8 Oct 2020, 20:15 drdamour, ***@***.***> wrote:
@jackofallops <https://github.com/jackofallops> isn't this request for
more native support, IE an app_insights attribute or more likely block
within app_service? so we do NOT have to hack through the property namings?
in such a case this should stay open i'd think
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#1303 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AH7GYFZDCUPIL32HUSN7XM3SJYFVXANCNFSM4FB2CX2Q>
.
|
@drdamour / @Marcus-James-Adams / @bkaid - if that's what you want then go tell Microsoft, it is them, not the resource provider who implement connecting the connection in this way (using app settings). Terraform's Azure provider just follows the Azure APIs. The change made to resolve this to make it nicer is the following: What used to be this: resource "azurerm_app_service" "example" {
# ....
app_settings {
APPINSIGHTS_INSTRUMENTATIONKEY = azurerm_application_insights.appinsight.instrumentation_key
APPLICATIONINSIGHTS_CONNECTION_STRING = "InstrumentationKey=${azurerm_application_insights.appinsight.instrumentation_key};IngestionEndpoint=https://${azurerm_resource_group.rg.location}-0.in.applicationinsights.azure.com/"
}
} is now this: resource "azurerm_app_service" "example" {
# ....
app_settings {
APPINSIGHTS_INSTRUMENTATIONKEY = azurerm_application_insights.appinsight.instrumentation_key
APPLICATIONINSIGHTS_CONNECTION_STRING = azurerm_application_insights.appinsight.connection_string
}
} Which imo is much better than it was, and is exactly native. |
Attaching application insights to a webapp works as expected using the app settings for instrumentation key and connection string. Oddly though for function apps the same approach does not work. When attached using the portal it adds a hidden tag to the app insights resource. Running terraform removes the hidden tag, therefore disconnecting the two, so I've tried adding the tag to the app insights resource code using the ID output from the function app. This however causes a race condition in terraform as the function app needs the app insights resource to get the instrumentation key and connection string, and the app insights resource now needs the function app for the app ID, and terraform can't cope with this. |
@CyanMass45 whats the tag |
|
does the hidden tag actually break it? I don't think it does... and it would seem to create a circular dependency if you were to make it yourself... my way around it is to deterministically calculate what the resource_id will be after the other side is created and create the hidden-link tag using terraform also, then it won't remove it next time you apply it. Again, this is a circular dependency introduced by Microsoft and not the terraform providers fault. |
i didn't realize that terraform azurerm provide was against making these types of abstractions. consider me learned. this issue which is over 2 years old wasn't just about this connectionstring property which just showed up recently so the closure reason seemed not to be compatible with the request.
given that thought the request was already in progress. |
So is there a way to get Application Insights and a Function App to attach using Terraform? |
I got it to work by doing the following to avoid the 'cycle':
Example snippet:
|
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 feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 [email protected]. Thanks! |
Community Note
Description
Greetings, this is just a feature request to enable attachment of a azurerm_application_insights to a azurerm_app_service.
Right now, this can only be done via the portal (or assuming also via Azure ARM template) by going to an App Service -> Application Insights, then creating or selecting an existing resource. After this, I see it creates APPINSIGHTS_* environment variables (app settings) and also a peculiar "hidden" tag on the target application insights resource with a value
"hidden-link:/subscriptions/<subscription id>/resourceGroups/<rg name>/providers/Microsoft.Web/sites/<site name>": "Resource"
I tried to replicate this via terraform, however it does not appear to be working even though the resulting exported ARM template is exactly the same as one generated manually via Azure Portal.
Thanks!
The text was updated successfully, but these errors were encountered: