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_subscription_policy_remediation attempts deletion after completion and fails #16456

Closed
1 task done
davejhahn opened this issue Apr 19, 2022 · 2 comments · Fixed by #16478
Closed
1 task done

Comments

@davejhahn
Copy link

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

Terraform Version

1.1.8

AzureRM Provider Version

3.2.0

Affected Resource(s)/Data Source(s)

azurerm_subscription_policy_remediation

Terraform Configuration Files

provider "azurerm" {
  features {}
}

resource "azurerm_subscription_policy_assignment" "tags" {

  for_each = {for policy in var.policies : policy.name => policy}   
    name                 = each.value["name"]
    subscription_id      = "/subscriptions/${data.azurerm_client_config.this.subscription_id}"
    policy_definition_id = data.azurerm_policy_definition.addtags.id
    description          = each.value["description"]
    display_name         = each.value["display_name"]
    enforce              = each.value["enforce"]
    location             = var.location
    identity {
            type = "SystemAssigned"
    }
    not_scopes = each.value["not_scopes"]
    parameters = <<PARAMETERS
        {
            "tagName"  : { 
                "value" : "${each.value["tagName"]}"
            },
            "tagValue" : {
                "value" : "${each.value["tagValue"]}"
            }
        }
    PARAMETERS
}

resource "azurerm_subscription_policy_remediation" "this" {

  for_each = {for policy in var.policies : policy.name => policy }

    name                 = lower(each.value["name"])
    subscription_id      = "/subscriptions/${data.azurerm_client_config.this.subscription_id}"
    policy_assignment_id = azurerm_subscription_policy_assignment.tags[each.key].id
    resource_discovery_mode = "ReEvaluateCompliance"
}

data "azurerm_policy_definition" "addtags" {
  display_name = "Add a tag to resources"
}

data "azurerm_client_config" "this" {
}

Debug Output/Panic Output

Error: cancelling /subscriptions/XXXXXX/providers/Microsoft.PolicyInsights/remediations/tagremediation: policyinsights.RemediationsClient#CancelAtSubscription: Failure responding to request: StatusCode=400 -- Original Error: autorest/azure: Service returned an error. Status=400 Code="InvalidCancelRemediationRequest" Message="The request to cancel remediation 'XXXXX' is invalid. A completed remediation cannot be cancelled."

Expected Behaviour

Changes to a policy assignment that would cause a delete/create should complete without an error. If there is an associated policy remediation that has already run, it should not attempt to delete it because a policy remediation cannot be deleted once completed.

Actual Behaviour

When changing a policy assignment that causes a delete/create, if there is a policy remediation that has already executed for that policy, it fails trying to delete and prevents the new policy from being created.

Steps to Reproduce

No response

Important Factoids

No response

References

No response

@github-actions
Copy link

This functionality has been released in v3.4.0 of the Terraform Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

@github-actions
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 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
3 participants