terraform-provider-azurerm
terraform-provider-azurerm copied to clipboard
Creating Application Insights ends with error 400
Is there an existing issue for this?
- [X] I have searched the existing issues
Community Note
- Please vote on this issue by adding a :thumbsup: reaction to the original issue to help the community and maintainers prioritize this request
- Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
- If you are interested in working on this issue or have submitted a pull request, please leave a comment
Terraform Version
1.2.1
AzureRM Provider Version
3.8.0
Affected Resource(s)/Data Source(s)
azurerm_application_insights
Terraform Configuration Files
resource "azurerm_application_insights" "ai" {
name = "test-ai"
resource_group_name = "TESTAI"
location = "westeurope"
application_type = "web"
}
Debug Output/Panic Output
https://gist.github.com/spc-pl/ab8d14ccdbb3eb19df0625dbcab9be52
Expected Behaviour
Application Insights component is created, terraform state is updated and no error occurs, script continues.
Actual Behaviour
Application Insights component is created, terraform state is not updated and error is thrown, script stops its execution.
│ Error: update Application Insights Billing Feature "test-ai" (Resource Group "TESTAI"): insights.ComponentCurrentBillingFeaturesClient#Update: Failure responding to request: StatusCode=400 -- Original Error: autorest/azure: Service returned an error. Status=400 Code="One or more errors occurred." Message="One or more errors occurred." InnerError={"diagnosticcontext":"d58b23bb-639f-48d5-86df-fca0ef220b84","time":"2022-05-31T08:02:15.4081332Z"} │ │ with azurerm_application_insights.ai, │ on main.tf line 11, in resource "azurerm_application_insights" "ai": │ 11: resource "azurerm_application_insights" "ai" {
Steps to Reproduce
No response
Important Factoids
References
Do we have workaround? I received similar error and same behavior as original poster.
"
Error: read Application Insights Billing Features "appi-" (Resource Group "rg-"): insights.ComponentCurrentBillingFeaturesClient#Get: Failure responding to request: StatusCode=200 -- Original Error: Error occurred unmarshalling JSON - Error = 'json: cannot unmarshal array into Go value of type insights.ApplicationInsightsComponentBillingFeatures' JSON = '[]'
│
│ with azurerm_application_insights.appi1,
│ on application-insights.tf line 2, in resource "azurerm_application_insights" "appi1":
│ 2: resource "azurerm_application_insights" "appi1" {
"
Any clue about this? I receive the same error. Even though the application insight is created, terraform throws an error and stops execution. Error: read Application Insights Billing Features "Appinsights-name" (Resource Group "RGname"): insights.ComponentCurrentBillingFeaturesClient#Get: Failure responding to request: StatusCode=200 -- Original Error: Error occurred unmarshalling JSON - Error = 'json: cannot unmarshal array into Go value of type insights.ApplicationInsightsComponentBillingFeatures' JSON = '[]'
The same script works on another subscription in same region, same permission level!
The call to /subscriptions/my_subscription_id/resourceGroups/appinsight-rg/providers/Microsoft.Insights/components/my-appinsight/currentbillingfeatures?api-version=2015-05-01 returns an empty array, which seems to be unexpected by azurerm provider. Raised a ticket to try to get some help from Microsoft.
2022-06-13T22:04:20.609+0200 [DEBUG] provider.terraform-provider-azurerm_v3.10.0_x5: AzureRM Request:
GET /subscriptions/my_subscription_id/resourceGroups/appinsight-rg/providers/Microsoft.Insights/components/my-appinsight/currentbillingfeatures?api-version=2015-05-01 HTTP/1.1
Host: management.azure.com
User-Agent: Go/go1.18.1 (amd64-linux) go-autorest/v14.2.1 Azure-SDK-For-Go/v64.1.0 insights/2020-02-02 HashiCorp Terraform/1.2.2 (+https://www.terraform.io) Terraform Plugin SDK/2.10.1 terraform-provider-azurerm/dev pid-222c6c49-1b0a-5959-a213-6608f9eb8820
X-Ms-Correlation-Request-Id: [...]
Accept-Encoding: gzip: timestamp=2022-06-13T22:04:20.608+0200
2022-06-13T22:04:21.016+0200 [DEBUG] provider.terraform-provider-azurerm_v3.10.0_x5: AzureRM Response for https://management.azure.com/subscriptions/my_subscription_id/resourceGroups/appinsight-rg/providers/Microsoft.Insights/components/my-appinsight/currentbillingfeatures?api-version=2015-05-01:
HTTP/2.0 200 OK
Access-Control-Expose-Headers: Request-Context
Cache-Control: no-cache
Content-Type: application/json; charset=utf-8
Date: Mon, 13 Jun 2022 20:04:21 GMT
Expires: -1
Pragma: no-cache
Request-Context: appId=cid-v1:[...]
Server: Microsoft-IIS/10.0
Strict-Transport-Security: max-age=31536000; includeSubDomains
Vary: Accept-Encoding
X-Content-Type-Options: nosniff
X-Ms-Correlation-Request-Id: [...]
X-Ms-Ratelimit-Remaining-Subscription-Reads: 11999
X-Ms-Request-Id: [...]
X-Ms-Routing-Request-Id: FRANCECENTRAL:20220613T200421Z:[...]
[]: timestamp=2022-06-13T22:04:21.016+0200
2022-06-13T22:04:21.017+0200 [ERROR] vertex "import azurerm_application_insights.this[0] result" error: making Read request on AzureRM Application Insights Billing Feature 'my-appinsight': insights.ComponentCurrentBillingFeaturesClient#Get: Failure responding to request: StatusCode=200 -- Original Error: Error occurred unmarshalling JSON - Error = 'json: cannot unmarshal array into Go value of type insights.ApplicationInsightsComponentBillingFeatures' JSON = '[]'
2022-06-13T22:04:21.017+0200 [ERROR] vertex "azurerm_application_insights.this[0] (import id \"/subscriptions/my_subscription_id/resourceGroups/appinsight-rg/providers/Microsoft.Insights/components/my-appinsight\")" error: making Read request on AzureRM Application Insights Billing Feature 'my-appinsight': insights.ComponentCurrentBillingFeaturesClient#Get: Failure responding to request: StatusCode=200 -- Original Error: Error occurred unmarshalling JSON - Error = 'json: cannot unmarshal array into Go value of type insights.ApplicationInsightsComponentBillingFeatures' JSON = '[]'
Error: making Read request on AzureRM Application Insights Billing Feature 'my-appinsight': insights.ComponentCurrentBillingFeaturesClient#Get: Failure responding to request: StatusCode=200 -- Original Error: Error occurred unmarshalling JSON - Error = 'json: cannot unmarshal array into Go value of type insights.ApplicationInsightsComponentBillingFeatures' JSON = '[]'
EDIT : got a reply from MS, that pointed out issue #17229
The issue pointed by MS is now closed, but it didn't resolve the problrm for me. Still AI is created and the process is failing without properly updating the state. Do I need to execute terraform script on a new resource group, or the root cause of the issue is different?
This seems to be a separate but similar issue to #17229. Slightly different error messages, but the end result is the same: App Insights instance is created but not added to TF state.
I'm still seeing this error sporadically, e.g. I just ran a TF deployment that failed with this error message, then manually deleted the App Insights instance and re-ran TF and it succeeded.
It's frustrating. I wouldn't be so bothered by the issue if it didn't require manual intervention to fix/try again.
Hi,
I'm getting the same error during last two weeks.
│ Error: read Application Insights Billing Features "appi-apim-xxx-test-westus3" (Resource Group "rg-xxx-test-westus3"): insights.ComponentCurrentBillingFeaturesClient#Get: Failure responding to request: StatusCode=404 -- Original Error: autorest/azure: error response cannot be parsed: {"" '\x00' '\x00'} error: EOF │ │ with module.api_management.azurerm_application_insights.application_insights, │ on ../baseline_modules/api_management/main.tf line 125, in resource "azurerm_application_insights" "application_insights": │ 125: resource "azurerm_application_insights" "application_insights" {
@SergiyDivnych I'm faced with the exact error as you. Did you manage to overcome it somehow?
Hi @tamirkamara. It's happening from time to time, when I'm spinning up new environments.
For who ever encounter this in the future, we have temporarily mitigated the "billing" issue mentioned about by moving to AzApi provider and this example definition for app insights:
resource "azapi_resource" "appinsights" {
type = "Microsoft.Insights/components@2020-02-02"
name = local.app_insights_name
parent_id = var.resource_group_id
location = var.location
body = jsonencode({
kind = "web"
properties = {
Application_Type = "web"
Flow_Type = "Bluefield"
Request_Source = "rest"
IngestionMode = "LogAnalytics"
WorkspaceResourceId = var.azmonitor_workspace_id
}
})
response_export_values = [
"id",
"properties.ConnectionString",
]
}