-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ecec784
commit 9470ece
Showing
5 changed files
with
377 additions
and
2 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
34 changes: 34 additions & 0 deletions
34
builtin/providers/azurerm/import_arm_eventhub_consumer_group_test.go
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 TestAccAzureRMEventHubConsumerGroup_importBasic(t *testing.T) { | ||
resourceName := "azurerm_eventhub_consumer_group.test" | ||
|
||
ri := acctest.RandInt() | ||
config := fmt.Sprintf(testAccAzureRMEventHubConsumerGroup_basic, ri, ri) | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testCheckAzureRMEventHubConsumerGroupDestroy, | ||
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
158 changes: 158 additions & 0 deletions
158
builtin/providers/azurerm/resource_arm_eventhub_consumer_group.go
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,158 @@ | ||
package azurerm | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
|
||
"net/http" | ||
|
||
"github.com/Azure/azure-sdk-for-go/arm/eventhub" | ||
"github.com/hashicorp/terraform/helper/schema" | ||
) | ||
|
||
func resourceArmEventHubConsumerGroup() *schema.Resource { | ||
return &schema.Resource{ | ||
Create: resourceArmEventHubConsumerGroupCreate, | ||
Read: resourceArmEventHubConsumerGroupRead, | ||
Update: resourceArmEventHubConsumerGroupCreate, | ||
Delete: resourceArmEventHubConsumerGroupDelete, | ||
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, | ||
}, | ||
|
||
"eventhub_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, | ||
}, | ||
|
||
"eventhub_path": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
|
||
"user_metadata": { | ||
Type: schema.TypeString, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func resourceArmEventHubConsumerGroupCreate(d *schema.ResourceData, meta interface{}) error { | ||
client := meta.(*ArmClient) | ||
eventhubClient := client.eventHubConsumerGroupClient | ||
log.Printf("[INFO] preparing arguments for Azure ARM EventHub Consumer Group creation.") | ||
|
||
name := d.Get("name").(string) | ||
namespaceName := d.Get("namespace_name").(string) | ||
eventHubName := d.Get("eventhub_name").(string) | ||
location := d.Get("location").(string) | ||
resGroup := d.Get("resource_group_name").(string) | ||
eventHubPath := d.Get("eventhub_path").(string) | ||
userMetaData := d.Get("user_metadata").(string) | ||
|
||
parameters := eventhub.ConsumerGroupCreateOrUpdateParameters{ | ||
Location: &location, | ||
Properties: &eventhub.ConsumerGroupProperties{ | ||
EventHubPath: &eventHubPath, | ||
UserMetadata: &userMetaData, | ||
}, | ||
} | ||
|
||
_, err := eventhubClient.CreateOrUpdate(resGroup, namespaceName, eventHubName, name, parameters) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
read, err := eventhubClient.Get(resGroup, namespaceName, eventHubName, name) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if read.ID == nil { | ||
return fmt.Errorf("Cannot read EventHub Consumer Group %s (resource group %s) ID", name, resGroup) | ||
} | ||
|
||
d.SetId(*read.ID) | ||
|
||
return resourceArmEventHubRead(d, meta) | ||
} | ||
|
||
func resourceArmEventHubConsumerGroupRead(d *schema.ResourceData, meta interface{}) error { | ||
eventhubClient := meta.(*ArmClient).eventHubConsumerGroupClient | ||
|
||
id, err := parseAzureResourceID(d.Id()) | ||
if err != nil { | ||
return err | ||
} | ||
resGroup := id.ResourceGroup | ||
namespaceName := id.Path["namespaces"] | ||
eventHubName := id.Path["eventhubs"] | ||
name := id.Path["consumergroups"] | ||
|
||
resp, err := eventhubClient.Get(resGroup, namespaceName, eventHubName, name) | ||
if err != nil { | ||
return fmt.Errorf("Error making Read request on Azure EventHub Consumer Group %s: %s", name, err) | ||
} | ||
if resp.StatusCode == http.StatusNotFound { | ||
d.SetId("") | ||
return nil | ||
} | ||
|
||
d.Set("name", resp.Name) | ||
d.Set("eventhub_name", eventHubName) | ||
d.Set("namespace_name", namespaceName) | ||
d.Set("resource_group_name", resGroup) | ||
d.Set("location", azureRMNormalizeLocation(*resp.Location)) | ||
|
||
d.Set("eventhub_path", resp.Properties.EventHubPath) | ||
d.Set("user_metadata", resp.Properties.UserMetadata) | ||
|
||
return nil | ||
} | ||
|
||
func resourceArmEventHubConsumerGroupDelete(d *schema.ResourceData, meta interface{}) error { | ||
eventhubClient := meta.(*ArmClient).eventHubConsumerGroupClient | ||
|
||
id, err := parseAzureResourceID(d.Id()) | ||
if err != nil { | ||
return err | ||
} | ||
resGroup := id.ResourceGroup | ||
namespaceName := id.Path["namespaces"] | ||
eventHubName := id.Path["eventhubs"] | ||
name := id.Path["consumergroups"] | ||
|
||
resp, err := eventhubClient.Delete(resGroup, namespaceName, eventHubName, name) | ||
|
||
if resp.StatusCode != http.StatusOK { | ||
return fmt.Errorf("Error issuing Azure ARM delete request of EventHub Consumer Group '%s': %s", name, err) | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.