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

v3.98.0: azurerm_application_insights_api_key fails with error due to casing in resourcegroup #25522

Closed
1 task done
patst opened this issue Apr 5, 2024 · 7 comments · Fixed by #25567 or #25628
Closed
1 task done

Comments

@patst
Copy link
Contributor

patst commented Apr 5, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Community Note

  • Please vote on this issue by adding a 👍 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 and review the contribution guide to help.

Terraform Version

1.7.5

AzureRM Provider Version

3.98.0

Affected Resource(s)/Data Source(s)

azurerm_application_insights_api_key

Terraform Configuration Files

resource "azurerm_application_insights_api_key" "a" {
  name                    = "appik-${local.resource_infix}-a"
  application_insights_id = var.datasources.application_insights.id
  read_permissions        = ["aggregate", "api", "draft", "extendqueries", "search"]
  write_permissions       = ["annotations"]
}

Debug Output/Panic Output

Error: parsing "/subscriptions/<subscriptionid>/resourcegroups/rg-my-resource/providers/microsoft.insights/components/appi-my-resource/apiKeys/f4ad4343-cf20-424e-b111-b86e5a83a349": parsing segment "staticResourceGroups": parsing the ApiKey ID: the segment at position 2 didn't match

Expected a ApiKey ID that matched:

> /subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Insights/components/componentValue/apiKeys/keyIdValue

However this value was provided:

> /subscriptions/<subscriptionid>/resourcegroups/rg-my-resource/providers/microsoft.insights/components/appi-my-resource/apiKeys/f4ad4343-cf20-424e-b111-b86e5a83a349

The parsed Resource ID was missing a value for the segment at position 2
(which should be the literal value "resourceGroups").



  with module.chatbot.azurerm_application_insights_api_key.chatbot,
  on ../../../../../modules/gap-chatbot/main.tf line 31, in resource "azurerm_application_insights_api_key" "chatbot":
  31: resource "azurerm_application_insights_api_key" "chatbot" {

##[error]Terraform command 'plan' failed with exit code '1'.:  parsing "/subscriptions/<subscriptionid>/resourcegroups/rg-my-resource/providers/microsoft.insights/components/appi-my-resource/apiKeys/f4ad4343-cf20-424e-b111-b86e5a83a349": parsing segment "staticResourceGroups": parsing the ApiKey ID: the segment at position 2 didn't match
##[error]
Error: parsing "/subscriptions/<subscriptionid>/resourcegroups/rg-my-resource/providers/microsoft.insights/components/appi-my-resource/apiKeys/f4ad4343-cf20-424e-b111-b86e5a83a349": parsing segment "staticResourceGroups": parsing the ApiKey ID: the segment at position 2 didn't match

Expected a ApiKey ID that matched:

> /subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Insights/components/componentValue/apiKeys/keyIdValue

However this value was provided:

> /subscriptions/<subscriptionid>/resourcegroups/rg-my-resource/providers/microsoft.insights/components/appi-my-resource/apiKeys/f4ad4343-cf20-424e-b111-b86e5a83a349

The parsed Resource ID was missing a value for the segment at position 2
(which should be the literal value "resourceGroups").

Expected Behaviour

resource is created

Actual Behaviour

error occurs (see debug output)

Steps to Reproduce

terraform plan

The issue occurs after updating the provider to v3.98.0 and running a plan.

The issue did not occur with provider version 3.97.1

I think it is probably an error in the Azure REST API, which returns the value resourcegroup in lower casing. The validation expect its with an upper g(resourceGroup)

Important Factoids

No response

References

Maybe it is related to this change: #25376

@Devvox93
Copy link

Devvox93 commented Apr 9, 2024

I have similar Output and indeed this did not happen with 3.97.1 and now occurs with 3.98.0.
My observation is that it is indeed casing, but not with "resourceGroups" but with "Microsoft.Insights" (expected) and "microsoft.insights" (provided).
I can see that that differs in the error message in my own pipeline as well as the output provided above.

Our output:

Error: parsing "/subscriptions/ac4c0c2c-af8a-42de-b36d-29b37fe715ce/resourceGroups/<our_resource_group>/providers/microsoft.insights/components/<our_appi_id>": parsing segment "staticMicrosoftInsights": parsing the Component ID: the segment at position 5 didn't match

│ Expected a Component ID that matched:

│ > /subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Insights/components/componentValue

│ However this value was provided:

│ > /subscriptions/ac4c0c2c-af8a-42de-b36d-29b37fe715ce/resourceGroups/<our_resource_group>/providers/microsoft.insights/components/<our_appi_id>

│ The parsed Resource ID was missing a value for the segment at position 5
│ (which should be the name of the Resource Provider [for example 'Microsoft.Insights']).

@katbyte
Copy link
Collaborator

katbyte commented Apr 9, 2024

I believe this might have been caused by #25376

@celia-moreno
Copy link

I am facing also similar issue. Output:

Error: parsing "/subscriptions/<mysubscriptionId>/resourcegroups/<myResourceGroup>/providers/microsoft.insights/components/<myComponentName>/apiKeys/<myApiKeyvalue>": parsing segment "staticResourceGroups": parsing the ApiKey ID: the segment at position 2 didn't match

Expected a ApiKey ID that matched:

> /subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Insights/components/componentValue/apiKeys/keyIdValue

However this value was provided:

> /subscriptions/<mysubscriptionId>/resourcegroups/<myResourceGroup>/providers/microsoft.insights/components/<myComponentName>/apiKeys/<myApiKeyvalue>

The parsed Resource ID was missing a value for the segment at position 2
(which should be the literal value "resourceGroups").

@Devvox93
Copy link

Devvox93 commented Apr 12, 2024

I would like to reopen this issue, as even with v3.99.0 set, the issue still persists. See the terraform init and plan below:

Initializing provider plugins...
- Finding hashicorp/azuread versions matching "2.47.0"...
- Finding azure/azapi versions matching "1.12.1"...
- Finding latest version of hashicorp/random...
- Finding hashicorp/azurerm versions matching "3.99.0"...
- Installing hashicorp/azuread v2.47.0...
- Installed hashicorp/azuread v2.47.0 (signed by HashiCorp)
- Installing azure/azapi v1.12.1...
- Installed azure/azapi v1.12.1 (signed by a HashiCorp partner, key ID 6F0B91BDE98478CF)
- Installing hashicorp/random v3.6.0...
- Installed hashicorp/random v3.6.0 (signed by HashiCorp)
- Installing hashicorp/azurerm v3.99.0...
- Installed hashicorp/azurerm v3.99.0 (signed by HashiCorp)

Partner and community providers are signed by their developers.
If you'd like to know more about provider signing, you can read about it here:
https://www.terraform.io/docs/cli/plugins/signing.html

Terraform has created a lock file .terraform.lock.hcl to record the provider
selections it made above. Include this file in your version control repository
so that Terraform can guarantee to make the same selections by default when
you run "terraform init" in the future.

Terraform has been successfully initialized!

Next pipeline task (plan):

Planning failed. Terraform encountered an error while generating this plan.

╷
│ Error: parsing "/subscriptions/af9cf5e1-3be2-4ad2-808b-2c1f6648200b/resourceGroups/<redacted-lowercase-rg>/providers/microsoft.insights/components/<redacted-lowercase-resource>": parsing segment "staticMicrosoftInsights": parsing the Component ID: the segment at position 5 didn't match

│ Expected a Component ID that matched:

│ > /subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Insights/components/componentValue

│ However this value was provided:

│ > /subscriptions/af9cf5e1-3be2-4ad2-808b-2c1f6648200b/resourceGroups/<redacted-lowercase-rg>/providers/microsoft.insights/components/<redacted-lowercase-resource>

│ The parsed Resource ID was missing a value for the segment at position 5
│ (which should be the name of the Resource Provider [for example 'Microsoft.Insights']).



│   with module.ai.azurerm_application_insights.ai,
│   on .terraform/modules/ai/main.tf line 1, in resource "azurerm_application_insights" "ai":
│    1: resource "azurerm_application_insights" "ai" {

I saw mention of a state-migration in the PR that was supposed to fix this and assumed that would happen automatically.
Am I wrong to assume that and if so, what manual actions are required to fix this?
Asking here, because probably other devs will be wondering this as well (if this bug has indeed been fixed).

@stephybun Could you confirm/deny that this bug could still be present and/or explain what steps are needed?

@tombuildsstuff
Copy link
Contributor

@Devvox93 apologies for the inconvenience here, it appears that a second state migration is needed on that resource too - @stephybun can you take a look at that adding that one?

Alternatively/in the interim you should be able to workaround that by using terraform state rm to remove this resource from your state and then re-importing the terraform import the azurerm_application_insights resource with the fixed Resource ID, which'll fix this.

@Devvox93
Copy link

Thanks for confirming it's not on our side and not blaming anyone. We're all human!

Unfortunately, this runs in separated environments, each with isolated state backends with no direct way of accessing them.
To prevent manual changes, we've temporarily locked our provider version to 3.97.1 and will remove that lock once this issue is released. Will that be a 3.99.1 or should we wait for 3.100? Either way is fine by me/us :)

Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 17, 2024
@rcskosir rcskosir added the bug label Aug 23, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.