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

azurerm_datadog_monitor_tag_rule remains after destroy #22793

Closed
1 task done
bmv0161 opened this issue Aug 2, 2023 · 2 comments · Fixed by #22806
Closed
1 task done

azurerm_datadog_monitor_tag_rule remains after destroy #22793

bmv0161 opened this issue Aug 2, 2023 · 2 comments · Fixed by #22806

Comments

@bmv0161
Copy link

bmv0161 commented Aug 2, 2023

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.5.4

AzureRM Provider Version

3.67.0

Affected Resource(s)/Data Source(s)

azurerm_datadog_monitor_tag_rule, azurerm_datadog_monitor

Terraform Configuration Files

terraform {
  required_version = "~>1.5.4"

  backend "azurerm" {
  }

  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = "~>3.67.0"
    }
  }
}

resource "azurerm_datadog_monitor" "logs" {
  name = "test"

  location            = "westus2" # Hard requirement on Azure.
  resource_group_name = "test"

  sku_name = "Linked"

  datadog_organization {
    api_key         = ""
    application_key = ""
  }

  identity {
    type = "SystemAssigned"
  }

  user {
    email = "a@example.com"
    name  = "asdf"
  }
}

resource "azurerm_datadog_monitor_tag_rule" "example" {
  datadog_monitor_id = azurerm_datadog_monitor.test.id
  log {
    subscription_log_enabled = false
    resource_log_enabled = false
    aad_log_enabled = false
  }
  metric {
    filter {
      name   = "Test"
      value  = "Logs"
      action = "Include"
    }
  }
}

Debug Output/Panic Output

------ Destroy -----
/opt/hostedtoolcache/terraform/1.5.4/x64/terraform apply -auto-approve tfplandestroy
azurerm_datadog_monitor_tag_rule.example: Destroying... [id=/subscriptions/***/resourceGroups/rg-datadog/providers/Microsoft.Datadog/monitors/nonprd-rbs-skele-datadog/tagRules/default]
azurerm_role_assignment.example: Destroying... [id=/subscriptions/***/providers/Microsoft.Authorization/roleAssignments/d686901f-03a1-8ec9-ef55-272c4eec17d1]
azurerm_role_assignment.example: Destruction complete after 2s
azurerm_datadog_monitor_tag_rule.example: Destruction complete after 2s
azurerm_datadog_monitor.adusa_datadog: Destroying... [id=/subscriptions/***/resourceGroups/rg-datadog/providers/Microsoft.Datadog/monitors/nonprd-rbs-skele-datadog]
azurerm_datadog_monitor.adusa_datadog: Still destroying... [id=/subscriptions/...adog/monitors/nonprd-rbs-skele-datadog, 10s elapsed]
azurerm_datadog_monitor.adusa_datadog: Destruction complete after 11s
azurerm_resource_group_policy_exemption.loc_exemption: Destroying... [id=/subscriptions/***/resourceGroups/rg-datadog/providers/Microsoft.Authorization/policyExemptions/datadogMonitorLocation]
azurerm_resource_group_policy_exemption.loc_exemption: Destruction complete after 1s
azurerm_resource_group.rgdatadog: Destroying... [id=/subscriptions/***/resourceGroups/rg-datadog]
azurerm_resource_group.rgdatadog: Still destroying... [id=/subscriptions/***/resourceGroups/rg-datadog, 10s elapsed]
azurerm_resource_group.rgdatadog: Still destroying... [id=/subscriptions/***/resourceGroups/rg-datadog, 20s elapsed]
azurerm_resource_group.rgdatadog: Still destroying... [id=/subscriptions/***/resourceGroups/rg-datadog, 30s elapsed]
azurerm_resource_group.rgdatadog: Still destroying... [id=/subscriptions/***/resourceGroups/rg-datadog, 40s elapsed]
azurerm_resource_group.rgdatadog: Destruction complete after 46s

Apply complete! Resources: 0 added, 0 changed, 5 destroyed.

------ Apply -----
azurerm_resource_group.rgdatadog: Creating...
azurerm_resource_group.rgdatadog: Creation complete after 0s [id=/subscriptions/***/resourceGroups/rg-datadog]
azurerm_resource_group_policy_exemption.loc_exemption: Creating...
azurerm_resource_group_policy_exemption.loc_exemption: Creation complete after 1s [id=/subscriptions/***/resourceGroups/rg-datadog/providers/Microsoft.Authorization/policyExemptions/datadogMonitorLocation]
azurerm_datadog_monitor.adusa_datadog: Creating...
azurerm_datadog_monitor.adusa_datadog: Still creating... [10s elapsed]
azurerm_datadog_monitor.adusa_datadog: Still creating... [20s elapsed]
azurerm_datadog_monitor.adusa_datadog: Creation complete after 25s [id=/subscriptions/***/resourceGroups/rg-datadog/providers/Microsoft.Datadog/monitors/nonprd-rbs-skele-datadog]
azurerm_datadog_monitor_tag_rule.example: Creating...
azurerm_role_assignment.example: Creating...
azurerm_role_assignment.example: Still creating... [10s elapsed]
azurerm_role_assignment.example: Still creating... [20s elapsed]
azurerm_role_assignment.example: Creation complete after 22s [id=/subscriptions/***/providers/Microsoft.Authorization/roleAssignments/518d595d-956e-9080-a8b1-32daeb9f484f]
╷
│ Error: A resource with the ID "/subscriptions/***/resourceGroups/rg-datadog/providers/Microsoft.Datadog/monitors/nonprd-rbs-skele-datadog/tagRules/default" already exists - to be managed via Terraform this resource needs to be imported into the State. Please see the resource documentation for "azurerm_datadog_monitor_tag_rule" for more information.
│ 
│   with azurerm_datadog_monitor_tag_rule.example,
│   on main.tf line 52, in resource "azurerm_datadog_monitor_tag_rule" "example":
│   52: resource "azurerm_datadog_monitor_tag_rule" "example" {
│ 
╵
##[debug]Exit code 1 received from tool '/opt/hostedtoolcache/terraform/1.5.4/x64/terraform'
##[debug]STDIO streams have closed for tool '/opt/hostedtoolcache/terraform/1.5.4/x64/terraform'
##[debug]allowTelemetryCollection=true
##[error]Terraform command 'apply' failed with exit code '1'.

Expected Behaviour

After Terraform Destroy, resources can be recreated without error.

Actual Behaviour

When attempting to recreate, receive a resource already exists error for azurerm_datadog_monitor_tag_rule.

Apply only succeeds when resource is manually removed through Azure Powershell, Remove-AzResource, before the destroy step.

Error: A resource with the ID "/subscriptions/***/resourceGroups/rg-datadog/providers/Microsoft.Datadog/monitors/nonprd-rbs-skele-datadog/tagRules/default" already exists - to be managed via Terraform this resource needs to be imported into the State. Please see the resource documentation for "azurerm_datadog_monitor_tag_rule" for more information.

Steps to Reproduce

  1. terraform apply to create azurerm_datadog_monitor and azurerm_datadog_monitor_tag_rule resources.
  2. terraform destroy
  3. terraform apply to recreate - causes error

Important Factoids

Using the Datadog US3 region which requires the location of the azurerm_datadog_monitor to be westus2.

References

No response

@bmv0161 bmv0161 changed the title Microsoft.Datadog/monitors/tagrules remains after destroy azurerm_datadog_monitor_tag_rule remains after destroy Aug 2, 2023
@bmv0161
Copy link
Author

bmv0161 commented Aug 2, 2023

I have also encountered this issue without Terraform Destroy.

When the Microsoft.Datadog/monitors resource is removed outside of Terraform (without removing the tagrules/default resource first), the apply also fails with the same error.

Copy link

github-actions bot commented May 1, 2024

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 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
2 participants