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_network_watcher_flow_log: the name property can now be configured for new resources. #15016

Merged
merged 11 commits into from
Feb 9, 2022

Conversation

magodo
Copy link
Collaborator

@magodo magodo commented Jan 19, 2022

This PR expose the name for the azurerm_network_watcher_flow_log, as an enhancement after #12533. It is implemented in a backward compatible manner.
I've tested locally that I can import a flow log resource that is created without setting the name via either the old import format and the new import format, both has no plan diff.

Test Result

💤  TF_ACC=1 go test -v -timeout=20h ./internal/services/network  -run='TestAccNetworkWatcherFlowLog_'
=== RUN   TestAccNetworkWatcherFlowLog_basic
--- PASS: TestAccNetworkWatcherFlowLog_basic (186.91s)
=== RUN   TestAccNetworkWatcherFlowLog_basicWithName
--- PASS: TestAccNetworkWatcherFlowLog_basicWithName (113.57s)
=== RUN   TestAccNetworkWatcherFlowLog_disabled
--- PASS: TestAccNetworkWatcherFlowLog_disabled (172.85s)
=== RUN   TestAccNetworkWatcherFlowLog_reenabled
--- PASS: TestAccNetworkWatcherFlowLog_reenabled (857.81s)
=== RUN   TestAccNetworkWatcherFlowLog_retentionPolicy
--- PASS: TestAccNetworkWatcherFlowLog_retentionPolicy (248.87s)
=== RUN   TestAccNetworkWatcherFlowLog_updateStorageAccount
--- PASS: TestAccNetworkWatcherFlowLog_updateStorageAccount (282.49s)
=== RUN   TestAccNetworkWatcherFlowLog_trafficAnalytics
--- PASS: TestAccNetworkWatcherFlowLog_trafficAnalytics (284.03s)
=== RUN   TestAccNetworkWatcherFlowLog_longName
--- PASS: TestAccNetworkWatcherFlowLog_longName (186.87s)
=== RUN   TestAccNetworkWatcherFlowLog_longName_end_hyphen
    testcase.go:117: Step 1/2 error: Error running apply: exit status 1

        Error: creating/updating Network Security Group: (Name "acctestNSG01-" / Resource Group "acctestRG-watcher-01234567890123456789012345678902"): network.SecurityGroupsClient#CreateOrUpdate: Failure sending request: StatusCode=400 -- Original Error: Code="InvalidResourceName" Message="Resource name acctestNSG01- is invalid. The name can be up to 80 characters long. It must begin with a word character, and it must end with a word character or with '_'. The name may contain word characters or '.', '-', '_'." Details=[]

          with azurerm_network_security_group.test,
          on terraform_plugin_test.tf line 12, in resource "azurerm_network_security_group" "test":
          12: resource "azurerm_network_security_group" "test" {

--- FAIL: TestAccNetworkWatcherFlowLog_longName_end_hyphen (131.82s)
=== RUN   TestAccNetworkWatcherFlowLog_version
--- PASS: TestAccNetworkWatcherFlowLog_version (213.48s)
=== RUN   TestAccNetworkWatcherFlowLog_location
--- PASS: TestAccNetworkWatcherFlowLog_location (180.27s)
=== RUN   TestAccNetworkWatcherFlowLog_tags
--- PASS: TestAccNetworkWatcherFlowLog_tags (156.05s)
FAIL
FAIL    github.com/hashicorp/terraform-provider-azurerm/internal/services/network       3015.023s
FAIL

The only failed test is due to that the NSG API now treat a name with an ending dash an invalid name, therefore, this PR has removed that test.

Comment on lines 185 to 186
id := parse.NewFlowLogID(subscriptionId, resourceGroupName, networkWatcherName, *nsgId)

locks.ByID(nsgId.ID())
defer locks.UnlockByID(nsgId.ID())
id := parse.NewFlowLogIDShim(subscriptionId, resourceGroupName, networkWatcherName, d.Get("name").(string), *nsgId)
Copy link
Collaborator

Choose a reason for hiding this comment

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

how come we are removing the lock?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sorry for that, I've added them back.
Besides, do you think we should support the way how to import the resource backward compatibly? Or I should just add a ID migration and use the new way to import only?

Copy link
Collaborator

Choose a reason for hiding this comment

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

we'll need to do a state migration, could you update this PR with the new 3.0 beta "this is for good" flag so this can be included in the beta?

@magodo
Copy link
Collaborator Author

magodo commented Feb 7, 2022

@katbyte
I've updated the PR to make the name being required for newly created resources, which IMO is more user-friendly and consistent behavior in the provider wide, comparing to automatically generate the name for the users.
Meanwhile, the schema of the name is still marked as optional & computed for those existing TF configs with the flow log created to further manage them, for backward compatibility.
Therefore, I've modified all the test cases to add the name, also removed the two test cases related to verify the auto-generated names and the truncation behavior, as the new resources are required to specify the name. Also, I've locally validated the state migration, i.e. using the old provider to provision a flow log, and use the new provider to plan, which is expected to be of no diff.

Please see whether it makes sense, thank you!

💤  TF_ACC=1 go test -v -timeout=20h ./internal/services/network -run='TestAccNetworkWatcherFlowLog_'
=== RUN   TestAccNetworkWatcherFlowLog_basic
--- PASS: TestAccNetworkWatcherFlowLog_basic (189.14s)
=== RUN   TestAccNetworkWatcherFlowLog_requiresImport
--- PASS: TestAccNetworkWatcherFlowLog_requiresImport (190.40s)
=== RUN   TestAccNetworkWatcherFlowLog_disabled
--- PASS: TestAccNetworkWatcherFlowLog_disabled (127.55s)
=== RUN   TestAccNetworkWatcherFlowLog_reenabled
--- PASS: TestAccNetworkWatcherFlowLog_reenabled (210.11s)
=== RUN   TestAccNetworkWatcherFlowLog_retentionPolicy
--- PASS: TestAccNetworkWatcherFlowLog_retentionPolicy (151.02s)
=== RUN   TestAccNetworkWatcherFlowLog_updateStorageAccount
--- PASS: TestAccNetworkWatcherFlowLog_updateStorageAccount (259.72s)
=== RUN   TestAccNetworkWatcherFlowLog_trafficAnalytics
--- PASS: TestAccNetworkWatcherFlowLog_trafficAnalytics (326.26s)
=== RUN   TestAccNetworkWatcherFlowLog_version
--- PASS: TestAccNetworkWatcherFlowLog_version (839.23s)
=== RUN   TestAccNetworkWatcherFlowLog_location
--- PASS: TestAccNetworkWatcherFlowLog_location (223.67s)
=== RUN   TestAccNetworkWatcherFlowLog_tags
--- PASS: TestAccNetworkWatcherFlowLog_tags (227.80s)
PASS
ok      github.com/hashicorp/terraform-provider-azurerm/internal/services/network       2744.944s

@katbyte katbyte changed the title azurerm_network_watcher_flow_log: add supports of name azurerm_network_watcher_flow_log: the name property can now be configured for new resources. Feb 9, 2022
Copy link
Collaborator

@katbyte katbyte left a comment

Choose a reason for hiding this comment

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

Thanks @magodo - much more elegant solution! LGTM 🔥

@katbyte katbyte merged commit 59e5eee into hashicorp:main Feb 9, 2022
@github-actions github-actions bot added this to the v2.96.0 milestone Feb 9, 2022
katbyte added a commit that referenced this pull request Feb 9, 2022
@github-actions
Copy link

This functionality has been released in v2.96.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 pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, 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 Mar 14, 2022
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.

2 participants