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

provider/azurerm: fix servicebus_topic updating values #9323

Merged
merged 1 commit into from
Oct 25, 2016
Merged
Show file tree
Hide file tree
Changes from all 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
28 changes: 24 additions & 4 deletions builtin/providers/azurerm/resource_arm_servicebus_topic.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,20 @@ func resourceArmServiceBusTopic() *schema.Resource {
"enable_partitioning": {
Type: schema.TypeBool,
Optional: true,
ForceNew: true,
},

"max_size_in_megabytes": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
Type: schema.TypeInt,
Optional: true,
Computed: true,
ValidateFunc: validateArmServiceBusTopicMaxSize,
},

"requires_duplicate_detection": {
Type: schema.TypeBool,
Optional: true,
ForceNew: true,
},

"support_ordering": {
Expand Down Expand Up @@ -199,10 +202,18 @@ func resourceArmServiceBusTopicRead(d *schema.ResourceData, meta interface{}) er
d.Set("enable_express", props.EnableExpress)
d.Set("enable_filtering_messages_before_publishing", props.FilteringMessagesBeforePublishing)
d.Set("enable_partitioning", props.EnablePartitioning)
d.Set("max_size_in_megabytes", int(*props.MaxSizeInMegabytes))
d.Set("requires_duplicate_detection", props.RequiresDuplicateDetection)
d.Set("support_ordering", props.SupportOrdering)

// if partitioning is enabled then the max size returned by the API will be
// 16 times greater than the value set by the user
if *props.EnablePartitioning {
const partitionCount = 16
d.Set("max_size_in_megabytes", int(*props.MaxSizeInMegabytes/partitionCount))
} else {
d.Set("max_size_in_megabytes", int(*props.MaxSizeInMegabytes))
}

return nil
}

Expand All @@ -221,3 +232,12 @@ func resourceArmServiceBusTopicDelete(d *schema.ResourceData, meta interface{})

return err
}

func validateArmServiceBusTopicMaxSize(i interface{}, k string) (s []string, es []error) {
v := i.(int)
if v%1024 != 0 || v < 0 || v > 10240 {
es = append(es, fmt.Errorf("%q must be a multiple of 1024 up to and including 10240", k))
}

return
}
102 changes: 102 additions & 0 deletions builtin/providers/azurerm/resource_arm_servicebus_topic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,63 @@ func TestAccAzureRMServiceBusTopic_update(t *testing.T) {
})
}

func TestAccAzureRMServiceBusTopic_enablePartitioning(t *testing.T) {
ri := acctest.RandInt()
preConfig := fmt.Sprintf(testAccAzureRMServiceBusTopic_basic, ri, ri, ri)
postConfig := fmt.Sprintf(testAccAzureRMServiceBusTopic_enablePartitioning, ri, ri, ri)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMServiceBusTopicDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: preConfig,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMServiceBusTopicExists("azurerm_servicebus_topic.test"),
),
},
resource.TestStep{
Config: postConfig,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"azurerm_servicebus_topic.test", "enable_partitioning", "true"),
// Ensure size is read back in it's original value and not the x16 value returned by Azure
resource.TestCheckResourceAttr(
"azurerm_servicebus_topic.test", "max_size_in_megabytes", "10240"),
),
},
},
})
}

func TestAccAzureRMServiceBusTopic_enableDuplicateDetection(t *testing.T) {
ri := acctest.RandInt()
preConfig := fmt.Sprintf(testAccAzureRMServiceBusTopic_basic, ri, ri, ri)
postConfig := fmt.Sprintf(testAccAzureRMServiceBusTopic_enableDuplicateDetection, ri, ri, ri)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMServiceBusTopicDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: preConfig,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMServiceBusTopicExists("azurerm_servicebus_topic.test"),
),
},
resource.TestStep{
Config: postConfig,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"azurerm_servicebus_topic.test", "requires_duplicate_detection", "true"),
),
},
},
})
}

func testCheckAzureRMServiceBusTopicDestroy(s *terraform.State) error {
client := testAccProvider.Meta().(*ArmClient).serviceBusTopicsClient

Expand Down Expand Up @@ -159,3 +216,48 @@ resource "azurerm_servicebus_topic" "test" {
enable_express = true
}
`

var testAccAzureRMServiceBusTopic_enablePartitioning = `
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "West US"
}

resource "azurerm_servicebus_namespace" "test" {
name = "acctestservicebusnamespace-%d"
location = "West US"
resource_group_name = "${azurerm_resource_group.test.name}"
sku = "standard"
}

resource "azurerm_servicebus_topic" "test" {
name = "acctestservicebustopic-%d"
location = "West US"
namespace_name = "${azurerm_servicebus_namespace.test.name}"
resource_group_name = "${azurerm_resource_group.test.name}"
enable_partitioning = true
max_size_in_megabytes = 10240
}
`

var testAccAzureRMServiceBusTopic_enableDuplicateDetection = `
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "West US"
}

resource "azurerm_servicebus_namespace" "test" {
name = "acctestservicebusnamespace-%d"
location = "West US"
resource_group_name = "${azurerm_resource_group.test.name}"
sku = "standard"
}

resource "azurerm_servicebus_topic" "test" {
name = "acctestservicebustopic-%d"
location = "West US"
namespace_name = "${azurerm_servicebus_namespace.test.name}"
resource_group_name = "${azurerm_resource_group.test.name}"
requires_duplicate_detection = true
}
`
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,16 @@ The following arguments are supported:

* `enable_partitioning` - (Optional) Boolean flag which controls whether to enable
the topic to be partitioned across multiple message brokers. Defaults to false.
Changing this forces a new resource to be created.

* `max_size_in_megabytes` - (Optional) Integer value which controls the size of
memory allocated for the topic.
memory allocated for the topic. Supported values are multiples of 1024 up to
10240, if `enable_partitioning` is enabled then 16 partitions will be created
per GB, making the maximum possible topic size 163840 (10240 * 16).

* `requires_duplicate_detection` - (Optional) Boolean flag which controls whether
the Topic requires duplicate detection. Defaults to false.
the Topic requires duplicate detection. Defaults to false. Changing this forces
a new resource to be created.

* `support_ordering` - (Optional) Boolean flag which controls whether the Topic
supports ordering. Defaults to false.
Expand Down