-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Implemented EventHubs * Missing the sidebar link * Fixing the type * Fixing the docs for Namespace * Removing premium tests * Checking the correct status code on delete * Added a test case for the import * Documentation for importing * Fixing a typo
- Loading branch information
1 parent
a0c5d42
commit b15b7e1
Showing
9 changed files
with
578 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package azurerm | ||
|
||
import ( | ||
"testing" | ||
|
||
"fmt" | ||
|
||
"github.com/hashicorp/terraform/helper/acctest" | ||
"github.com/hashicorp/terraform/helper/resource" | ||
) | ||
|
||
func TestAccAzureRMEventHub_importBasic(t *testing.T) { | ||
resourceName := "azurerm_eventhub.test" | ||
|
||
ri := acctest.RandInt() | ||
config := fmt.Sprintf(testAccAzureRMEventHub_basic, ri, ri, ri) | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testCheckAzureRMEventHubDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: config, | ||
}, | ||
|
||
{ | ||
ResourceName: resourceName, | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
}, | ||
}, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,177 @@ | ||
package azurerm | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
|
||
"net/http" | ||
|
||
"github.com/Azure/azure-sdk-for-go/arm/eventhub" | ||
"github.com/hashicorp/terraform/helper/schema" | ||
) | ||
|
||
func resourceArmEventHub() *schema.Resource { | ||
return &schema.Resource{ | ||
Create: resourceArmEventHubCreate, | ||
Read: resourceArmEventHubRead, | ||
Update: resourceArmEventHubCreate, | ||
Delete: resourceArmEventHubDelete, | ||
Importer: &schema.ResourceImporter{ | ||
State: schema.ImportStatePassthrough, | ||
}, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
}, | ||
|
||
"namespace_name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
}, | ||
|
||
"resource_group_name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
}, | ||
|
||
"location": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
}, | ||
|
||
"partition_count": { | ||
Type: schema.TypeInt, | ||
Required: true, | ||
ValidateFunc: validateEventHubPartitionCount, | ||
}, | ||
|
||
"message_retention": { | ||
Type: schema.TypeInt, | ||
Required: true, | ||
ValidateFunc: validateEventHubMessageRetentionCount, | ||
}, | ||
|
||
"partition_ids": { | ||
Type: schema.TypeSet, | ||
Elem: &schema.Schema{Type: schema.TypeString}, | ||
Set: schema.HashString, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func resourceArmEventHubCreate(d *schema.ResourceData, meta interface{}) error { | ||
client := meta.(*ArmClient) | ||
eventhubClient := client.eventHubClient | ||
log.Printf("[INFO] preparing arguments for Azure ARM EventHub creation.") | ||
|
||
name := d.Get("name").(string) | ||
namespaceName := d.Get("namespace_name").(string) | ||
location := d.Get("location").(string) | ||
resGroup := d.Get("resource_group_name").(string) | ||
partitionCount := int64(d.Get("partition_count").(int)) | ||
messageRetention := int64(d.Get("message_retention").(int)) | ||
|
||
parameters := eventhub.CreateOrUpdateParameters{ | ||
Location: &location, | ||
Properties: &eventhub.Properties{ | ||
PartitionCount: &partitionCount, | ||
MessageRetentionInDays: &messageRetention, | ||
}, | ||
} | ||
|
||
_, err := eventhubClient.CreateOrUpdate(resGroup, namespaceName, name, parameters) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
read, err := eventhubClient.Get(resGroup, namespaceName, name) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if read.ID == nil { | ||
return fmt.Errorf("Cannot read EventHub %s (resource group %s) ID", name, resGroup) | ||
} | ||
|
||
d.SetId(*read.ID) | ||
|
||
return resourceArmEventHubRead(d, meta) | ||
} | ||
|
||
func resourceArmEventHubRead(d *schema.ResourceData, meta interface{}) error { | ||
eventhubClient := meta.(*ArmClient).eventHubClient | ||
|
||
id, err := parseAzureResourceID(d.Id()) | ||
if err != nil { | ||
return err | ||
} | ||
resGroup := id.ResourceGroup | ||
namespaceName := id.Path["namespaces"] | ||
name := id.Path["eventhubs"] | ||
|
||
resp, err := eventhubClient.Get(resGroup, namespaceName, name) | ||
if err != nil { | ||
return fmt.Errorf("Error making Read request on Azure EventHub %s: %s", name, err) | ||
} | ||
if resp.StatusCode == http.StatusNotFound { | ||
d.SetId("") | ||
return nil | ||
} | ||
|
||
d.Set("name", resp.Name) | ||
d.Set("namespace_name", namespaceName) | ||
d.Set("resource_group_name", resGroup) | ||
d.Set("location", azureRMNormalizeLocation(*resp.Location)) | ||
|
||
d.Set("partition_count", resp.Properties.PartitionCount) | ||
d.Set("message_retention", resp.Properties.MessageRetentionInDays) | ||
d.Set("partition_ids", resp.Properties.PartitionIds) | ||
|
||
return nil | ||
} | ||
|
||
func resourceArmEventHubDelete(d *schema.ResourceData, meta interface{}) error { | ||
eventhubClient := meta.(*ArmClient).eventHubClient | ||
|
||
id, err := parseAzureResourceID(d.Id()) | ||
if err != nil { | ||
return err | ||
} | ||
resGroup := id.ResourceGroup | ||
namespaceName := id.Path["namespaces"] | ||
name := id.Path["eventhubs"] | ||
|
||
resp, err := eventhubClient.Delete(resGroup, namespaceName, name) | ||
|
||
if resp.StatusCode != http.StatusOK { | ||
return fmt.Errorf("Error issuing Azure ARM delete request of EventHub'%s': %s", name, err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func validateEventHubPartitionCount(v interface{}, k string) (ws []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")) | ||
} | ||
return | ||
} | ||
|
||
func validateEventHubMessageRetentionCount(v interface{}, k string) (ws []string, errors []error) { | ||
value := v.(int) | ||
|
||
if !(7 >= value && value >= 1) { | ||
errors = append(errors, fmt.Errorf("EventHub Retention Count has to be between 1 and 7")) | ||
} | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.