Skip to content

Commit b1fcd20

Browse files
katbytetombuildsstuff
authored andcommitted
New Resource - resource_arm_servicebus_queue_authorization_rule (#1543)
New Resource - azurerm_servicebus_queue_authorization_rule
1 parent 8c4ab9d commit b1fcd20

15 files changed

+657
-366
lines changed

azurerm/helpers/azure/servicebus.go

+75
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,20 @@ func ValidateServiceBusNamespaceName() schema.SchemaValidateFunc {
1919
)
2020
}
2121

22+
func ValidateServiceBusQueueName() schema.SchemaValidateFunc {
23+
return validation.StringMatch(
24+
regexp.MustCompile(`^[a-zA-Z0-9][\w-./~]{0,258}([a-zA-Z0-9])?$`),
25+
"The topic name can contain only letters, numbers, periods, hyphens, tildas, forward slashes and underscores. The namespace must start and end with a letter or number and be less then 260 characters long.",
26+
)
27+
}
28+
29+
func ValidateServiceBusSubscriptionName() schema.SchemaValidateFunc {
30+
return validation.StringMatch(
31+
regexp.MustCompile("^[a-zA-Z][-._a-zA-Z0-9]{0,48}([a-zA-Z0-9])?$"),
32+
"The name can contain only letters, numbers, periods, hyphens and underscores. The name must start and end with a letter or number and be less then 50 characters long.",
33+
)
34+
}
35+
2236
func ValidateServiceBusTopicName() schema.SchemaValidateFunc {
2337
return validation.StringMatch(
2438
regexp.MustCompile("^[a-zA-Z][-._a-zA-Z0-9]{0,258}([a-zA-Z0-9])?$"),
@@ -73,6 +87,67 @@ func FlattenServiceBusAuthorizationRuleRights(rights *[]servicebus.AccessRights)
7387
}
7488

7589
//shared schema
90+
func MergeSchema(a map[string]*schema.Schema, b map[string]*schema.Schema) map[string]*schema.Schema {
91+
s := map[string]*schema.Schema{}
92+
93+
for k, v := range a {
94+
s[k] = v
95+
}
96+
97+
for k, v := range b {
98+
s[k] = v
99+
}
100+
101+
return s
102+
}
103+
104+
func ServiceBusAuthorizationRuleSchemaFrom(s map[string]*schema.Schema) map[string]*schema.Schema {
105+
106+
authSchema := map[string]*schema.Schema{
107+
"listen": {
108+
Type: schema.TypeBool,
109+
Optional: true,
110+
Default: false,
111+
},
112+
113+
"send": {
114+
Type: schema.TypeBool,
115+
Optional: true,
116+
Default: false,
117+
},
118+
119+
"manage": {
120+
Type: schema.TypeBool,
121+
Optional: true,
122+
Default: false,
123+
},
124+
125+
"primary_key": {
126+
Type: schema.TypeString,
127+
Computed: true,
128+
Sensitive: true,
129+
},
130+
131+
"primary_connection_string": {
132+
Type: schema.TypeString,
133+
Computed: true,
134+
Sensitive: true,
135+
},
136+
137+
"secondary_key": {
138+
Type: schema.TypeString,
139+
Computed: true,
140+
Sensitive: true,
141+
},
142+
143+
"secondary_connection_string": {
144+
Type: schema.TypeString,
145+
Computed: true,
146+
Sensitive: true,
147+
},
148+
}
149+
return MergeSchema(s, authSchema)
150+
}
76151

77152
func ServiceBusAuthorizationRuleCustomizeDiff(d *schema.ResourceDiff, _ interface{}) error {
78153
listen, hasListen := d.GetOk("listen")

azurerm/import_arm_servicebus_topic_authorization_rule_test.go

-104
This file was deleted.

azurerm/provider.go

+1
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ func Provider() terraform.ResourceProvider {
207207
"azurerm_servicebus_namespace": resourceArmServiceBusNamespace(),
208208
"azurerm_servicebus_namespace_authorization_rule": resourceArmServiceBusNamespaceAuthorizationRule(),
209209
"azurerm_servicebus_queue": resourceArmServiceBusQueue(),
210+
"azurerm_servicebus_queue_authorization_rule": resourceArmServiceBusQueueAuthorizationRule(),
210211
"azurerm_servicebus_subscription": resourceArmServiceBusSubscription(),
211212
"azurerm_servicebus_subscription_rule": resourceArmServiceBusSubscriptionRule(),
212213
"azurerm_servicebus_topic": resourceArmServiceBusTopic(),

azurerm/resource_arm_servicebus_namespace_authorization_rule.go

+3-48
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@ import (
1010
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
1111
)
1212

13-
func resourceArmServiceAuthRuleSchemaFrom(schema map[string]*schema.Schema) map[string]*schema.Schema {
14-
return schema
15-
}
16-
1713
func resourceArmServiceBusNamespaceAuthorizationRule() *schema.Resource {
1814
return &schema.Resource{
1915
Create: resourceArmServiceBusNamespaceAuthorizationRuleCreateUpdate,
@@ -25,7 +21,8 @@ func resourceArmServiceBusNamespaceAuthorizationRule() *schema.Resource {
2521
State: schema.ImportStatePassthrough,
2622
},
2723

28-
Schema: resourceArmServiceAuthRuleSchemaFrom(map[string]*schema.Schema{
24+
//function takes a schema map and adds the authorization rule properties to it
25+
Schema: azure.ServiceBusAuthorizationRuleSchemaFrom(map[string]*schema.Schema{
2926
"name": {
3027
Type: schema.TypeString,
3128
Required: true,
@@ -41,48 +38,6 @@ func resourceArmServiceBusNamespaceAuthorizationRule() *schema.Resource {
4138
},
4239

4340
"resource_group_name": resourceGroupNameSchema(),
44-
45-
"listen": {
46-
Type: schema.TypeBool,
47-
Optional: true,
48-
Default: false,
49-
},
50-
51-
"send": {
52-
Type: schema.TypeBool,
53-
Optional: true,
54-
Default: false,
55-
},
56-
57-
"manage": {
58-
Type: schema.TypeBool,
59-
Optional: true,
60-
Default: false,
61-
},
62-
63-
"primary_key": {
64-
Type: schema.TypeString,
65-
Computed: true,
66-
Sensitive: true,
67-
},
68-
69-
"primary_connection_string": {
70-
Type: schema.TypeString,
71-
Computed: true,
72-
Sensitive: true,
73-
},
74-
75-
"secondary_key": {
76-
Type: schema.TypeString,
77-
Computed: true,
78-
Sensitive: true,
79-
},
80-
81-
"secondary_connection_string": {
82-
Type: schema.TypeString,
83-
Computed: true,
84-
Sensitive: true,
85-
},
8641
}),
8742

8843
CustomizeDiff: azure.ServiceBusAuthorizationRuleCustomizeDiff,
@@ -182,7 +137,7 @@ func resourceArmServiceBusNamespaceAuthorizationRuleDelete(d *schema.ResourceDat
182137

183138
resGroup := id.ResourceGroup
184139
namespaceName := id.Path["namespaces"]
185-
name := id.Path["AuthorizationRules"] //this is slightly different then topic (Authorization vs authorization)
140+
name := id.Path["AuthorizationRules"] //this is slightly different then topic/queue (Authorization vs authorization)
186141

187142
if _, err = client.DeleteAuthorizationRule(ctx, resGroup, namespaceName, name); err != nil {
188143
return fmt.Errorf("Error issuing Azure ARM delete request of ServiceBus Namespace Authorization Rule %q (Resource Group %q): %+v", name, resGroup, err)

azurerm/resource_arm_servicebus_namespace_authorization_rule_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ func testCheckAzureRMServiceBusNamespaceAuthorizationRuleDestroy(s *terraform.St
106106
ctx := testAccProvider.Meta().(*ArmClient).StopContext
107107

108108
for _, rs := range s.RootModule().Resources {
109-
if rs.Type != "azurerm_servicebus_topic_authorization_rule" {
109+
if rs.Type != "azurerm_servicebus_namespace_authorization_rule" {
110110
continue
111111
}
112112

@@ -173,6 +173,7 @@ resource "azurerm_servicebus_namespace_authorization_rule" "test" {
173173
name = "acctest-%[1]d"
174174
namespace_name = "${azurerm_servicebus_namespace.test.name}"
175175
resource_group_name = "${azurerm_resource_group.test.name}"
176+
176177
listen = %[3]t
177178
send = %[4]t
178179
manage = %[5]t

azurerm/resource_arm_servicebus_queue.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ func resourceArmServiceBusQueue() *schema.Resource {
2222

2323
Schema: map[string]*schema.Schema{
2424
"name": {
25-
Type: schema.TypeString,
26-
Required: true,
27-
ForceNew: true,
25+
Type: schema.TypeString,
26+
Required: true,
27+
ForceNew: true,
28+
ValidateFunc: azure.ValidateServiceBusQueueName(),
2829
},
2930

3031
"namespace_name": {
@@ -107,6 +108,7 @@ func resourceArmServiceBusQueue() *schema.Resource {
107108
Optional: true,
108109
Deprecated: "This field has been removed by Azure.",
109110
},
111+
110112
"support_ordering": {
111113
Type: schema.TypeBool,
112114
Optional: true,

0 commit comments

Comments
 (0)