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

Update segment of resource id for network packet capture #8167

Merged
merged 7 commits into from
Sep 11, 2020

Conversation

neil-yechenwei
Copy link
Contributor

@neil-yechenwei neil-yechenwei commented Aug 19, 2020

As this resource cannot be deleted anymore for incorrect resource id segment issue, so we have to update segment of resource id here for this resource.

--- PASS: TestAccAzureRMNetworkWatcher/PacketCapture (1924.64s)
--- PASS: TestAccAzureRMNetworkWatcher/PacketCapture/localDisk (453.99s)
--- PASS: TestAccAzureRMNetworkWatcher/PacketCapture/storageAccount (504.75s)
--- PASS: TestAccAzureRMNetworkWatcher/PacketCapture/storageAccountAndLocalDisk (446.00s)
--- PASS: TestAccAzureRMNetworkWatcher/PacketCapture/withFilters (519.90s)
--- PASS: TestAccAzureRMNetworkWatcher/PacketCapture/requiresImport (532.44s)

@ghost ghost added the size/XS label Aug 19, 2020
@neil-yechenwei neil-yechenwei changed the title Fix test case for network packet capture Update segment of resource id for network packet capture Aug 19, 2020
Copy link
Member

@mbfrahry mbfrahry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should check both the old and the new path in case users still have the old path.

@neil-yechenwei
Copy link
Contributor Author

neil-yechenwei commented Aug 19, 2020

@mbfrahry, it's not appropriate for this case. Because the segment of resource id of the 2018-08-01 version terraform initially used is also updated to "packetCaptures". So I think this issue would also happen on older version. After tested with old version, this issue also happened. So I assume we don't need to be aware of compatible problem for this case. Based on above conclusion, I assume all users are blocked on all released azurerm provider versions now.

@neil-yechenwei
Copy link
Contributor Author

neil-yechenwei commented Aug 20, 2020

@tombuildsstuff ,@mbfrahry, although it's a breaking change, but I assume all users are blocked now by this issue on all released azurerm provider versions. Could we merge it to unblock users first?

Copy link
Contributor

@tombuildsstuff tombuildsstuff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi @neil-yechenwei

Taking a look though here unfortunately this would be a breaking change for existing users - as such we'll need to add a state migration to update these ID's to the new format here.

Thanks!

@@ -217,7 +217,7 @@ func resourceArmNetworkPacketCaptureRead(d *schema.ResourceData, meta interface{

resourceGroup := id.ResourceGroup
watcherName := id.Path["networkWatchers"]
name := id.Path["NetworkPacketCaptures"]
name := id.Path["packetCaptures"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unfortunately where this will be different for older resources we'd need to add a state migration to update this ID - as-is this is a breaking change

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated code

@@ -266,7 +266,7 @@ func resourceArmNetworkPacketCaptureDelete(d *schema.ResourceData, meta interfac

resourceGroup := id.ResourceGroup
watcherName := id.Path["networkWatchers"]
name := id.Path["NetworkPacketCaptures"]
name := id.Path["packetCaptures"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unfortunately where this will be different for older resources we'd need to add a state migration to update this ID - as-is this is a breaking change

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated code

@ghost ghost added size/L and removed size/XS labels Aug 21, 2020
@neil-yechenwei
Copy link
Contributor Author

neil-yechenwei commented Aug 21, 2020

@tombuildsstuff , thanks for the comment. I've updated code to use MigrateState. After used MigrateState, I assume this PR doesn't belong to "breaking-change", right?

Copy link
Contributor

@tombuildsstuff tombuildsstuff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we can confirm the state migration works then this otherwise LGTM 👍


log.Printf("[DEBUG] ARM Network Packet Capture before Migration: %#v", is.Attributes)

newID := strings.Replace(is.Attributes["id"], "/NetworkPacketCaptures/", "/packetCaptures/", 1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you confirm this migration works correctly when provisioning a resource using 2.0.0 -> that then shows no diff using tis branch?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tombuildsstuff , yes. I tested the scenario you mentioned and it works fine.
The scenario:

  1. Create Network Packet Captures with 2.0.0 (Also tried 1.27.0)
  2. Run tf plan with this branch
  3. There is no diff.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @neil-yechenwei - Can you post the manual test results / output here? (Ideally with an apply rather than a plan as this will actually update the state and exercise the code.).

Thanks

Copy link
Contributor Author

@neil-yechenwei neil-yechenwei Sep 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jackofallops , sure.

  1. Run tf apply to create Network Packet Capture with provider.azurerm v2.0.0 (I have to manually update the name segment to "NetworkPacketCaptures" since the name segment in all api versions has been updated to "packetCaptures" such as api version 2018-08-01. So we cannot get old value anymore.)
azurerm_network_packet_capture.test: Creation complete after 16s [id=/subscriptions/xx-xx-xx-xx/resourceGroups/acctestRG-watcher-test01/providers/Microsoft.Network/networkWatchers/acctestnw-test01/NetworkPacketCaptures/acctestpc-test02]

image
2. Switch provider.azurerm from v2.0.0 to this branch
3. Run tf plan

azurerm_network_packet_capture.test: Refreshing state... [id=/subscriptions/xx-xx-xx-xx/resourceGroups/acctestRG-watcher-test01/providers/Microsoft.Network/networkWatchers/acctestnw-test01/packetCaptures/acctestpc-test02]

image
4. Run tf apply

azurerm_network_packet_capture.test: Refreshing state... [id=/subscriptions/xx-x-xx-xx/resourceGroups/acctestRG-watcher-test01/providers/Microsoft.Network/networkWatchers/acctestnw-test01/packetCaptures/acctestpc-test02]

image
5. Update the name of network packet capture in tfconfig. (I cannot test update scenario since this resource doesn't support update operation.)
6. Run tf apply

azurerm_network_packet_capture.test: Creation complete after 5s [id=/subscriptions/xx-xx-xx-xxx/resourceGroups/acctestRG-watcher-test01/providers/Microsoft.Network/networkWatchers/acctestnw-test01/packetCaptures/acctestpc-test03]

image
7. Run tf plan

azurerm_network_packet_capture.test: Refreshing state... [id=/subscriptions/xx-xx-xx-xx/resourceGroups/acctestRG-watcher-test01/providers/Microsoft.Network/networkWatchers/acctestnw-test01/packetCaptures/acctestpc-test03]

image
8. Run tf destroy

azurerm_network_packet_capture.test: Destroying... [id=/subscriptions/xx-x-x-xx/resourceGroups/acctestRG-watcher-test01/providers/Microsoft.Network/networkWatchers/acctestnw-test01/packetCaptures/acctestpc-test03]
azurerm_network_packet_capture.test: Destruction complete after 2s

image

@WodansSon WodansSon added this to the v2.27.0 milestone Sep 4, 2020
@jackofallops jackofallops modified the milestones: v2.27.0, v2.28.0 Sep 10, 2020
@neil-yechenwei
Copy link
Contributor Author

@jackofallops , thanks for your comments. I've posted manual test results. Please have a look. Thanks.

@ghost ghost added size/XL and removed size/L labels Sep 11, 2020
Copy link
Member

@jackofallops jackofallops left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @neil-yechenwei, this LGTM now 👍

@jackofallops jackofallops dismissed stale reviews from mbfrahry and tombuildsstuff September 11, 2020 06:26

outdated

@jackofallops jackofallops merged commit bbaa762 into hashicorp:master Sep 11, 2020
jackofallops added a commit that referenced this pull request Sep 11, 2020
@ghost
Copy link

ghost commented Sep 17, 2020

This has been released in version 2.28.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.28.0"
}
# ... other configuration ...

@ghost
Copy link

ghost commented Oct 11, 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 👉 [email protected]. Thanks!

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

Successfully merging this pull request may close these issues.

5 participants