Skip to content

Commit

Permalink
Event Hub: force new resource on partition_count change (#2400)
Browse files Browse the repository at this point in the history
  • Loading branch information
tiantun authored and tombuildsstuff committed Nov 28, 2018
1 parent 4cea44d commit e7f9d34
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 2 deletions.
4 changes: 3 additions & 1 deletion azurerm/resource_arm_eventhub.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/helper/validation"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/suppress"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)

Expand Down Expand Up @@ -46,6 +47,7 @@ func resourceArmEventHub() *schema.Resource {
"partition_count": {
Type: schema.TypeInt,
Required: true,
ForceNew: true,
ValidateFunc: validateEventHubPartitionCount,
},

Expand All @@ -68,7 +70,7 @@ func resourceArmEventHub() *schema.Resource {
"encoding": {
Type: schema.TypeString,
Required: true,
DiffSuppressFunc: ignoreCaseDiffSuppressFunc,
DiffSuppressFunc: suppress.CaseDifference,
ValidateFunc: validation.StringInSlice([]string{
string(eventhub.Avro),
string(eventhub.AvroDeflate),
Expand Down
53 changes: 53 additions & 0 deletions azurerm/resource_arm_eventhub_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,35 @@ func TestAccAzureRMEventHub_basic(t *testing.T) {
})
}

func TestAccAzureRMEventHub_partitionCountUpdate(t *testing.T) {
resourceName := "azurerm_eventhub.test"
ri := acctest.RandInt()
preConfig := testAccAzureRMEventHub_basic(ri, testLocation())
postConfig := testAccAzureRMEventHub_partitionCountUpdate(ri, testLocation())

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMEventHubDestroy,
Steps: []resource.TestStep{
{
Config: preConfig,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMEventHubExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "partition_count", "2"),
),
},
{
Config: postConfig,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMEventHubExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "partition_count", "10"),
),
},
},
})
}

func TestAccAzureRMEventHub_standard(t *testing.T) {
resourceName := "azurerm_eventhub.test"
ri := acctest.RandInt()
Expand Down Expand Up @@ -381,6 +410,30 @@ resource "azurerm_eventhub" "test" {
`, rInt, location, rInt, rInt)
}

func testAccAzureRMEventHub_partitionCountUpdate(rInt int, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "%s"
}
resource "azurerm_eventhub_namespace" "test" {
name = "acctesteventhubnamespace-%d"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
sku = "Basic"
}
resource "azurerm_eventhub" "test" {
name = "acctesteventhub-%d"
namespace_name = "${azurerm_eventhub_namespace.test.name}"
resource_group_name = "${azurerm_resource_group.test.name}"
partition_count = 10
message_retention = 1
}
`, rInt, location, rInt, rInt)
}

func testAccAzureRMEventHub_standard(rInt int, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/eventhub.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ The following arguments are supported:

* `resource_group_name` - (Required) The name of the resource group in which the EventHub's parent Namespace exists. Changing this forces a new resource to be created.

* `partition_count` - (Required) Specifies the current number of shards on the Event Hub.
* `partition_count` - (Required) Specifies the current number of shards on the Event Hub. Changing this forces a new resource to be created.

* `message_retention` - (Required) Specifies the number of days to retain the events for this Event Hub. Needs to be between 1 and 7 days; or 1 day when using a Basic SKU for the parent EventHub Namespace.

Expand Down

0 comments on commit e7f9d34

Please sign in to comment.