hashicorp / terraform-provider-azurerm

Terraform provider for Azure Resource Manager
https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs
Mozilla Public License 2.0
4.53k stars 4.6k forks source link

Destroy azurerm_network_watcher_flow_log fails if traffic_analytics is not enabled #6913

Closed markhoiland closed 4 years ago

markhoiland commented 4 years ago

Community Note

Terraform (and AzureRM Provider) Version

Terraform v0.12.24

Affected Resource(s)

Terraform Configuration Files

resource "azurerm_network_watcher_flow_log" "flow-log-main" { count = length(var.region)

network_watcher_name = azurerm_network_watcher.my-nw[count.index].name resource_group_name = data.azurerm_resource_group.my-rg.name network_security_group_id = element(matchkeys(azurerm_network_security_group.my-nsg..id, azurerm_network_security_group.my-nsg..location, var.region), count.index) storage_account_id = azurerm_storage_account.nsg-storage[count.index].id enabled = true version = 2

retention_policy { enabled = true days = 30

} }

Debug Output

Error: Error disabling Flow Log Configuration for target "/subscriptions/xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/test-rg/providers/Microsoft.Network/networkSecurityGroups/my-main-nsg" (Network Watcher "NetworkWatcher_eastasia" / Resource Group "test-rg"): network.WatchersClient#SetFlowLogConfiguration: Invalid input: autorest/validation: validation failed: parameter=parameters.FlowAnalyticsConfiguration.NetworkWatcherFlowAnalyticsConfiguration constraint=Null value=(*network.TrafficAnalyticsConfigurationProperties)(nil) details: value cannot be null; required parameter

Expected Behavior

All NSG resources should be destroyed, including the NSG Flog Log configurations, even if Traffic Analytics is in a disabled state as configured by the Terraform code.

Actual Behavior

When destroying deployed TF resources, TF is trying to disable NSG Flow logs and expecting “Traffic Analytics” section in enabled mode. If "Traffic Analytics" is disabled, the destroy errors out and will not destroy the NSG resources.

Steps to Reproduce

  1. terraform apply
  2. terraform destroy

Important Factoids

When the following code to enable Traffic Analytics for the NSG Flow Logs is included, the destroy command works without issue.

traffic_analytics { enabled = true workspace_id = element(azurerm_log_analytics_workspace.my-workspace..workspace_id, count.index) workspace_region = element(azurerm_log_analytics_workspace.my-workspace..location, count.index) workspace_resource_id = element(azurerm_log_analytics_workspace.my-workspace.*.id, count.index) // interval_in_minutes = 60 } }

References

ghost commented 4 years ago

This has been released in version 2.15.0 of the provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. As an example:

provider "azurerm" {
    version = "~> 2.15.0"
}
# ... other configuration ...
ghost commented 4 years ago

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!