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

Error when trying to create more than one Azure Application Insights API Key #8472

Closed
herrickd opened this issue Sep 15, 2020 · 5 comments · Fixed by #23463
Closed

Error when trying to create more than one Azure Application Insights API Key #8472

herrickd opened this issue Sep 15, 2020 · 5 comments · Fixed by #23463
Labels

Comments

@herrickd
Copy link

herrickd commented Sep 15, 2020

Terraform Version

0.13.2

Terraform Configuration Files

resource "azurerm_resource_group" "prirg" {
    name     = "application-${var.priloc}-${var.env}-rg-01"
    location = var.prilocation
    tags     = var.tags
}

resource "azurerm_application_insights" "priai" {
    name                = "application-${var.priloc}-${var.env}-ai-01"
    location            = azurerm_resource_group.prirg.location
    resource_group_name = azurerm_resource_group.prirg.name
    application_type    = "web"
    retention_in_days   = "365"
    tags                = var.tags
}

resource "azurerm_application_insights_api_key" "priaiapikread" {
    name                    = "application-${var.priloc}-${var.env}-ai-apik-read-01"
    application_insights_id = azurerm_application_insights.priai.id
    read_permissions        = ["aggregate", "api", "draft", "extendqueries", "search"]
}

resource "azurerm_application_insights_api_key" "priaiapikwrite" {
    name                    = "application-${var.priloc}-${var.env}-ai-apik-write-01"
    application_insights_id = azurerm_application_insights.priai.id
    write_permissions       = ["annotations"]
}

Expected Behavior

Two Application Insights API Keys should have been created. One with Read permissions and a second with write permissions.

Actual Behavior

Only one Application Insights API Key was created, the Read key. When trying to create the Write key, the following error was received:
A resource with the ID "/subscriptions/************************/resourcegroups/application-e1us-hdtest-rg-01/providers/microsoft.insights/components/application-e1us-hdtest-ai-01/apikeys/************************" already exists - to be managed via Terraform this resource needs to be imported into the State. Please see the resource documentation for "azurerm_application_insights_api_key" for more information.

Steps to Reproduce

1. terraform init
2. terraform plan
3. terraform validate
4. terraform apply
@neil-yechenwei
Copy link
Contributor

Thanks for opening this issue. I assume you already have the "application-${var.priloc}-${var.env}-ai-apik-write-01" in Azure. So suggest to delete the existing application insights api key resource in Azure, and then have a try below tfconfig to check whether the issue still exists? Thanks.

provider "azurerm" {
  features {}
}

resource "azurerm_resource_group" "test" {
    name     = "application-rg-01"
    location = "eastus2"
}

resource "azurerm_application_insights" "test" {
    name                = "application-ai-test01"
    location            = azurerm_resource_group.test.location
    resource_group_name = azurerm_resource_group.test.name
    application_type    = "web"
    retention_in_days   = "365"
}

resource "azurerm_application_insights_api_key" "test" {
    name                    = "application-apik-readopt-test01"
    application_insights_id = azurerm_application_insights.test.id
    read_permissions        = ["aggregate", "api", "draft", "extendqueries", "search"]
}

resource "azurerm_application_insights_api_key" "test2" {
    name                    = "application-apik-writeopt-01"
    application_insights_id = azurerm_application_insights.test.id
    write_permissions       = ["annotations"]
}

@tombuildsstuff
Copy link
Contributor

hi @herrickd

Thanks for opening this issue.

This forum is intended to be used for feature enhancements and bugs in the Azure Provider - so that we can keep this forum focused on that we instead ask that broader questions are raised using one of the Community Resources. As such I'm going to close this issue for the moment, but I believe you should be able to get an answer for this using one of the Community Resources.

Thanks!

@herrickd
Copy link
Author

@tombuildsstuff - I believe this is a bug, and I request that this be reopened.

@ghost ghost removed the waiting-response label Sep 16, 2020
@herrickd
Copy link
Author

@neil-yechenwei - Your assumption is incorrect. I do not already have this resource created. As I stated in my original post, I am trying to create both keys with the initial script and terraform is throwing the error which acts like the second resource is already created, but it is not.

@ghost
Copy link

ghost commented Oct 16, 2020

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 👉 hashibot-feedback@hashicorp.com. Thanks!

@ghost ghost locked as resolved and limited conversation to collaborators Oct 16, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
4 participants