-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New resource -
azurerm_servicebus_namespace_network_rule_set
(#6379)
Introduces new resource azurerm_servicebus_namespace_network_rule_set Fixes #3930
- Loading branch information
1 parent
11db030
commit 50bb45e
Showing
13 changed files
with
987 additions
and
15 deletions.
There are no files selected for viewing
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,33 @@ | ||
package parse | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" | ||
) | ||
|
||
type ServiceBusNamespaceId struct { | ||
Name string | ||
ResourceGroup string | ||
} | ||
|
||
func ServiceBusNamespaceID(input string) (*ServiceBusNamespaceId, error) { | ||
id, err := azure.ParseAzureResourceID(input) | ||
if err != nil { | ||
return nil, fmt.Errorf("unable to parse Service Bus Namespace ID %q: %+v", input, err) | ||
} | ||
|
||
namespace := ServiceBusNamespaceId{ | ||
ResourceGroup: id.ResourceGroup, | ||
} | ||
|
||
if namespace.Name, err = id.PopSegment("namespaces"); err != nil { | ||
return nil, fmt.Errorf("unable to parse Service Bus Namespace ID %q: %+v", input, err) | ||
} | ||
|
||
if err := id.ValidateNoEmptySegments(input); err != nil { | ||
return nil, fmt.Errorf("unable to parse Service Bus Namespace ID %q: %+v", input, err) | ||
} | ||
|
||
return &namespace, nil | ||
} |
38 changes: 38 additions & 0 deletions
38
azurerm/internal/services/servicebus/parse/namespace_network_rule_set.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,38 @@ | ||
package parse | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" | ||
) | ||
|
||
type ServiceBusNamespaceNetworkRuleSetId struct { | ||
Name string | ||
NamespaceName string | ||
ResourceGroup string | ||
} | ||
|
||
func ServiceBusNamespaceNetworkRuleSetID(input string) (*ServiceBusNamespaceNetworkRuleSetId, error) { | ||
id, err := azure.ParseAzureResourceID(input) | ||
if err != nil { | ||
return nil, fmt.Errorf("unable to parse Service Bus Namespace Network Rule Set ID %q: %+v", input, err) | ||
} | ||
|
||
rule := ServiceBusNamespaceNetworkRuleSetId{ | ||
ResourceGroup: id.ResourceGroup, | ||
} | ||
|
||
if rule.Name, err = id.PopSegment("networkrulesets"); err != nil { | ||
return nil, fmt.Errorf("unable to parse Service Bus Namespace Network Rule Set ID %q: %+v", input, err) | ||
} | ||
|
||
if rule.NamespaceName, err = id.PopSegment("namespaces"); err != nil { | ||
return nil, fmt.Errorf("unable to parse Service Bus Namespace Network Rule Set ID %q: %+v", input, err) | ||
} | ||
|
||
if err := id.ValidateNoEmptySegments(input); err != nil { | ||
return nil, fmt.Errorf("unable to parse Service Bus Namespace Network Rule Set ID %q: %+v", input, err) | ||
} | ||
|
||
return &rule, nil | ||
} |
87 changes: 87 additions & 0 deletions
87
azurerm/internal/services/servicebus/parse/namespace_network_rule_set_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,87 @@ | ||
package parse | ||
|
||
import "testing" | ||
|
||
func TestServiceBusNamespaceNetworkRuleID(t *testing.T) { | ||
testData := []struct { | ||
Name string | ||
Input string | ||
Error bool | ||
Expected *ServiceBusNamespaceNetworkRuleSetId | ||
}{ | ||
{ | ||
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 Service Bus Namespace Name", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.ServiceBus/namespaces/", | ||
Error: true, | ||
}, | ||
{ | ||
Name: "Service Bus Namespace ID", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.ServiceBus/namespaces/namespace1", | ||
Error: true, | ||
}, | ||
{ | ||
Name: "Missing Network Rule Name", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.ServiceBus/namespaces/namespace1/networkrulesets/", | ||
Error: true, | ||
}, | ||
{ | ||
Name: "Service Bus Namespace Network Rule ID", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.ServiceBus/namespaces/namespace1/networkrulesets/default", | ||
Expected: &ServiceBusNamespaceNetworkRuleSetId{ | ||
Name: "default", | ||
NamespaceName: "namespace1", | ||
ResourceGroup: "resGroup1", | ||
}, | ||
}, | ||
{ | ||
Name: "Wrong casing", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.ServiceBus/Namespaces/namespace1", | ||
Error: true, | ||
}, | ||
} | ||
|
||
for _, v := range testData { | ||
t.Logf("[DEBUG] Testing %q", v.Name) | ||
|
||
actual, err := ServiceBusNamespaceNetworkRuleSetID(v.Input) | ||
if err != nil { | ||
if v.Error { | ||
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.NamespaceName != v.Expected.NamespaceName { | ||
t.Fatalf("Expected %q but got %q for Name", v.Expected.NamespaceName, actual.NamespaceName) | ||
} | ||
|
||
if actual.ResourceGroup != v.Expected.ResourceGroup { | ||
t.Fatalf("Expected %q but got %q for Resource Group", v.Expected.ResourceGroup, actual.ResourceGroup) | ||
} | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
azurerm/internal/services/servicebus/parse/namespace_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,74 @@ | ||
package parse | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestServiceBusNamespaceID(t *testing.T) { | ||
testData := []struct { | ||
Name string | ||
Input string | ||
Error bool | ||
Expected *ServiceBusNamespaceId | ||
}{ | ||
{ | ||
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 Service Bus Namespace Name", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.ServiceBus/namespaces/", | ||
Error: true, | ||
}, | ||
{ | ||
Name: "Service Bus Namespace ID", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.ServiceBus/namespaces/namespace1", | ||
Expected: &ServiceBusNamespaceId{ | ||
ResourceGroup: "resGroup1", | ||
Name: "namespace1", | ||
}, | ||
}, | ||
{ | ||
Name: "Wrong casing", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.ServiceBus/Namespaces/namespace1", | ||
Error: true, | ||
}, | ||
} | ||
|
||
for _, v := range testData { | ||
t.Logf("[DEBUG] Testing %q", v.Name) | ||
|
||
actual, err := ServiceBusNamespaceID(v.Input) | ||
if err != nil { | ||
if v.Error { | ||
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.ResourceGroup != v.Expected.ResourceGroup { | ||
t.Fatalf("Expected %q but got %q for Resource Group", v.Expected.ResourceGroup, actual.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
Oops, something went wrong.