-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
network: reverting the locking changes from #3673
- Loading branch information
1 parent
1d1d696
commit 2df3b8a
Showing
7 changed files
with
279 additions
and
6 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
azurerm/internal/services/network/network_security_group.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,31 @@ | ||
package network | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" | ||
) | ||
|
||
type NetworkSecurityGroupResourceID struct { | ||
Base azure.ResourceID | ||
|
||
Name string | ||
} | ||
|
||
func ParseNetworkSecurityGroupResourceID(input string) (*NetworkSecurityGroupResourceID, error) { | ||
id, err := azure.ParseAzureResourceID(input) | ||
if err != nil { | ||
return nil, fmt.Errorf("[ERROR] Unable to parse Network Security Group ID %q: %+v", input, err) | ||
} | ||
|
||
routeTable := NetworkSecurityGroupResourceID{ | ||
Base: *id, | ||
Name: id.Path["networkSecurityGroups"], | ||
} | ||
|
||
if routeTable.Name == "" { | ||
return nil, fmt.Errorf("ID was missing the `networkSecurityGroups` element") | ||
} | ||
|
||
return &routeTable, nil | ||
} |
62 changes: 62 additions & 0 deletions
62
azurerm/internal/services/network/network_security_group_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,62 @@ | ||
package network | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" | ||
) | ||
|
||
func TestParseNetworkSecurityGroup(t *testing.T) { | ||
testData := []struct { | ||
Name string | ||
Input string | ||
Expected *RouteTableResourceID | ||
}{ | ||
{ | ||
Name: "Empty", | ||
Input: "", | ||
Expected: nil, | ||
}, | ||
{ | ||
Name: "No Network Security Groups Segment", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/foo", | ||
Expected: nil, | ||
}, | ||
{ | ||
Name: "No Network Security Groups Value", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/foo/networkSecurityGroups/", | ||
Expected: nil, | ||
}, | ||
{ | ||
Name: "Completed", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/foo/networkSecurityGroups/example", | ||
Expected: &RouteTableResourceID{ | ||
Name: "example", | ||
Base: azure.ResourceID{ | ||
ResourceGroup: "foo", | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
for _, v := range testData { | ||
t.Logf("[DEBUG] Testing %q", v.Name) | ||
|
||
actual, err := ParseNetworkSecurityGroupResourceID(v.Input) | ||
if err != nil { | ||
if v.Expected == nil { | ||
continue | ||
} | ||
|
||
t.Fatalf("Expected a value but got an error: %s", err) | ||
} | ||
|
||
if actual.Name != v.Expected.Name { | ||
t.Fatalf("Expected %q but got %q for Name", v.Expected.Name, actual.Name) | ||
} | ||
|
||
if actual.Base.ResourceGroup != v.Expected.Base.ResourceGroup { | ||
t.Fatalf("Expected %q but got %q for ResourceGroup", v.Expected.Base.ResourceGroup, actual.Base.ResourceGroup) | ||
} | ||
} | ||
} |
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,34 @@ | ||
package network | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" | ||
) | ||
|
||
// NOTE: there's some nice things we can do with this around validation | ||
// since these top level objects exist | ||
|
||
type RouteTableResourceID struct { | ||
Base azure.ResourceID | ||
|
||
Name string | ||
} | ||
|
||
func ParseRouteTableResourceID(input string) (*RouteTableResourceID, error) { | ||
id, err := azure.ParseAzureResourceID(input) | ||
if err != nil { | ||
return nil, fmt.Errorf("[ERROR] Unable to parse Route Table ID %q: %+v", input, err) | ||
} | ||
|
||
routeTable := RouteTableResourceID{ | ||
Base: *id, | ||
Name: id.Path["routeTables"], | ||
} | ||
|
||
if routeTable.Name == "" { | ||
return nil, fmt.Errorf("ID was missing the `routeTables` element") | ||
} | ||
|
||
return &routeTable, nil | ||
} |
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,62 @@ | ||
package network | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" | ||
) | ||
|
||
func TestParseRouteTable(t *testing.T) { | ||
testData := []struct { | ||
Name string | ||
Input string | ||
Expected *RouteTableResourceID | ||
}{ | ||
{ | ||
Name: "Empty", | ||
Input: "", | ||
Expected: nil, | ||
}, | ||
{ | ||
Name: "No Route Table Segment", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/foo", | ||
Expected: nil, | ||
}, | ||
{ | ||
Name: "No Route Table Value", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/foo/routeTables/", | ||
Expected: nil, | ||
}, | ||
{ | ||
Name: "Completed", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/foo/routeTables/example", | ||
Expected: &RouteTableResourceID{ | ||
Name: "example", | ||
Base: azure.ResourceID{ | ||
ResourceGroup: "foo", | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
for _, v := range testData { | ||
t.Logf("[DEBUG] Testing %q", v.Name) | ||
|
||
actual, err := ParseRouteTableResourceID(v.Input) | ||
if err != nil { | ||
if v.Expected == nil { | ||
continue | ||
} | ||
|
||
t.Fatalf("Expected a value but got an error: %s", err) | ||
} | ||
|
||
if actual.Name != v.Expected.Name { | ||
t.Fatalf("Expected %q but got %q for Name", v.Expected.Name, actual.Name) | ||
} | ||
|
||
if actual.Base.ResourceGroup != v.Expected.Base.ResourceGroup { | ||
t.Fatalf("Expected %q but got %q for ResourceGroup", v.Expected.Base.ResourceGroup, actual.Base.ResourceGroup) | ||
} | ||
} | ||
} |
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
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
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