Skip to content

Commit 56344eb

Browse files
pmcatomineystack72
authored andcommitted
provider/azurerm: fix servicebus_topic max_size_in_megabytes for premium namespaces (hashicorp#10611)
The value is only multiplied by the API for topics in non-premium namespaces TF_ACC=1 go test ./builtin/providers/azurerm -v -run TestAccAzureRMServiceBusTopic_enablePartitioning -timeout 120m === RUN TestAccAzureRMServiceBusTopic_enablePartitioningStandard --- PASS: TestAccAzureRMServiceBusTopic_enablePartitioningStandard (378.80s) === RUN TestAccAzureRMServiceBusTopic_enablePartitioningPremium --- PASS: TestAccAzureRMServiceBusTopic_enablePartitioningPremium (655.00s) PASS ok github.com/hashicorp/terraform/builtin/providers/azurerm 1033.874s
1 parent 195b041 commit 56344eb

3 files changed

Lines changed: 96 additions & 25 deletions

File tree

builtin/providers/azurerm/resource_arm_servicebus_topic.go

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,9 @@ func resourceArmServiceBusTopic() *schema.Resource {
7979
},
8080

8181
"max_size_in_megabytes": {
82-
Type: schema.TypeInt,
83-
Optional: true,
84-
Computed: true,
85-
ValidateFunc: validateArmServiceBusTopicMaxSize,
82+
Type: schema.TypeInt,
83+
Optional: true,
84+
Computed: true,
8685
},
8786

8887
"requires_duplicate_detection": {
@@ -200,15 +199,24 @@ func resourceArmServiceBusTopicRead(d *schema.ResourceData, meta interface{}) er
200199
d.Set("requires_duplicate_detection", props.RequiresDuplicateDetection)
201200
d.Set("support_ordering", props.SupportOrdering)
202201

203-
// if partitioning is enabled then the max size returned by the API will be
204-
// 16 times greater than the value set by the user
202+
maxSize := int(*props.MaxSizeInMegabytes)
203+
204+
// if the topic is in a premium namespace and partitioning is enabled then the
205+
// max size returned by the API will be 16 times greater than the value set
205206
if *props.EnablePartitioning {
206-
const partitionCount = 16
207-
d.Set("max_size_in_megabytes", int(*props.MaxSizeInMegabytes/partitionCount))
208-
} else {
209-
d.Set("max_size_in_megabytes", int(*props.MaxSizeInMegabytes))
207+
namespace, err := meta.(*ArmClient).serviceBusNamespacesClient.Get(resGroup, namespaceName)
208+
if err != nil {
209+
return err
210+
}
211+
212+
if namespace.Sku.Name != servicebus.Premium {
213+
const partitionCount = 16
214+
maxSize = int(*props.MaxSizeInMegabytes / partitionCount)
215+
}
210216
}
211217

218+
d.Set("max_size_in_megabytes", maxSize)
219+
212220
return nil
213221
}
214222

@@ -227,12 +235,3 @@ func resourceArmServiceBusTopicDelete(d *schema.ResourceData, meta interface{})
227235

228236
return err
229237
}
230-
231-
func validateArmServiceBusTopicMaxSize(i interface{}, k string) (s []string, es []error) {
232-
v := i.(int)
233-
if v%1024 != 0 || v < 0 || v > 5120 {
234-
es = append(es, fmt.Errorf("%q must be a multiple of 1024 up to and including 5120", k))
235-
}
236-
237-
return
238-
}

builtin/providers/azurerm/resource_arm_servicebus_topic_test.go

Lines changed: 76 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ func TestAccAzureRMServiceBusTopic_update(t *testing.T) {
5858
})
5959
}
6060

61-
func TestAccAzureRMServiceBusTopic_enablePartitioning(t *testing.T) {
61+
func TestAccAzureRMServiceBusTopic_enablePartitioningStandard(t *testing.T) {
6262
ri := acctest.RandInt()
6363
preConfig := fmt.Sprintf(testAccAzureRMServiceBusTopic_basic, ri, ri, ri)
64-
postConfig := fmt.Sprintf(testAccAzureRMServiceBusTopic_enablePartitioning, ri, ri, ri)
64+
postConfig := fmt.Sprintf(testAccAzureRMServiceBusTopic_enablePartitioningStandard, ri, ri, ri)
6565

6666
resource.Test(t, resource.TestCase{
6767
PreCheck: func() { testAccPreCheck(t) },
@@ -88,6 +88,35 @@ func TestAccAzureRMServiceBusTopic_enablePartitioning(t *testing.T) {
8888
})
8989
}
9090

91+
func TestAccAzureRMServiceBusTopic_enablePartitioningPremium(t *testing.T) {
92+
ri := acctest.RandInt()
93+
preConfig := fmt.Sprintf(testAccAzureRMServiceBusTopic_basic, ri, ri, ri)
94+
postConfig := fmt.Sprintf(testAccAzureRMServiceBusTopic_enablePartitioningPremium, ri, ri, ri)
95+
96+
resource.Test(t, resource.TestCase{
97+
PreCheck: func() { testAccPreCheck(t) },
98+
Providers: testAccProviders,
99+
CheckDestroy: testCheckAzureRMServiceBusTopicDestroy,
100+
Steps: []resource.TestStep{
101+
resource.TestStep{
102+
Config: preConfig,
103+
Check: resource.ComposeTestCheckFunc(
104+
testCheckAzureRMServiceBusTopicExists("azurerm_servicebus_topic.test"),
105+
),
106+
},
107+
resource.TestStep{
108+
Config: postConfig,
109+
Check: resource.ComposeTestCheckFunc(
110+
resource.TestCheckResourceAttr(
111+
"azurerm_servicebus_topic.test", "enable_partitioning", "true"),
112+
resource.TestCheckResourceAttr(
113+
"azurerm_servicebus_topic.test", "max_size_in_megabytes", "81920"),
114+
),
115+
},
116+
},
117+
})
118+
}
119+
91120
func TestAccAzureRMServiceBusTopic_enableDuplicateDetection(t *testing.T) {
92121
ri := acctest.RandInt()
93122
preConfig := fmt.Sprintf(testAccAzureRMServiceBusTopic_basic, ri, ri, ri)
@@ -194,6 +223,27 @@ resource "azurerm_servicebus_topic" "test" {
194223
}
195224
`
196225

226+
var testAccAzureRMServiceBusTopic_basicPremium = `
227+
resource "azurerm_resource_group" "test" {
228+
name = "acctestRG-%d"
229+
location = "West US"
230+
}
231+
232+
resource "azurerm_servicebus_namespace" "test" {
233+
name = "acctestservicebusnamespace-%d"
234+
location = "West US"
235+
resource_group_name = "${azurerm_resource_group.test.name}"
236+
sku = "premium"
237+
}
238+
239+
resource "azurerm_servicebus_topic" "test" {
240+
name = "acctestservicebustopic-%d"
241+
location = "West US"
242+
namespace_name = "${azurerm_servicebus_namespace.test.name}"
243+
resource_group_name = "${azurerm_resource_group.test.name}"
244+
}
245+
`
246+
197247
var testAccAzureRMServiceBusTopic_update = `
198248
resource "azurerm_resource_group" "test" {
199249
name = "acctestRG-%d"
@@ -217,7 +267,7 @@ resource "azurerm_servicebus_topic" "test" {
217267
}
218268
`
219269

220-
var testAccAzureRMServiceBusTopic_enablePartitioning = `
270+
var testAccAzureRMServiceBusTopic_enablePartitioningStandard = `
221271
resource "azurerm_resource_group" "test" {
222272
name = "acctestRG-%d"
223273
location = "West US"
@@ -240,6 +290,29 @@ resource "azurerm_servicebus_topic" "test" {
240290
}
241291
`
242292

293+
var testAccAzureRMServiceBusTopic_enablePartitioningPremium = `
294+
resource "azurerm_resource_group" "test" {
295+
name = "acctestRG-%d"
296+
location = "West US"
297+
}
298+
299+
resource "azurerm_servicebus_namespace" "test" {
300+
name = "acctestservicebusnamespace-%d"
301+
location = "West US"
302+
resource_group_name = "${azurerm_resource_group.test.name}"
303+
sku = "premium"
304+
}
305+
306+
resource "azurerm_servicebus_topic" "test" {
307+
name = "acctestservicebustopic-%d"
308+
location = "West US"
309+
namespace_name = "${azurerm_servicebus_namespace.test.name}"
310+
resource_group_name = "${azurerm_resource_group.test.name}"
311+
enable_partitioning = true
312+
max_size_in_megabytes = 81920
313+
}
314+
`
315+
243316
var testAccAzureRMServiceBusTopic_enableDuplicateDetection = `
244317
resource "azurerm_resource_group" "test" {
245318
name = "acctestRG-%d"

website/source/docs/providers/azurerm/r/servicebus_topic.html.markdown

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,8 @@ The following arguments are supported:
8585
Changing this forces a new resource to be created.
8686

8787
* `max_size_in_megabytes` - (Optional) Integer value which controls the size of
88-
memory allocated for the topic. Supported values are multiples of 1024 up to
89-
5120, if `enable_partitioning` is enabled then 16 partitions will be created
90-
per GB, making the maximum possible topic size 81920 (5120 * 16).
88+
memory allocated for the topic. For supported values see the "Queue/topic size"
89+
section of [this document](https://docs.microsoft.com/en-us/azure/service-bus-messaging/service-bus-quotas).
9190

9291
* `requires_duplicate_detection` - (Optional) Boolean flag which controls whether
9392
the Topic requires duplicate detection. Defaults to false. Changing this forces

0 commit comments

Comments
 (0)