diff --git a/azurerm/internal/services/eventgrid/eventgrid_event_subscription_resource.go b/azurerm/internal/services/eventgrid/eventgrid_event_subscription_resource.go index a19f6c9f7ded..b133082a6639 100644 --- a/azurerm/internal/services/eventgrid/eventgrid_event_subscription_resource.go +++ b/azurerm/internal/services/eventgrid/eventgrid_event_subscription_resource.go @@ -6,6 +6,7 @@ import ( "time" "github.com/Azure/azure-sdk-for-go/services/preview/eventgrid/mgmt/2020-04-01-preview/eventgrid" + "github.com/Azure/go-autorest/autorest/date" "github.com/hashicorp/go-azure-helpers/response" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/helper/validation" @@ -19,8 +20,17 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) -func getEnpointTypes() []string { - return []string{"webhook_endpoint", "storage_queue_endpoint", "eventhub_endpoint", "hybrid_connection_endpoint"} +func enpointPropertyNames() []string { + return []string{ + "eventhub_endpoint", + "eventhub_endpoint_id", + "hybrid_connection_endpoint", + "hybrid_connection_endpoint_id", + "service_bus_queue_endpoint_id", + "service_bus_topic_endpoint_id", + "storage_queue_endpoint", + "webhook_endpoint", + } } func resourceArmEventGridEventSubscription() *schema.Resource { @@ -69,61 +79,103 @@ func resourceArmEventGridEventSubscription() *schema.Resource { }, false), }, + "expiration_time_utc": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + "topic_name": { Type: schema.TypeString, Optional: true, Computed: true, }, - "storage_queue_endpoint": { + "eventhub_endpoint_id": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ConflictsWith: utils.RemoveFromStringArray(enpointPropertyNames(), "eventhub_endpoint_id"), + ValidateFunc: azure.ValidateResourceID, + }, + + "eventhub_endpoint": { Type: schema.TypeList, MaxItems: 1, + Deprecated: "Deprecated in favour of `" + "eventhub_endpoint_id" + "`", Optional: true, - ConflictsWith: utils.RemoveFromStringArray(getEnpointTypes(), "storage_queue_endpoint"), + Computed: true, + ConflictsWith: utils.RemoveFromStringArray(enpointPropertyNames(), "eventhub_endpoint"), Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "storage_account_id": { + "eventhub_id": { Type: schema.TypeString, - Required: true, + Optional: true, + Computed: true, ValidateFunc: azure.ValidateResourceID, }, - "queue_name": { - Type: schema.TypeString, - Required: true, - ValidateFunc: validation.StringIsNotEmpty, - }, }, }, }, - "eventhub_endpoint": { + "hybrid_connection_endpoint_id": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ConflictsWith: utils.RemoveFromStringArray(enpointPropertyNames(), "hybrid_connection_endpoint_id"), + ValidateFunc: azure.ValidateResourceID, + }, + + "hybrid_connection_endpoint": { Type: schema.TypeList, MaxItems: 1, + Deprecated: "Deprecated in favour of `" + "hybrid_connection_endpoint_id" + "`", Optional: true, - ConflictsWith: utils.RemoveFromStringArray(getEnpointTypes(), "eventhub_endpoint"), + Computed: true, + ConflictsWith: utils.RemoveFromStringArray(enpointPropertyNames(), "hybrid_connection_endpoint"), Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "eventhub_id": { + "hybrid_connection_id": { Type: schema.TypeString, - Required: true, + Optional: true, + Computed: true, ValidateFunc: azure.ValidateResourceID, }, }, }, }, - "hybrid_connection_endpoint": { + "service_bus_queue_endpoint_id": { + Type: schema.TypeString, + Optional: true, + ConflictsWith: utils.RemoveFromStringArray(enpointPropertyNames(), "service_bus_queue_endpoint_id"), + ValidateFunc: azure.ValidateResourceID, + }, + + "service_bus_topic_endpoint_id": { + Type: schema.TypeString, + Optional: true, + ConflictsWith: utils.RemoveFromStringArray(enpointPropertyNames(), "service_bus_topic_endpoint_id"), + ValidateFunc: azure.ValidateResourceID, + }, + + "storage_queue_endpoint": { Type: schema.TypeList, MaxItems: 1, Optional: true, - ConflictsWith: utils.RemoveFromStringArray(getEnpointTypes(), "hybrid_connection_endpoint"), + ConflictsWith: utils.RemoveFromStringArray(enpointPropertyNames(), "storage_queue_endpoint"), Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "hybrid_connection_id": { + "storage_account_id": { Type: schema.TypeString, Required: true, ValidateFunc: azure.ValidateResourceID, }, + "queue_name": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.StringIsNotEmpty, + }, }, }, }, @@ -132,7 +184,7 @@ func resourceArmEventGridEventSubscription() *schema.Resource { Type: schema.TypeList, MaxItems: 1, Optional: true, - ConflictsWith: utils.RemoveFromStringArray(getEnpointTypes(), "webhook_endpoint"), + ConflictsWith: utils.RemoveFromStringArray(enpointPropertyNames(), "webhook_endpoint"), Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "url": { @@ -251,11 +303,16 @@ func resourceArmEventGridEventSubscriptionCreateUpdate(d *schema.ResourceData, m destination := expandEventGridEventSubscriptionDestination(d) if destination == nil { - return fmt.Errorf("One of the following endpoint types must be specificed to create an EventGrid Event Subscription: %q", getEnpointTypes()) + return fmt.Errorf("One of the following endpoint types must be specificed to create an EventGrid Event Subscription: %q", enpointPropertyNames()) } filter := expandEventGridEventSubscriptionFilter(d) + expirationTime, err := expandEventGridExpirationTime(d) + if err != nil { + return fmt.Errorf("Error creating/updating EventGrid Event Subscription %q (Scope %q): %s", name, scope, err) + } + eventSubscriptionProperties := eventgrid.EventSubscriptionProperties{ Destination: destination, Filter: filter, @@ -263,6 +320,7 @@ func resourceArmEventGridEventSubscriptionCreateUpdate(d *schema.ResourceData, m RetryPolicy: expandEventGridEventSubscriptionRetryPolicy(d), Labels: utils.ExpandStringSlice(d.Get("labels").([]interface{})), EventDeliverySchema: eventgrid.EventDeliverySchema(d.Get("event_delivery_schema").(string)), + ExpirationTimeUtc: expirationTime, } eventSubscription := eventgrid.EventSubscription{ @@ -318,25 +376,47 @@ func resourceArmEventGridEventSubscriptionRead(d *schema.ResourceData, meta inte d.Set("scope", id.Scope) if props := resp.EventSubscriptionProperties; props != nil { + if props.ExpirationTimeUtc != nil { + d.Set("expiration_time_utc", props.ExpirationTimeUtc.Format(time.RFC3339)) + } + d.Set("event_delivery_schema", string(props.EventDeliverySchema)) if props.Topic != nil && *props.Topic != "" { d.Set("topic_name", props.Topic) } - if storageQueueEndpoint, ok := props.Destination.AsStorageQueueEventSubscriptionDestination(); ok { - if err := d.Set("storage_queue_endpoint", flattenEventGridEventSubscriptionStorageQueueEndpoint(storageQueueEndpoint)); err != nil { - return fmt.Errorf("Error setting `storage_queue_endpoint` for EventGrid Event Subscription %q (Scope %q): %s", id.Name, id.Scope, err) + if v, ok := props.Destination.AsEventHubEventSubscriptionDestination(); ok { + if err := d.Set("eventhub_endpoint_id", v.ResourceID); err != nil { + return fmt.Errorf("Error setting `%q` for EventGrid Event Subscription %q (Scope %q): %s", "eventhub_endpoint_id", id.Name, id.Scope, err) + } + + if err := d.Set("eventhub_endpoint", flattenEventGridEventSubscriptionEventhubEndpoint(v)); err != nil { + return fmt.Errorf("Error setting `%q` for EventGrid Event Subscription %q (Scope %q): %s", "eventhub_endpoint", id.Name, id.Scope, err) + } + } + if v, ok := props.Destination.AsHybridConnectionEventSubscriptionDestination(); ok { + if err := d.Set("hybrid_connection_endpoint_id", v.ResourceID); err != nil { + return fmt.Errorf("Error setting `%q` for EventGrid Event Subscription %q (Scope %q): %s", "hybrid_connection_endpoint_id", id.Name, id.Scope, err) + } + + if err := d.Set("hybrid_connection_endpoint", flattenEventGridEventSubscriptionHybridConnectionEndpoint(v)); err != nil { + return fmt.Errorf("Error setting `%q` for EventGrid Event Subscription %q (Scope %q): %s", "hybrid_connection_endpoint", id.Name, id.Scope, err) } } - if eventHubEndpoint, ok := props.Destination.AsEventHubEventSubscriptionDestination(); ok { - if err := d.Set("eventhub_endpoint", flattenEventGridEventSubscriptionEventHubEndpoint(eventHubEndpoint)); err != nil { - return fmt.Errorf("Error setting `eventhub_endpoint` for EventGrid Event Subscription %q (Scope %q): %s", id.Name, id.Scope, err) + if serviceBusQueueEndpoint, ok := props.Destination.AsServiceBusQueueEventSubscriptionDestination(); ok { + if err := d.Set("service_bus_queue_endpoint_id", serviceBusQueueEndpoint.ResourceID); err != nil { + return fmt.Errorf("Error setting `%q` for EventGrid Event Subscription %q (Scope %q): %s", "service_bus_queue_endpoint_id", id.Name, id.Scope, err) } } - if hybridConnectionEndpoint, ok := props.Destination.AsHybridConnectionEventSubscriptionDestination(); ok { - if err := d.Set("hybrid_connection_endpoint", flattenEventGridEventSubscriptionHybridConnectionEndpoint(hybridConnectionEndpoint)); err != nil { - return fmt.Errorf("Error setting `hybrid_connection_endpoint` for EventGrid Event Subscription %q (Scope %q): %s", id.Name, id.Scope, err) + if serviceBusTopicEndpoint, ok := props.Destination.AsServiceBusTopicEventSubscriptionDestination(); ok { + if err := d.Set("service_bus_topic_endpoint_id", serviceBusTopicEndpoint.ResourceID); err != nil { + return fmt.Errorf("Error setting `%q` for EventGrid Event Subscription %q (Scope %q): %s", "service_bus_topic_endpoint_id", id.Name, id.Scope, err) + } + } + if v, ok := props.Destination.AsStorageQueueEventSubscriptionDestination(); ok { + if err := d.Set("storage_queue_endpoint", flattenEventGridEventSubscriptionStorageQueueEndpoint(v)); err != nil { + return fmt.Errorf("Error setting `%q` for EventGrid Event Subscription %q (Scope %q): %s", "storage_queue_endpoint", id.Name, id.Scope, err) } } if _, ok := props.Destination.AsWebHookEventSubscriptionDestination(); ok { @@ -345,7 +425,7 @@ func resourceArmEventGridEventSubscriptionRead(d *schema.ResourceData, meta inte return fmt.Errorf("Error making Read request on EventGrid Event Subscription full URL '%s': %+v", id.Name, err) } if err := d.Set("webhook_endpoint", flattenEventGridEventSubscriptionWebhookEndpoint(&fullURL)); err != nil { - return fmt.Errorf("Error setting `webhook_endpoint` for EventGrid Event Subscription %q (Scope %q): %s", id.Name, id.Scope, err) + return fmt.Errorf("Error setting `%q` for EventGrid Event Subscription %q (Scope %q): %s", "webhook_endpoint", id.Name, id.Scope, err) } } @@ -406,19 +486,68 @@ func resourceArmEventGridEventSubscriptionDelete(d *schema.ResourceData, meta in return nil } -func expandEventGridEventSubscriptionDestination(d *schema.ResourceData) eventgrid.BasicEventSubscriptionDestination { - if _, ok := d.GetOk("storage_queue_endpoint"); ok { - return expandEventGridEventSubscriptionStorageQueueEndpoint(d) +func expandEventGridExpirationTime(d *schema.ResourceData) (*date.Time, error) { + if expirationTimeUtc, ok := d.GetOk("expiration_time_utc"); ok { + if expirationTimeUtc == "" { + return nil, nil + } + + parsedExpirationTimeUtc, err := date.ParseTime(time.RFC3339, expirationTimeUtc.(string)) + if err != nil { + return nil, err + } + + return &date.Time{Time: parsedExpirationTimeUtc}, nil } - if _, ok := d.GetOk("eventhub_endpoint"); ok { - return expandEventGridEventSubscriptionEventHubEndpoint(d) + return nil, nil +} + +func expandEventGridEventSubscriptionDestination(d *schema.ResourceData) eventgrid.BasicEventSubscriptionDestination { + if v, ok := d.GetOk("eventhub_endpoint_id"); ok { + return &eventgrid.EventHubEventSubscriptionDestination{ + EndpointType: eventgrid.EndpointTypeEventHub, + EventHubEventSubscriptionDestinationProperties: &eventgrid.EventHubEventSubscriptionDestinationProperties{ + ResourceID: utils.String(v.(string)), + }, + } + } else if _, ok := d.GetOk("eventhub_endpoint"); ok { + return expandEventGridEventSubscriptionEventhubEndpoint(d) } - if _, ok := d.GetOk("hybrid_connection_endpoint"); ok { + if v, ok := d.GetOk("hybrid_connection_endpoint_id"); ok { + return &eventgrid.HybridConnectionEventSubscriptionDestination{ + EndpointType: eventgrid.EndpointTypeHybridConnection, + HybridConnectionEventSubscriptionDestinationProperties: &eventgrid.HybridConnectionEventSubscriptionDestinationProperties{ + ResourceID: utils.String(v.(string)), + }, + } + } else if _, ok := d.GetOk("hybrid_connection_endpoint"); ok { return expandEventGridEventSubscriptionHybridConnectionEndpoint(d) } + if v, ok := d.GetOk("service_bus_queue_endpoint_id"); ok { + return &eventgrid.ServiceBusQueueEventSubscriptionDestination{ + EndpointType: eventgrid.EndpointTypeServiceBusQueue, + ServiceBusQueueEventSubscriptionDestinationProperties: &eventgrid.ServiceBusQueueEventSubscriptionDestinationProperties{ + ResourceID: utils.String(v.(string)), + }, + } + } + + if v, ok := d.GetOk("service_bus_topic_endpoint_id"); ok { + return &eventgrid.ServiceBusTopicEventSubscriptionDestination{ + EndpointType: eventgrid.EndpointTypeServiceBusTopic, + ServiceBusTopicEventSubscriptionDestinationProperties: &eventgrid.ServiceBusTopicEventSubscriptionDestinationProperties{ + ResourceID: utils.String(v.(string)), + }, + } + } + + if _, ok := d.GetOk("storage_queue_endpoint"); ok { + return expandEventGridEventSubscriptionStorageQueueEndpoint(d) + } + if _, ok := d.GetOk("webhook_endpoint"); ok { return expandEventGridEventSubscriptionWebhookEndpoint(d) } @@ -431,53 +560,49 @@ func expandEventGridEventSubscriptionStorageQueueEndpoint(d *schema.ResourceData storageAccountID := props["storage_account_id"].(string) queueName := props["queue_name"].(string) - storageQueueEndpoint := eventgrid.StorageQueueEventSubscriptionDestination{ + return eventgrid.StorageQueueEventSubscriptionDestination{ EndpointType: eventgrid.EndpointTypeStorageQueue, StorageQueueEventSubscriptionDestinationProperties: &eventgrid.StorageQueueEventSubscriptionDestinationProperties{ ResourceID: &storageAccountID, QueueName: &queueName, }, } - return storageQueueEndpoint } -func expandEventGridEventSubscriptionEventHubEndpoint(d *schema.ResourceData) eventgrid.BasicEventSubscriptionDestination { +func expandEventGridEventSubscriptionEventhubEndpoint(d *schema.ResourceData) eventgrid.BasicEventSubscriptionDestination { props := d.Get("eventhub_endpoint").([]interface{})[0].(map[string]interface{}) eventHubID := props["eventhub_id"].(string) - eventHubEndpoint := eventgrid.EventHubEventSubscriptionDestination{ + return eventgrid.EventHubEventSubscriptionDestination{ EndpointType: eventgrid.EndpointTypeEventHub, EventHubEventSubscriptionDestinationProperties: &eventgrid.EventHubEventSubscriptionDestinationProperties{ ResourceID: &eventHubID, }, } - return eventHubEndpoint } func expandEventGridEventSubscriptionHybridConnectionEndpoint(d *schema.ResourceData) eventgrid.BasicEventSubscriptionDestination { props := d.Get("hybrid_connection_endpoint").([]interface{})[0].(map[string]interface{}) hybridConnectionID := props["hybrid_connection_id"].(string) - hybridConnectionEndpoint := eventgrid.HybridConnectionEventSubscriptionDestination{ + return eventgrid.HybridConnectionEventSubscriptionDestination{ EndpointType: eventgrid.EndpointTypeHybridConnection, HybridConnectionEventSubscriptionDestinationProperties: &eventgrid.HybridConnectionEventSubscriptionDestinationProperties{ ResourceID: &hybridConnectionID, }, } - return hybridConnectionEndpoint } func expandEventGridEventSubscriptionWebhookEndpoint(d *schema.ResourceData) eventgrid.BasicEventSubscriptionDestination { props := d.Get("webhook_endpoint").([]interface{})[0].(map[string]interface{}) url := props["url"].(string) - webhookEndpoint := eventgrid.WebHookEventSubscriptionDestination{ + return eventgrid.WebHookEventSubscriptionDestination{ EndpointType: eventgrid.EndpointTypeWebHook, WebHookEventSubscriptionDestinationProperties: &eventgrid.WebHookEventSubscriptionDestinationProperties{ EndpointURL: &url, }, } - return webhookEndpoint } func expandEventGridEventSubscriptionFilter(d *schema.ResourceData) *eventgrid.EventSubscriptionFilter { @@ -514,6 +639,7 @@ func expandEventGridEventSubscriptionStorageBlobDeadLetterDestination(d *schema. }, } } + return nil } @@ -527,26 +653,24 @@ func expandEventGridEventSubscriptionRetryPolicy(d *schema.ResourceData) *eventg EventTimeToLiveInMinutes: utils.Int32(int32(eventTimeToLive)), } } + return nil } -func flattenEventGridEventSubscriptionStorageQueueEndpoint(input *eventgrid.StorageQueueEventSubscriptionDestination) []interface{} { +func flattenEventGridEventSubscriptionEventhubEndpoint(input *eventgrid.EventHubEventSubscriptionDestination) []interface{} { if input == nil { return nil } result := make(map[string]interface{}) if input.ResourceID != nil { - result["storage_account_id"] = *input.ResourceID - } - if input.QueueName != nil { - result["queue_name"] = *input.QueueName + result["eventhub_id"] = *input.ResourceID } return []interface{}{result} } -func flattenEventGridEventSubscriptionEventHubEndpoint(input *eventgrid.EventHubEventSubscriptionDestination) []interface{} { +func flattenEventGridEventSubscriptionHybridConnectionEndpoint(input *eventgrid.HybridConnectionEventSubscriptionDestination) []interface{} { if input == nil { return nil } @@ -559,14 +683,17 @@ func flattenEventGridEventSubscriptionEventHubEndpoint(input *eventgrid.EventHub return []interface{}{result} } -func flattenEventGridEventSubscriptionHybridConnectionEndpoint(input *eventgrid.HybridConnectionEventSubscriptionDestination) []interface{} { +func flattenEventGridEventSubscriptionStorageQueueEndpoint(input *eventgrid.StorageQueueEventSubscriptionDestination) []interface{} { if input == nil { return nil } result := make(map[string]interface{}) if input.ResourceID != nil { - result["eventhub_id"] = *input.ResourceID + result["storage_account_id"] = *input.ResourceID + } + if input.QueueName != nil { + result["queue_name"] = *input.QueueName } return []interface{}{result} diff --git a/azurerm/internal/services/eventgrid/tests/eventgrid_event_subscription_resource_test.go b/azurerm/internal/services/eventgrid/tests/eventgrid_event_subscription_resource_test.go index 32ef7d96271e..dea09dffd18b 100644 --- a/azurerm/internal/services/eventgrid/tests/eventgrid_event_subscription_resource_test.go +++ b/azurerm/internal/services/eventgrid/tests/eventgrid_event_subscription_resource_test.go @@ -32,7 +32,7 @@ func TestAccAzureRMEventGridEventSubscription_basic(t *testing.T) { }) } -func TestAccAzureRMEventGridEventSubscription_eventhub(t *testing.T) { +func TestAccAzureRMEventGridEventSubscription_requiresImport(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_eventgrid_event_subscription", "test") resource.ParallelTest(t, resource.TestCase{ @@ -41,11 +41,75 @@ func TestAccAzureRMEventGridEventSubscription_eventhub(t *testing.T) { CheckDestroy: testCheckAzureRMEventGridEventSubscriptionDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMEventGridEventSubscription_eventhub(data), + Config: testAccAzureRMEventGridEventSubscription_basic(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMEventGridEventSubscriptionExists(data.ResourceName), + ), + }, + { + Config: testAccAzureRMEventGridEventSubscription_requiresImport(data), + ExpectError: acceptance.RequiresImportError("azurerm_eventgrid_event_subscription"), + }, + }, + }) +} + +func TestAccAzureRMEventGridEventSubscription_eventHubID(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_eventgrid_event_subscription", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMEventGridEventSubscriptionDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMEventGridEventSubscription_eventHubID(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMEventGridEventSubscriptionExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "event_delivery_schema", "CloudEventSchemaV1_0"), + resource.TestCheckResourceAttrSet(data.ResourceName, "eventhub_endpoint_id"), + ), + }, + data.ImportStep(), + }, + }) +} + +func TestAccAzureRMEventGridEventSubscription_serviceBusQueueID(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_eventgrid_event_subscription", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMEventGridEventSubscriptionDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMEventGridEventSubscription_serviceBusQueueID(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMEventGridEventSubscriptionExists(data.ResourceName), resource.TestCheckResourceAttr(data.ResourceName, "event_delivery_schema", "CloudEventSchemaV1_0"), - resource.TestCheckResourceAttr(data.ResourceName, "eventhub_endpoint.#", "1"), + resource.TestCheckResourceAttrSet(data.ResourceName, "service_bus_queue_endpoint_id"), + ), + }, + data.ImportStep(), + }, + }) +} + +func TestAccAzureRMEventGridEventSubscription_serviceBusTopicID(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_eventgrid_event_subscription", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMEventGridEventSubscriptionDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMEventGridEventSubscription_serviceBusTopicID(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMEventGridEventSubscriptionExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "event_delivery_schema", "CloudEventSchemaV1_0"), + resource.TestCheckResourceAttrSet(data.ResourceName, "service_bus_topic_endpoint_id"), ), }, data.ImportStep(), @@ -68,7 +132,7 @@ func TestAccAzureRMEventGridEventSubscription_update(t *testing.T) { resource.TestCheckResourceAttr(data.ResourceName, "event_delivery_schema", "EventGridSchema"), resource.TestCheckResourceAttr(data.ResourceName, "storage_queue_endpoint.#", "1"), resource.TestCheckResourceAttr(data.ResourceName, "storage_blob_dead_letter_destination.#", "1"), - resource.TestCheckResourceAttr(data.ResourceName, "included_event_types.0", "All"), + resource.TestCheckResourceAttr(data.ResourceName, "included_event_types.0", "Microsoft.Resources.ResourceWriteSuccess"), resource.TestCheckResourceAttr(data.ResourceName, "retry_policy.0.max_delivery_attempts", "11"), resource.TestCheckResourceAttr(data.ResourceName, "retry_policy.0.event_time_to_live", "11"), resource.TestCheckResourceAttr(data.ResourceName, "labels.0", "test"), @@ -182,7 +246,7 @@ provider "azurerm" { } resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" + name = "acctestRG-eg-%d" location = "%s" } @@ -243,6 +307,18 @@ resource "azurerm_eventgrid_event_subscription" "test" { `, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomInteger, data.RandomInteger) } +func testAccAzureRMEventGridEventSubscription_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMEventGridEventSubscription_basic(data) + return fmt.Sprintf(` +%s + +resource "azurerm_eventgrid_event_subscription" "import" { + name = azurerm_eventgrid_event_subscription.test.name + scope = azurerm_eventgrid_event_subscription.test.scope +} +`, template) +} + func testAccAzureRMEventGridEventSubscription_update(data acceptance.TestData) string { return fmt.Sprintf(` provider "azurerm" { @@ -250,7 +326,7 @@ provider "azurerm" { } resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" + name = "acctestRG-eg-%d" location = "%s" } @@ -288,7 +364,7 @@ resource "azurerm_storage_blob" "test" { } resource "azurerm_eventgrid_event_subscription" "test" { - name = "acctesteg-%d" + name = "acctest-eg-%d" scope = azurerm_resource_group.test.id storage_queue_endpoint { @@ -317,14 +393,14 @@ resource "azurerm_eventgrid_event_subscription" "test" { `, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMEventGridEventSubscription_eventhub(data acceptance.TestData) string { +func testAccAzureRMEventGridEventSubscription_eventHubID(data acceptance.TestData) string { return fmt.Sprintf(` provider "azurerm" { features {} } resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" + name = "acctestRG-eg-%d" location = "%s" } @@ -344,13 +420,72 @@ resource "azurerm_eventhub" "test" { } resource "azurerm_eventgrid_event_subscription" "test" { - name = "acctesteg-%d" + name = "acctest-eg-%d" scope = azurerm_resource_group.test.id event_delivery_schema = "CloudEventSchemaV1_0" - eventhub_endpoint { - eventhub_id = azurerm_eventhub.test.id - } + eventhub_endpoint_id = azurerm_eventhub.test.id +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) +} + +func testAccAzureRMEventGridEventSubscription_serviceBusQueueID(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} +resource "azurerm_resource_group" "test" { + name = "acctestRG-eg-%d" + location = "%s" +} + +resource "azurerm_servicebus_namespace" "example" { + name = "acctestservicebusnamespace-%d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + sku = "Basic" +} +resource "azurerm_servicebus_queue" "test" { + name = "acctestservicebusqueue-%d" + resource_group_name = azurerm_resource_group.test.name + namespace_name = azurerm_servicebus_namespace.example.name + enable_partitioning = true +} +resource "azurerm_eventgrid_event_subscription" "test" { + name = "acctest-eg-%d" + scope = azurerm_resource_group.test.id + event_delivery_schema = "CloudEventSchemaV1_0" + service_bus_queue_endpoint_id = azurerm_servicebus_queue.test.id +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) +} + +func testAccAzureRMEventGridEventSubscription_serviceBusTopicID(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} +resource "azurerm_resource_group" "test" { + name = "acctestRG-eg-%d" + location = "%s" +} +resource "azurerm_servicebus_namespace" "example" { + name = "acctestservicebusnamespace-%d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + sku = "Standard" +} +resource "azurerm_servicebus_topic" "test" { + name = "acctestservicebustopic-%d" + resource_group_name = azurerm_resource_group.test.name + namespace_name = azurerm_servicebus_namespace.example.name + enable_partitioning = true +} +resource "azurerm_eventgrid_event_subscription" "test" { + name = "acctest-eg-%d" + scope = azurerm_resource_group.test.id + event_delivery_schema = "CloudEventSchemaV1_0" + service_bus_topic_endpoint_id = azurerm_servicebus_topic.test.id } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } @@ -362,7 +497,7 @@ provider "azurerm" { } resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" + name = "acctestRG-eg-%d" location = "%s" } @@ -384,7 +519,7 @@ resource "azurerm_storage_queue" "test" { } resource "azurerm_eventgrid_event_subscription" "test" { - name = "acctesteg-%d" + name = "acctest-eg-%d" scope = "${azurerm_resource_group.test.id}" storage_queue_endpoint { diff --git a/website/docs/r/eventgrid_event_subscription.html.markdown b/website/docs/r/eventgrid_event_subscription.html.markdown index 0e6932d32fda..d9b3ded22ad1 100644 --- a/website/docs/r/eventgrid_event_subscription.html.markdown +++ b/website/docs/r/eventgrid_event_subscription.html.markdown @@ -55,17 +55,27 @@ The following arguments are supported: * `scope` - (Required) Specifies the scope at which the EventGrid Event Subscription should be created. Changing this forces a new resource to be created. +* `expiration_time_utc` - (Optional) Specifies the expiration time of the event subscription (Datetime Format `RFC 3339`). + * `event_delivery_schema` - (Optional) Specifies the event delivery schema for the event subscription. Possible values include: `EventGridSchema`, `CloudEventSchemaV1_0`, `CustomInputSchema`. Defaults to `EventGridSchema`. Changing this forces a new resource to be created. -* `storage_queue_endpoint` - (Optional) A `storage_queue_endpoint` block as defined below. +* `eventhub_endpoint` - (Optional / **Deprecated in favour of `eventhub_endpoint_id`**) A `eventhub_endpoint` block as defined below. + +* `eventhub_endpoint_id` - (Optional) Specifies the id where the Event Hub is located. + +* `hybrid_connection_endpoint` - (Optional / **Deprecated in favour of `hybrid_connection_endpoint_id`**) A `hybrid_connection_endpoint` block as defined below. -* `eventhub_endpoint` - (Optional) A `eventhub_endpoint` block as defined below. +* `hybrid_connection_endpoint_id` - (Optional) Specifies the id where the Hybrid Connection is located. -* `hybrid_connection_endpoint` - (Optional) A `hybrid_connection_endpoint` block as defined below. +* `service_bus_queue_endpoint_id` - (Optional) Specifies the id where the Service Bus Queue is located. + +* `service_bus_topic_endpoint_id` - (Optional) Specifies the id where the Service Bus Topic is located. + +* `storage_queue_endpoint` - (Optional) A `storage_queue_endpoint` block as defined below. * `webhook_endpoint` - (Optional) A `webhook_endpoint` block as defined below. -~> **NOTE:** One of `storage_queue_endpoint`, `eventhub_endpoint`, `hybrid_connection_endpoint` or `webhook_endpoint` must be specified. +~> **NOTE:** One of `eventhub_endpoint`, `eventhub_endpoint_id`, `hybrid_connection_endpoint`, `hybrid_connection_endpoint_id`, `service_bus_queue_endpoint_id`, `service_bus_topic_endpoint_id`, `storage_queue_endpoint` or `webhook_endpoint` must be specified. * `included_event_types` - (Optional) A list of applicable event types that need to be part of the event subscription. @@ -119,7 +129,7 @@ A `storage_blob_dead_letter_destination` supports the following: * `storage_account_id` - (Required) Specifies the id of the storage account id where the storage blob is located. -* `storage_blob_container_name` - (Required) Specifies the name of the Storage blob container that is the destination of the deadletter events +* `storage_blob_container_name` - (Required) Specifies the name of the Storage blob container that is the destination of the deadletter events. --- diff --git a/website/docs/r/iot_time_series_insights_standard_environment.html.markdown b/website/docs/r/iot_time_series_insights_standard_environment.html.markdown index 28d2cc78cb3b..5816abefae47 100644 --- a/website/docs/r/iot_time_series_insights_standard_environment.html.markdown +++ b/website/docs/r/iot_time_series_insights_standard_environment.html.markdown @@ -67,4 +67,4 @@ Azure IoT Time Series Insights Standard Environment can be imported using the `r ```shell terraform import azurerm_iot_time_series_environment.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/example/providers/Microsoft.TimeSeriesInsights/environments/example -``` \ No newline at end of file +```