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

New Resource - azurerm_servicebus_queue_authorization_rule #1543

Merged
merged 5 commits into from
Jul 15, 2018
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions azurerm/helpers/azure/servicebus.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,20 @@ func ValidateServiceBusNamespaceName() schema.SchemaValidateFunc {
)
}

func ValidateServiceBusQueueName() schema.SchemaValidateFunc {
return validation.StringMatch(
regexp.MustCompile(`^[a-zA-Z0-9][\w-./~]{0,258}([a-zA-Z0-9])?$`),
"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.",
)
}

func ValidateServiceBusSubscriptionName() schema.SchemaValidateFunc {
return validation.StringMatch(
regexp.MustCompile("^[a-zA-Z][-._a-zA-Z0-9]{0,48}([a-zA-Z0-9])?$"),
"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.",
)
}

func ValidateServiceBusTopicName() schema.SchemaValidateFunc {
return validation.StringMatch(
regexp.MustCompile("^[a-zA-Z][-._a-zA-Z0-9]{0,258}([a-zA-Z0-9])?$"),
Expand Down Expand Up @@ -73,6 +87,67 @@ func FlattenServiceBusAuthorizationRuleRights(rights *[]servicebus.AccessRights)
}

//shared schema
func MergeSchema(a map[string]*schema.Schema, b map[string]*schema.Schema) map[string]*schema.Schema {
Copy link
Contributor

Choose a reason for hiding this comment

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

since this isn't being used outside of this package, this could probably become a private method?

s := map[string]*schema.Schema{}

for k, v := range a {
s[k] = v
}

for k, v := range b {
s[k] = v
}

return s
}

func ServiceBusAuthorizationRuleSchemaFrom(s map[string]*schema.Schema) map[string]*schema.Schema {

authSchema := map[string]*schema.Schema{
"listen": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},

"send": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},

"manage": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},

"primary_key": {
Type: schema.TypeString,
Computed: true,
Sensitive: true,
},

"primary_connection_string": {
Type: schema.TypeString,
Computed: true,
Sensitive: true,
},

"secondary_key": {
Type: schema.TypeString,
Computed: true,
Sensitive: true,
},

"secondary_connection_string": {
Type: schema.TypeString,
Computed: true,
Sensitive: true,
},
}
return MergeSchema(s, authSchema)
}

func ServiceBusAuthorizationRuleCustomizeDiff(d *schema.ResourceDiff, _ interface{}) error {
listen, hasListen := d.GetOk("listen")
Expand Down
104 changes: 0 additions & 104 deletions azurerm/import_arm_servicebus_topic_authorization_rule_test.go

This file was deleted.

1 change: 1 addition & 0 deletions azurerm/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ func Provider() terraform.ResourceProvider {
"azurerm_servicebus_namespace": resourceArmServiceBusNamespace(),
"azurerm_servicebus_namespace_authorization_rule": resourceArmServiceBusNamespaceAuthorizationRule(),
"azurerm_servicebus_queue": resourceArmServiceBusQueue(),
"azurerm_servicebus_queue_authorization_rule": resourceArmServiceBusQueueAuthorizationRule(),
"azurerm_servicebus_subscription": resourceArmServiceBusSubscription(),
"azurerm_servicebus_subscription_rule": resourceArmServiceBusSubscriptionRule(),
"azurerm_servicebus_topic": resourceArmServiceBusTopic(),
Expand Down
51 changes: 3 additions & 48 deletions azurerm/resource_arm_servicebus_namespace_authorization_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ import (
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)

func resourceArmServiceAuthRuleSchemaFrom(schema map[string]*schema.Schema) map[string]*schema.Schema {
return schema
}

func resourceArmServiceBusNamespaceAuthorizationRule() *schema.Resource {
return &schema.Resource{
Create: resourceArmServiceBusNamespaceAuthorizationRuleCreateUpdate,
Expand All @@ -25,7 +21,8 @@ func resourceArmServiceBusNamespaceAuthorizationRule() *schema.Resource {
State: schema.ImportStatePassthrough,
},

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

"resource_group_name": resourceGroupNameSchema(),

"listen": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},

"send": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},

"manage": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},

"primary_key": {
Type: schema.TypeString,
Computed: true,
Sensitive: true,
},

"primary_connection_string": {
Type: schema.TypeString,
Computed: true,
Sensitive: true,
},

"secondary_key": {
Type: schema.TypeString,
Computed: true,
Sensitive: true,
},

"secondary_connection_string": {
Type: schema.TypeString,
Computed: true,
Sensitive: true,
},
}),

CustomizeDiff: azure.ServiceBusAuthorizationRuleCustomizeDiff,
Expand Down Expand Up @@ -182,7 +137,7 @@ func resourceArmServiceBusNamespaceAuthorizationRuleDelete(d *schema.ResourceDat

resGroup := id.ResourceGroup
namespaceName := id.Path["namespaces"]
name := id.Path["AuthorizationRules"] //this is slightly different then topic (Authorization vs authorization)
name := id.Path["AuthorizationRules"] //this is slightly different then topic/queue (Authorization vs authorization)

if _, err = client.DeleteAuthorizationRule(ctx, resGroup, namespaceName, name); err != nil {
return fmt.Errorf("Error issuing Azure ARM delete request of ServiceBus Namespace Authorization Rule %q (Resource Group %q): %+v", name, resGroup, err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func testCheckAzureRMServiceBusNamespaceAuthorizationRuleDestroy(s *terraform.St
ctx := testAccProvider.Meta().(*ArmClient).StopContext

for _, rs := range s.RootModule().Resources {
if rs.Type != "azurerm_servicebus_topic_authorization_rule" {
if rs.Type != "azurerm_servicebus_namespace_authorization_rule" {
continue
}

Expand Down Expand Up @@ -173,6 +173,7 @@ resource "azurerm_servicebus_namespace_authorization_rule" "test" {
name = "acctest-%[1]d"
namespace_name = "${azurerm_servicebus_namespace.test.name}"
resource_group_name = "${azurerm_resource_group.test.name}"

listen = %[3]t
send = %[4]t
manage = %[5]t
Expand Down
8 changes: 5 additions & 3 deletions azurerm/resource_arm_servicebus_queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ func resourceArmServiceBusQueue() *schema.Resource {

Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: azure.ValidateServiceBusQueueName(),
},

"namespace_name": {
Expand Down Expand Up @@ -107,6 +108,7 @@ func resourceArmServiceBusQueue() *schema.Resource {
Optional: true,
Deprecated: "This field has been removed by Azure.",
},

"support_ordering": {
Type: schema.TypeBool,
Optional: true,
Expand Down
Loading