-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Changes from 29 commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
d9cca21
Upgrade network connection monitor from v1 to v2
e5b46a5
Update code
0677841
Update code
1beb4c4
Merge remote-tracking branch 'upstream/master' into upgradeconnmonitor
6a0ab68
Update code
0e1e469
Update code
efaa286
Update code
dfd03eb
Update code
4c927c5
Update code
105bee9
Update code
894637a
Update code
37b117c
Update code
7fdd98a
Update code
f8ec59d
update code
b57ce1d
update code
877bcd8
Update code
005cb8b
Update code
5ecfd42
update code
34509f5
update code
cd54db5
update code
2755fa8
Merge remote-tracking branch 'upstream/master' into upgradeconnmonitor
3dfa0a0
update code
9ba887b
update code
863b990
update code
793be22
update code
71d7e50
update code
2919454
update code
e3400ff
update doc
5630be3
update doc
45d9b5f
update code
596341f
upadate test
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
964 changes: 859 additions & 105 deletions
964
azurerm/internal/services/network/network_connection_monitor_resource.go
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
azurerm/internal/services/network/parse/network_connection_monitor.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package parse | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" | ||
) | ||
|
||
type NetworkConnectionMonitorId struct { | ||
ResourceGroup string | ||
WatcherName string | ||
Name string | ||
} | ||
|
||
func NetworkConnectionMonitorID(input string) (*NetworkConnectionMonitorId, error) { | ||
id, err := azure.ParseAzureResourceID(input) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
connectionMonitor := NetworkConnectionMonitorId{ | ||
ResourceGroup: id.ResourceGroup, | ||
} | ||
|
||
if connectionMonitor.WatcherName, err = id.PopSegment("networkWatchers"); err != nil { | ||
return nil, err | ||
} | ||
|
||
if connectionMonitor.Name, err = id.PopSegment("connectionMonitors"); err != nil { | ||
return nil, err | ||
} | ||
|
||
if err := id.ValidateNoEmptySegments(input); err != nil { | ||
return nil, err | ||
} | ||
|
||
return &connectionMonitor, nil | ||
} | ||
|
||
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, | ||
} | ||
} | ||
104 changes: 104 additions & 0 deletions
104
azurerm/internal/services/network/parse/network_connection_monitor_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
package parse | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/resourceid" | ||
) | ||
|
||
var _ resourceid.Formatter = NetworkWatcherId{} | ||
|
||
func TestNetworkWatcherIDFormatter(t *testing.T) { | ||
subscriptionId := "12345678-1234-5678-1234-123456789012" | ||
actual := NewNetworkWatcherID("group1", "watcher1").ID(subscriptionId) | ||
expected := "/subscriptions/12345678-1234-5678-1234-123456789012/resourceGroups/group1/providers/Microsoft.Network/networkWatchers/watcher1" | ||
|
||
if actual != expected { | ||
t.Fatalf("Expected %q but got %q", expected, actual) | ||
} | ||
} | ||
|
||
func TestNetworkConnectionMonitorID(t *testing.T) { | ||
testData := []struct { | ||
Name string | ||
Input string | ||
Error bool | ||
Expect *NetworkConnectionMonitorId | ||
}{ | ||
{ | ||
Name: "Empty", | ||
Input: "", | ||
Error: true, | ||
}, | ||
{ | ||
Name: "No Resource Groups Segment", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000", | ||
Error: true, | ||
}, | ||
{ | ||
Name: "No Resource Groups Value", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/", | ||
Error: true, | ||
}, | ||
{ | ||
Name: "Resource Group ID", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/foo/", | ||
Error: true, | ||
}, | ||
{ | ||
Name: "Missing Network Watcher Key", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.Network/networkWatchers/", | ||
Error: true, | ||
}, | ||
{ | ||
Name: "Missing Network Watcher Value", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.Network/networkWatchers/watcher1", | ||
Error: true, | ||
}, | ||
{ | ||
Name: "Missing Network Connection Monitor Key", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.Network/networkWatchers/watcher1/connectionMonitors", | ||
Error: true, | ||
}, | ||
{ | ||
Name: "Namespace Network Connection Monitor Value", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.Network/networkWatchers/watcher1/connectionMonitors/connectionMonitor1", | ||
Error: false, | ||
Expect: &NetworkConnectionMonitorId{ | ||
ResourceGroup: "group1", | ||
WatcherName: "watcher1", | ||
Name: "connectionMonitor1", | ||
}, | ||
}, | ||
{ | ||
Name: "Wrong Segment", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.Network/networkWatchers/watcher1/NetworkConnectionMonitors/connectionMonitor1", | ||
Error: true, | ||
}, | ||
} | ||
|
||
for _, v := range testData { | ||
t.Logf("[DEBUG] Testing %q", v.Name) | ||
|
||
actual, err := NetworkConnectionMonitorID(v.Input) | ||
if err != nil { | ||
if v.Error { | ||
continue | ||
} | ||
|
||
t.Fatalf("Expected a value but got an error: %s", err) | ||
} | ||
|
||
if actual.Name != v.Expect.Name { | ||
t.Fatalf("Expected %q but got %q for Name", v.Expect.Name, actual.Name) | ||
} | ||
|
||
if actual.WatcherName != v.Expect.WatcherName { | ||
t.Fatalf("Expected %q but got %q for Name", v.Expect.WatcherName, actual.WatcherName) | ||
} | ||
|
||
if actual.ResourceGroup != v.Expect.ResourceGroup { | ||
t.Fatalf("Expected %q but got %q for Resource Group", v.Expect.ResourceGroup, actual.ResourceGroup) | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
azurerm/internal/services/network/parse/network_watcher.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package parse | ||
|
||
import "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" | ||
|
||
type NetworkWatcherId struct { | ||
ResourceGroup string | ||
Name string | ||
} | ||
|
||
func NetworkWatcherID(input string) (*NetworkWatcherId, error) { | ||
id, err := azure.ParseAzureResourceID(input) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
watcher := NetworkWatcherId{ | ||
ResourceGroup: id.ResourceGroup, | ||
} | ||
|
||
if watcher.Name, err = id.PopSegment("networkWatchers"); err != nil { | ||
return nil, err | ||
} | ||
|
||
if err := id.ValidateNoEmptySegments(input); err != nil { | ||
return nil, err | ||
} | ||
|
||
return &watcher, nil | ||
} |
69 changes: 69 additions & 0 deletions
69
azurerm/internal/services/network/parse/network_watcher_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package parse | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestNetworkWatcherID(t *testing.T) { | ||
testData := []struct { | ||
Name string | ||
Input string | ||
Error bool | ||
Expect *NetworkWatcherId | ||
}{ | ||
{ | ||
Name: "Empty", | ||
Input: "", | ||
Error: true, | ||
}, | ||
{ | ||
Name: "No Resource Groups Segment", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000", | ||
Error: true, | ||
}, | ||
{ | ||
Name: "No Resource Groups Value", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/", | ||
Error: true, | ||
}, | ||
{ | ||
Name: "Resource Group ID", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/foo/", | ||
Error: true, | ||
}, | ||
{ | ||
Name: "Missing Network Watcher Key", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.Network/networkWatchers/", | ||
Error: true, | ||
}, | ||
{ | ||
Name: "Missing Network Watcher Value", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.Network/networkWatchers/watcher1", | ||
Expect: &NetworkWatcherId{ | ||
ResourceGroup: "group1", | ||
Name: "watcher1", | ||
}, | ||
}, | ||
} | ||
|
||
for _, v := range testData { | ||
t.Logf("[DEBUG] Testing %q", v.Name) | ||
|
||
actual, err := NetworkWatcherID(v.Input) | ||
if err != nil { | ||
if v.Error { | ||
continue | ||
} | ||
|
||
t.Fatalf("Expected a value but got an error: %s", err) | ||
} | ||
|
||
if actual.Name != v.Expect.Name { | ||
t.Fatalf("Expected %q but got %q for Name", v.Expect.Name, actual.Name) | ||
} | ||
|
||
if actual.ResourceGroup != v.Expect.ResourceGroup { | ||
t.Fatalf("Expected %q but got %q for Resource Group", v.Expect.ResourceGroup, actual.ResourceGroup) | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated