provider/azurerm: fix servicebus_topic updating values (#9323)
enable_partitioning set to ForceNew requires_duplicate_detection set to ForceNew max_size_in_megabytes would cause a loop if enable_partitioning was true as this causes the value to be multiplied by 16 for it's effective value, this computed value is then returned by the ARM API in the same field which caused Terraform to always detect a change ``` TF_ACC=1 go test ./builtin/providers/azurerm -v -run TestAccAzureRMServiceBusTopic -timeout 120m === RUN TestAccAzureRMServiceBusTopic_importBasic --- PASS: TestAccAzureRMServiceBusTopic_importBasic (345.08s) === RUN TestAccAzureRMServiceBusTopic_basic --- PASS: TestAccAzureRMServiceBusTopic_basic (342.23s) === RUN TestAccAzureRMServiceBusTopic_update --- PASS: TestAccAzureRMServiceBusTopic_update (359.56s) === RUN TestAccAzureRMServiceBusTopic_enablePartitioning --- PASS: TestAccAzureRMServiceBusTopic_enablePartitioning (362.80s) === RUN TestAccAzureRMServiceBusTopic_enableDuplicateDetection --- PASS: TestAccAzureRMServiceBusTopic_enableDuplicateDetection (364.97s) PASS ok github.com/hashicorp/terraform/builtin/providers/azurerm 1774.657s ```
This commit is contained in:
parent
7c56e33319
commit
c199d1fde2
|
@ -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": {
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
`
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue