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.46k stars 4.54k forks source link

Cant import existing network watcher flow log #15777

Closed AgueroPefai closed 2 years ago

AgueroPefai commented 2 years ago

Community Note

Terraform (and AzureRM Provider) Version

Terraform v1.1.7 on darwin_amd64

Affected Resource(s)

Terraform Configuration Files

resource "azurerm_network_watcher_flow_log" "test" {

network_watcher_name = "NetworkWatcher_canadacentral" resource_group_name = "NetworkWatcherRG"

network_security_group_id = azurerm_network_security_group.nsg.id storage_account_id = azurerm_storage_account.storageaccount["OTHER"].id enabled = true

retention_policy { enabled = true days = 90 }

traffic_analytics { enabled = true workspace_id = azurerm_log_analytics_workspace.law.workspace_id workspace_region = azurerm_log_analytics_workspace.law.location workspace_resource_id = azurerm_log_analytics_workspace.law.id interval_in_minutes = 10 } }

# Copy-paste your Terraform configurations here - for large Terraform configs,
# please use a service like Dropbox and share a link to the ZIP file. For
# security, you can also encrypt the files using our GPG public key: https://keybase.io/hashicorp

Debug Output

N/A

Panic Output

N/A

Expected Behaviour

The resource should have been imported.

Actual Behaviour

terraform import azurerm_network_watcher_flow_log.test $flowlog.id
azurerm_network_watcher_flow_log.anw_flg_v2_cmn_alt: Importing from ID "/subscriptions/xxxxxxxxx/resourceGroups/NetworkWatcherRG/providers/Microsoft.Network/networkWatchers/NetworkWatcher_canadacentral/flowLogs/verylargenameofnsg"... ╷ │ Error: parsing Resource ID "/subscriptions/xxxxxxxxxxxx/resourceGroups/NetworkWatcherRG/providers/Microsoft.Network/networkWatchers/NetworkWatcher_canadacentral/flowLogs/verylargenameofnsg": Error: Network Watcher Flow Log ID could not be split on /networkSecurityGroupId: /subscriptions/xxxxxxxx/resourceGroups/NetworkWatcherRG/providers/Microsoft.Network/networkWatchers/NetworkWatcher_canadacentral/flowLogs/verylargenameofnsg

Steps to Reproduce

  1. Have a large name of nsg flow log that is created automaticaly in portal, and try to import it.

Important Factoids

N/A

References

N/A

magodo commented 2 years ago

@AgueroPefai As you are using the provider prior to v2.96.0, you'll need to import the flow log via following format:

terraform import azurerm_network_watcher_flow_log.watcher1 /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mygroup1/providers/Microsoft.Network/networkWatchers/watcher1/networkSecurityGroupId/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mygroup1/providers/Microsoft.Network/networkSecurityGroups/group1

While this way has issue when you have a long name.

Alternatively, you can upgrade your provider version to v2.96.0 or later, then you can import the resource in form of:

terraform import azurerm_network_watcher_flow_log.watcher1 /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mygroup1/providers/Microsoft.Network/networkWatchers/watcher1/flowLogs/log1
AgueroPefai commented 2 years ago

Got it!. Let me try it out!

tombuildsstuff commented 2 years ago

Closing since out since we've not heard back here - if this is still AN ISSUE then please let us know and we can take another look.

github-actions[bot] commented 2 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 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.