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

Upgrade network connection monitor from v1 to v2 #8640

Merged
merged 31 commits into from
Nov 10, 2020

Conversation

neil-yechenwei
Copy link
Contributor

@neil-yechenwei neil-yechenwei commented Sep 26, 2020

This PR is to fix below issues:

  1. fixes azurerm_network_connection_monitor Gets Recreated Every Run #3909 , as the resource azurerm_network_connection_monitor doesn't work anymore for id segment issue while deleting resource, so made this PR to update segment of resource id for network connection monitor.
  2. fixes azurerm_network_connection_monitor failed to create with properties source and destination in API version 2020-03-01 #7309 . Deprecate auto_start, interval_in_seconds, source and destination. These properties have been retired after version 2019-06-01.
  3. Add new properties endpoint, notes, test_configuration, test_group and output for new api version.

Note: Please merge PR 7349 first for connection monitor v1, and release a new azurerm provider version, then merge this PR for connection monitor v2.

Copy link
Collaborator

@magodo magodo left a comment

Choose a reason for hiding this comment

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

Thanks for this PR!
I've taken a look through and left some comments inline, but this is mostly looking good to me 👍

@neil-yechenwei neil-yechenwei requested a review from magodo October 27, 2020 08:38
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 for the PR @neil-yechenwei - i've given this a quick review and left comments inline that need to be asddressed

"address": {
Type: schema.TypeString,
Optional: true,
},
Copy link
Collaborator

Choose a reason for hiding this comment

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

could we validate this?

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


A `success_threshold` block supports the following:

* `checks_failed_percent` - (Optional) The maximum percentage of failed checks permitted for a test to evaluate as successful.
Copy link
Collaborator

Choose a reason for hiding this comment

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

grammer

Suggested change
* `checks_failed_percent` - (Optional) The maximum percentage of failed checks permitted for a test to evaluate as successful.
* `checks_failed_percent` - (Optional) The maximum percentage of failed checks permitted for a test to be successful.

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


* `checks_failed_percent` - (Optional) The maximum percentage of failed checks permitted for a test to evaluate as successful.

* `round_trip_time_ms` - (Optional) The maximum round-trip time in milliseconds permitted for a test to evaluate as successful.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
* `round_trip_time_ms` - (Optional) The maximum round-trip time in milliseconds permitted for a test to evaluate as successful.
* `round_trip_time_ms` - (Optional) The maximum round-trip time in milliseconds permitted for a test to be successful.

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


* `port` - (Required) The port to connect to.

* `disable_trace_route` - (Optional) Should path evaluation with trace route be disabled? Defaults to `false`.
Copy link
Collaborator

Choose a reason for hiding this comment

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

we always end with enabled/disabled

Suggested change
* `disable_trace_route` - (Optional) Should path evaluation with trace route be disabled? Defaults to `false`.
* `trace_route_disabled` - (Optional) Should path evaluation with trace route be disabled? Defaults to `false`.

or even change it to trace_route_enabled

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


* `name` - (Required) The name of the connection monitor test group.

* `destinations` - (Required) A list of destination endpoint names.
Copy link
Collaborator

Choose a reason for hiding this comment

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

would this be more clear as

Suggested change
* `destinations` - (Required) A list of destination endpoint names.
* `destination_endpoints` - (Required) A list of destination endpoint names.

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


A `icmp_configuration` block supports the following:

* `disable_trace_route` - (Optional) Will path evaluation with trace route be disabled? Defaults to `false`.
Copy link
Collaborator

Choose a reason for hiding this comment

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

we should always have disabled on the end of the property name

Suggested change
* `disable_trace_route` - (Optional) Will path evaluation with trace route be disabled? Defaults to `false`.
* `trace_route_disable` - (Optional) Will path evaluation with trace route be disabled? Defaults to `false`.

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

Copy link
Collaborator

@magodo magodo left a comment

Choose a reason for hiding this comment

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

@neil-yechenwei I have scanned through and left some comments inline. Once it is addressed, we can go on reviewing this PR.


connectionMonitor := NetworkConnectionMonitorId{
ResourceGroup: id.ResourceGroup,
WatcherId: strings.Split(input, "/connectionMonitors/")[0],
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we insist on using the id.Popsegment to do the id parsing?

Copy link
Contributor Author

@neil-yechenwei neil-yechenwei Nov 5, 2020

Choose a reason for hiding this comment

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

Here is the id of network watcher. So I assume we have to do this since id.Popsegment cannot expose it.


type NetworkConnectionMonitorId struct {
ResourceGroup string
WatcherId string
Copy link
Collaborator

Choose a reason for hiding this comment

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

Now that we have the WatcherName, we do we need to export this?

Copy link
Contributor Author

@neil-yechenwei neil-yechenwei Nov 5, 2020

Choose a reason for hiding this comment

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

Because we have to use it to set watcher id to state file.

d.Set("network_watcher_id", id.WatcherId)

Copy link
Collaborator

Choose a reason for hiding this comment

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

In this case, can we opt in ID formatter for the network watcher, and use the NewXXX() function in place where you need to set the network watcher id?

Example: https://github.com/magodo/terraform-provider-azurerm/blob/azurerm_vpn_gateway_connection/azurerm/internal/services/network/vpn_gateway_connection_resource.go#L373-L373

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks. updated

func NetworkConnectionMonitorHttpPath(v interface{}, k string) (warnings []string, errors []error) {
value := v.(string)

if !regexp.MustCompile(`^(/.*)?$`).MatchString(value) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we put more thoughts on the validation logic here? Otherwise, path like ////// is also a valid input?

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

@@ -10,61 +10,144 @@ description: |-

Manages a Network Connection Monitor.

~> **NOTE:** Any Network Connection Monitor resource created with API versions 2019-06-01 or earlier (v1) are now incompatible with terraform which now only supports v2.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
~> **NOTE:** Any Network Connection Monitor resource created with API versions 2019-06-01 or earlier (v1) are now incompatible with terraform which now only supports v2.
~> **NOTE:** Any Network Connection Monitor resource created with API versions 2019-06-01 or earlier (v1) are now incompatible with Terraform, which now only supports v2.

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


---

* `auto_start` - (Optional) Will the connection monitor start automatically once created? Changing this forces a new Network Connection Monitor to be created.
* `notes` - (Optional) Any notes about the Network Connection Monitor.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we modify this statement a bit?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This sentence is copied from existing resource.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Then could we fix this statement and apply the updated improved versinoit to where it was copied from?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure. Updated the description for this property. For the others, I will update them in another separate PR.

A `destination` block supports the following:
A `endpoint` block supports the following:

* `name` - (Required) The name of the connection monitor endpoint.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we capitalize the first letter of the resource type to be consistent (this applies to other parts)?

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


* `name` - (Required) The name of the connection monitor endpoint.

* `address` - (Optional) The address of the connection monitor endpoint (IP or domain name).
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
* `address` - (Optional) The address of the connection monitor endpoint (IP or domain name).
* `address` - (Optional) The IP address or domain name of the Network Connection Monitor endpoint.

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


* `filter` - (Optional) A `filter` block as defined below.

* `virtual_machine_id` - (Optional) The ID of the virtual machine which is used as the endpoint by connection monitor.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we capitalize the first letter of the resource type to be consistent?

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

A `source` block supports the following:
A `test_configuration` block supports the following:

* `name` - (Required) The name of the connection monitor test configuration.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we capitalize the first letter of the resource type to be consistent?

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


* `protocol` - (Required) The protocol used to evaluate tests. Possible values are `Tcp`, `Http` and `Icmp`.

* `test_frequency_iin_seconds` - (Optional) The frequency of test evaluation, in seconds. Defaults to `60`.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is double i here intended?

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

Copy link
Collaborator

@magodo magodo left a comment

Choose a reason for hiding this comment

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

@neil-yechenwei Thank you for the update, I left more comments inline, which shall be addressed.

Comment on lines 40 to 50
func (id NetworkWatcherId) ID(subscriptionId string) string {
return fmt.Sprintf("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Network/networkWatchers/%s",
subscriptionId, id.ResourceGroup, id.Name)
}

func NewNetworkWatcherID(resourceGroup, name string) NetworkWatcherId {
return NetworkWatcherId{
ResourceGroup: resourceGroup,
Name: name,
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we move these impl to network_watcher.go?

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

return warnings, errors
}

if !regexp.MustCompile(`^((/[^/]+)+[/]?|/)$`).MatchString(value) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm afraid this regexp is still error prone, is there any possiblity that we don't use regexp to validate a http path, but leverage some other parsing functions if any?

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

return warnings, errors
}

if !regexp.MustCompile(`^(([a-zA-Z]{1})|([a-zA-Z]{1}[a-zA-Z]{1})|([a-zA-Z]{1}[0-9]{1})|([0-9]{1}[a-zA-Z]{1})|([a-zA-Z0-9][a-zA-Z0-9-_]{1,61}[a-zA-Z0-9]))\.([a-zA-Z]{2,6}|[a-zA-Z0-9-]{2,30}\.[a-zA-Z
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you explain this complex regexp here? (some parts can be simplified by removing the {1})

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

return warnings, errors
}

if len(value) == 7 {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you add some comments to tell what the expected code range is?

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


* `interval_in_seconds` - (Optional) Monitoring interval in seconds.
* `output_workspace_resource_ids` - (Optional) A list of the Log Analytics Workspace id that should be used for producing output into a Log Analytics for the Network Connection Monitor.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
* `output_workspace_resource_ids` - (Optional) A list of the Log Analytics Workspace id that should be used for producing output into a Log Analytics for the Network Connection Monitor.
* `output_workspace_resource_ids` - (Optional) A list of IDs of the Log Analytics Workspace which will accept the output from the Network Connection Monitor.

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


* `method` - (Optional) The HTTP method for the HTTP request. Possible values are `Get` and `Post`. Defaults to `Get`.

* `port` - (Optional) The port for the Http connection.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we insist on using HTTP (all capitalized) all over the document to be consistent?

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


* `port` - (Optional) The port for the Http connection.

* `path` - (Optional) The path component of the URI. For instance, `/dir1/dir2`.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess there is no need to provide the example, as the path component of a URI is a well-known fact.

Suggested change
* `path` - (Optional) The path component of the URI. For instance, `/dir1/dir2`.
* `path` - (Optional) The path component of the URI.

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


A `icmp_configuration` block supports the following:

* `trace_route_disabled` - (Optional) Should path evaluation with trace route be disabled? Defaults to `false`.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we negate this to be trace_route_enabled, and change the logic to reflect this? Since it is more intuitive for users.

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


* `port` - (Required) The port for the Tcp connection.

* `trace_route_disabled` - (Optional) Should path evaluation with trace route be disabled? Defaults to `false`.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we negate this to be trace_route_enabled, and change the logic to reflect this? Since it is more intuitive for users.

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


* `virtual_machine_id` - (Required) The ID of the virtual machine used as the source by connection monitor.
* `test_configurations` - (Required) A list of test configuration names.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
* `test_configurations` - (Required) A list of test configuration names.
* `test_configuration_names` - (Required) A list of test configuration names.

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

@neil-yechenwei
Copy link
Contributor Author

@magodo & @katbyte , thanks for your comment. I've updated code.

@ghost ghost removed the waiting-response label Nov 6, 2020
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 @neil-yechenwei - LGTM 👍

@katbyte katbyte merged commit 57a17ff into hashicorp:master Nov 10, 2020
@katbyte katbyte added this to the v2.36.0 milestone Nov 10, 2020
katbyte added a commit that referenced this pull request Nov 10, 2020
@ghost
Copy link

ghost commented Nov 12, 2020

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

@ghost
Copy link

ghost commented Dec 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 Dec 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
3 participants