Skip to content

Commit

Permalink
Fix for minimum partition count (#3439)
Browse files Browse the repository at this point in the history
  • Loading branch information
WodansSon authored May 15, 2019
1 parent a947468 commit e17cd7d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 10 deletions.
4 changes: 2 additions & 2 deletions azurerm/resource_arm_eventhub.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,8 @@ func resourceArmEventHubDelete(d *schema.ResourceData, meta interface{}) error {
func validateEventHubPartitionCount(v interface{}, _ string) (warnings []string, errors []error) {
value := v.(int)

if !(32 >= value && value >= 2) {
errors = append(errors, fmt.Errorf("EventHub Partition Count has to be between 2 and 32"))
if !(32 >= value && value >= 1) {
errors = append(errors, fmt.Errorf("EventHub Partition Count has to be between 1 and 32"))
}

return warnings, errors
Expand Down
45 changes: 37 additions & 8 deletions azurerm/resource_arm_eventhub_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@ func TestAccAzureRMEventHubPartitionCount_validation(t *testing.T) {
ErrCount int
}{
{
Value: 1,
Value: 0,
ErrCount: 1,
},
{
Value: 1,
ErrCount: 0,
},
{
Value: 2,
ErrCount: 0,
Expand Down Expand Up @@ -175,9 +179,34 @@ func TestAccAzureRMEventHub_basic(t *testing.T) {
CheckDestroy: testCheckAzureRMEventHubDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMEventHub_basic(ri, testLocation()),
Config: testAccAzureRMEventHub_basic(ri, testLocation(), 2),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMEventHubExists(resourceName),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccAzureRMEventHub_basicOnePartition(t *testing.T) {
resourceName := "azurerm_eventhub.test"
ri := tf.AccRandTimeInt()

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMEventHubDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMEventHub_basic(ri, testLocation(), 1),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMEventHubExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "partition_count", "1"),
),
},
{
Expand Down Expand Up @@ -206,7 +235,7 @@ func TestAccAzureRMEventHub_requiresImport(t *testing.T) {
CheckDestroy: testCheckAzureRMEventHubDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMEventHub_basic(ri, location),
Config: testAccAzureRMEventHub_basic(ri, location, 2),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMEventHubExists(resourceName),
),
Expand All @@ -222,7 +251,7 @@ func TestAccAzureRMEventHub_requiresImport(t *testing.T) {
func TestAccAzureRMEventHub_partitionCountUpdate(t *testing.T) {
resourceName := "azurerm_eventhub.test"
ri := tf.AccRandTimeInt()
preConfig := testAccAzureRMEventHub_basic(ri, testLocation())
preConfig := testAccAzureRMEventHub_basic(ri, testLocation(), 2)
postConfig := testAccAzureRMEventHub_partitionCountUpdate(ri, testLocation())

resource.ParallelTest(t, resource.TestCase{
Expand Down Expand Up @@ -418,7 +447,7 @@ func testCheckAzureRMEventHubExists(resourceName string) resource.TestCheckFunc
}
}

func testAccAzureRMEventHub_basic(rInt int, location string) string {
func testAccAzureRMEventHub_basic(rInt int, location string, partitionCount int) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
Expand All @@ -436,14 +465,14 @@ resource "azurerm_eventhub" "test" {
name = "acctesteventhub-%d"
namespace_name = "${azurerm_eventhub_namespace.test.name}"
resource_group_name = "${azurerm_resource_group.test.name}"
partition_count = 2
partition_count = %d
message_retention = 1
}
`, rInt, location, rInt, rInt)
`, rInt, location, rInt, rInt, partitionCount)
}

func testAccAzureRMEventHub_requiresImport(rInt int, location string) string {
template := testAccAzureRMEventHub_basic(rInt, location)
template := testAccAzureRMEventHub_basic(rInt, location, 2)
return fmt.Sprintf(`
%s
Expand Down

0 comments on commit e17cd7d

Please sign in to comment.