From 23fd21637d4c8ff55d1677ef517e81e76079b5c0 Mon Sep 17 00:00:00 2001 From: Vladimir Lazarenko Date: Wed, 27 Oct 2021 11:01:29 +0200 Subject: [PATCH 1/4] New resource: `azurerm_iot_time_series_insights_event_source_eventhub` Fixes #13912 ``` $ TF_ACC=1 go test -v ./internal/services/iottimeseriesinsights -timeout=1000m -run='TestAccIoTTimeSeriesInsightsEventSourceEventhub' === RUN TestAccIoTTimeSeriesInsightsEventSourceEventhub_basic === PAUSE TestAccIoTTimeSeriesInsightsEventSourceEventhub_basic === RUN TestAccIoTTimeSeriesInsightsEventSourceEventhub_update === PAUSE TestAccIoTTimeSeriesInsightsEventSourceEventhub_update === CONT TestAccIoTTimeSeriesInsightsEventSourceEventhub_basic === CONT TestAccIoTTimeSeriesInsightsEventSourceEventhub_update --- PASS: TestAccIoTTimeSeriesInsightsEventSourceEventhub_basic (267.69s) --- PASS: TestAccIoTTimeSeriesInsightsEventSourceEventhub_update (368.87s) PASS ok github.com/hashicorp/terraform-provider-azurerm/internal/services/iottimeseriesinsights 370.345s ``` --- ...e_series_insights_event_source_eventhub.go | 233 ++++++++++++++++++ ...ies_insights_event_source_eventhub_test.go | 231 +++++++++++++++++ .../iottimeseriesinsights/registration.go | 11 +- ...sights_event_source_eventhub.html.markdown | 136 ++++++++++ 4 files changed, 606 insertions(+), 5 deletions(-) create mode 100644 internal/services/iottimeseriesinsights/iot_time_series_insights_event_source_eventhub.go create mode 100644 internal/services/iottimeseriesinsights/iot_time_series_insights_event_source_eventhub_test.go create mode 100644 website/docs/r/iot_time_series_insights_event_source_eventhub.html.markdown diff --git a/internal/services/iottimeseriesinsights/iot_time_series_insights_event_source_eventhub.go b/internal/services/iottimeseriesinsights/iot_time_series_insights_event_source_eventhub.go new file mode 100644 index 000000000000..457686228a92 --- /dev/null +++ b/internal/services/iottimeseriesinsights/iot_time_series_insights_event_source_eventhub.go @@ -0,0 +1,233 @@ +package iottimeseriesinsights + +import ( + "fmt" + "regexp" + "time" + + "github.com/Azure/azure-sdk-for-go/services/timeseriesinsights/mgmt/2020-05-15/timeseriesinsights" + "github.com/hashicorp/terraform-provider-azurerm/helpers/azure" + "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" + "github.com/hashicorp/terraform-provider-azurerm/internal/clients" + eventhubValidate "github.com/hashicorp/terraform-provider-azurerm/internal/services/eventhub/validate" + "github.com/hashicorp/terraform-provider-azurerm/internal/services/iottimeseriesinsights/parse" + "github.com/hashicorp/terraform-provider-azurerm/internal/tags" + "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" + "github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation" + "github.com/hashicorp/terraform-provider-azurerm/internal/timeouts" + "github.com/hashicorp/terraform-provider-azurerm/utils" +) + +func resourceIoTTimeSeriesInsightsEventSourceEventhub() *pluginsdk.Resource { + return &pluginsdk.Resource{ + Create: resourceIoTTimeSeriesInsightsEventSourceEventhubCreateUpdate, + Read: resourceIoTTimeSeriesInsightsEventSourceEventhubRead, + Update: resourceIoTTimeSeriesInsightsEventSourceEventhubCreateUpdate, + Delete: resourceIoTTimeSeriesInsightsEventSourceEventhubDelete, + Importer: pluginsdk.ImporterValidatingResourceId(func(id string) error { + _, err := parse.EventSourceID(id) + return err + }), + + Timeouts: &pluginsdk.ResourceTimeout{ + Create: pluginsdk.DefaultTimeout(30 * time.Minute), + Read: pluginsdk.DefaultTimeout(5 * time.Minute), + Update: pluginsdk.DefaultTimeout(30 * time.Minute), + Delete: pluginsdk.DefaultTimeout(30 * time.Minute), + }, + + Schema: map[string]*pluginsdk.Schema{ + "name": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validation.StringMatch( + regexp.MustCompile(`^[-\w\._\(\)]+$`), + "IoT Time Series Insights Event Source name must contain only word characters, periods, underscores, and parentheses.", + ), + }, + + "location": azure.SchemaLocation(), + + "environment_id": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: azure.ValidateResourceID, + }, + + "eventhub_name": { + Type: pluginsdk.TypeString, + Required: true, + ValidateFunc: eventhubValidate.ValidateEventHubName(), + }, + + "namespace_name": { + Type: pluginsdk.TypeString, + Required: true, + }, + + "shared_access_key": { + Type: pluginsdk.TypeString, + Required: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + + "consumer_group_name": { + Type: pluginsdk.TypeString, + Required: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + + "shared_access_key_name": { + Type: pluginsdk.TypeString, + Required: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + + "event_source_resource_id": { + Type: pluginsdk.TypeString, + Required: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + + "timestamp_property_name": { + Type: pluginsdk.TypeString, + Optional: true, + Computed: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + + "tags": tags.Schema(), + }, + } +} + +func resourceIoTTimeSeriesInsightsEventSourceEventhubCreateUpdate(d *pluginsdk.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).IoTTimeSeriesInsights.EventSourcesClient + ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d) + defer cancel() + + location := azure.NormalizeLocation(d.Get("location").(string)) + environmentID, err := parse.EnvironmentID(d.Get("environment_id").(string)) + if err != nil { + return fmt.Errorf("unable to parse `environment_id`: %+v", err) + } + + id := parse.NewEventSourceID(environmentID.SubscriptionId, environmentID.ResourceGroup, environmentID.Name, d.Get("name").(string)) + if d.IsNewResource() { + existing, err := client.Get(ctx, id.ResourceGroup, id.EnvironmentName, id.Name) + if err != nil { + if !utils.ResponseWasNotFound(existing.Response) { + return fmt.Errorf("checking for presence of existing IoT Time Series Insights Event Source %q: %s", id, err) + } + } + + if existing.Value != nil { + eventSource, ok := existing.Value.AsEventHubEventSourceResource() + if !ok { + return fmt.Errorf("exisiting resource was not an IoT Time Series Insights IoTHub Event Source %q", id) + } + + if eventSource.ID != nil && *eventSource.ID != "" { + return tf.ImportAsExistsError("azurerm_iot_time_series_insights_event_source_eventhub", *eventSource.ID) + } + } + } + + eventSource := timeseriesinsights.EventHubEventSourceCreateOrUpdateParameters{ + Location: &location, + Tags: tags.Expand(d.Get("tags").(map[string]interface{})), + EventHubEventSourceCreationProperties: ×eriesinsights.EventHubEventSourceCreationProperties{ + EventHubName: utils.String(d.Get("eventhub_name").(string)), + ServiceBusNamespace: utils.String(d.Get("namespace_name").(string)), + SharedAccessKey: utils.String(d.Get("shared_access_key").(string)), + ConsumerGroupName: utils.String(d.Get("consumer_group_name").(string)), + KeyName: utils.String(d.Get("shared_access_key_name").(string)), + EventSourceResourceID: utils.String(d.Get("event_source_resource_id").(string)), + TimestampPropertyName: utils.String(d.Get("timestamp_property_name").(string)), + }, + } + + _, err = client.CreateOrUpdate(ctx, id.ResourceGroup, id.EnvironmentName, id.Name, eventSource) + if err != nil { + return fmt.Errorf("creating/updating IoT Time Series Insights EventHub Event Source %q: %+v", id, err) + } + + resp, err := client.Get(ctx, id.ResourceGroup, id.EnvironmentName, id.Name) + if err != nil { + return fmt.Errorf("retrieving IoT Time Series Insights EventHub EventSource %q: %+v", id, err) + } + + _, ok := resp.Value.AsEventHubEventSourceResource() + if !ok { + return fmt.Errorf("created resource was not an IoT Time Series Insights EventHub Event Source %q", id) + } + + d.SetId(id.ID()) + + return resourceIoTTimeSeriesInsightsEventSourceEventhubRead(d, meta) +} + +func resourceIoTTimeSeriesInsightsEventSourceEventhubRead(d *pluginsdk.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).IoTTimeSeriesInsights.EventSourcesClient + ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) + defer cancel() + + id, err := parse.EventSourceID(d.Id()) + if err != nil { + return err + } + + resp, err := client.Get(ctx, id.ResourceGroup, id.EnvironmentName, id.Name) + if err != nil || resp.Value == nil { + if utils.ResponseWasNotFound(resp.Response) { + d.SetId("") + return nil + } + + return fmt.Errorf("retrieving IoT Time Series Insights EventHub EventSource %q: %+v", id, err) + } + + eventSource, ok := resp.Value.AsEventHubEventSourceResource() + if !ok { + return fmt.Errorf("exisiting resource was not a IoT Time Series Insights EventHub EventSource %q", id) + } + + d.Set("name", eventSource.Name) + d.Set("environment_id", parse.NewEnvironmentID(id.SubscriptionId, id.ResourceGroup, id.EnvironmentName).ID()) + if location := eventSource.Location; location != nil { + d.Set("location", azure.NormalizeLocation(*location)) + } + + if props := eventSource.EventHubEventSourceResourceProperties; props != nil { + d.Set("eventhub_name", props.EventHubName) + d.Set("namespace_name", props.ServiceBusNamespace) + d.Set("consumer_group_name", props.ConsumerGroupName) + d.Set("shared_access_key_name", props.KeyName) + d.Set("event_source_resource_id", props.EventSourceResourceID) + d.Set("timestamp_property_name", props.TimestampPropertyName) + } + + return tags.FlattenAndSet(d, eventSource.Tags) +} + +func resourceIoTTimeSeriesInsightsEventSourceEventhubDelete(d *pluginsdk.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).IoTTimeSeriesInsights.EventSourcesClient + ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) + defer cancel() + + id, err := parse.EventSourceID(d.Id()) + if err != nil { + return err + } + + response, err := client.Delete(ctx, id.ResourceGroup, id.EnvironmentName, id.Name) + if err != nil { + if !utils.ResponseWasNotFound(response) { + return fmt.Errorf("deleting IoT Time Series Insights EventHub Event Source %q: %+v", id, err) + } + } + + return nil +} diff --git a/internal/services/iottimeseriesinsights/iot_time_series_insights_event_source_eventhub_test.go b/internal/services/iottimeseriesinsights/iot_time_series_insights_event_source_eventhub_test.go new file mode 100644 index 000000000000..bfa54a855b26 --- /dev/null +++ b/internal/services/iottimeseriesinsights/iot_time_series_insights_event_source_eventhub_test.go @@ -0,0 +1,231 @@ +package iottimeseriesinsights_test + +import ( + "context" + "fmt" + "testing" + + "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance" + "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check" + "github.com/hashicorp/terraform-provider-azurerm/internal/clients" + "github.com/hashicorp/terraform-provider-azurerm/internal/services/iottimeseriesinsights/parse" + "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" + "github.com/hashicorp/terraform-provider-azurerm/utils" +) + +type IoTTimeSeriesInsightsEventSourceEventhubResource struct { +} + +func TestAccIoTTimeSeriesInsightsEventSourceEventhub_basic(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_iot_time_series_insights_event_source_eventhub", "test") + r := IoTTimeSeriesInsightsEventSourceEventhubResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.basic(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep("shared_access_key"), + }) +} + +func TestAccIoTTimeSeriesInsightsEventSourceEventhub_update(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_iot_time_series_insights_event_source_eventhub", "test") + r := IoTTimeSeriesInsightsEventSourceEventhubResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.basic(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep("shared_access_key"), + { + Config: r.update(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep("shared_access_key"), + { + Config: r.basic(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + }) +} + +func (IoTTimeSeriesInsightsEventSourceEventhubResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) { + id, err := parse.EventSourceID(state.ID) + if err != nil { + return nil, err + } + + resp, err := clients.IoTTimeSeriesInsights.EventSourcesClient.Get(ctx, id.ResourceGroup, id.EnvironmentName, id.Name) + if err != nil { + return nil, fmt.Errorf("retrieving IoT Time Series Insights EventSource Eventhub (%q): %+v", id.String(), err) + } + + return utils.Bool(!utils.ResponseWasNotFound(resp.Response)), nil +} + +func (IoTTimeSeriesInsightsEventSourceEventhubResource) basic(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} +resource "azurerm_resource_group" "test" { + name = "acctestRG-tsi-%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 = "Standard" +} + +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 + message_retention = 7 +} + +resource "azurerm_eventhub_consumer_group" "test" { + name = "acctesteventhubcg-%d" + namespace_name = azurerm_eventhub_namespace.test.name + eventhub_name = azurerm_eventhub.test.name + resource_group_name = azurerm_resource_group.test.name +} + +resource "azurerm_eventhub_authorization_rule" "test" { + name = "acctest-%d" + namespace_name = azurerm_eventhub_namespace.test.name + eventhub_name = azurerm_eventhub.test.name + resource_group_name = azurerm_resource_group.test.name + + listen = true + send = false + manage = false +} + +resource "azurerm_storage_account" "storage" { + name = "acctestsatsi%s" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + account_tier = "Standard" + account_replication_type = "LRS" +} + +resource "azurerm_iot_time_series_insights_gen2_environment" "test" { + name = "acctest_tsie%d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + sku_name = "L1" + id_properties = ["id"] + + storage { + name = azurerm_storage_account.storage.name + key = azurerm_storage_account.storage.primary_access_key + } +} + +resource "azurerm_iot_time_series_insights_event_source_eventhub" "test" { + name = "acctest_tsiesi%d" + location = azurerm_resource_group.test.location + environment_id = azurerm_iot_time_series_insights_gen2_environment.test.id + eventhub_name = azurerm_eventhub.test.name + namespace_name = azurerm_eventhub_namespace.test.name + shared_access_key = azurerm_eventhub_authorization_rule.test.primary_key + shared_access_key_name = azurerm_eventhub_authorization_rule.test.name + consumer_group_name = azurerm_eventhub_consumer_group.test.name + event_source_resource_id = azurerm_eventhub.test.id +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomString, data.RandomInteger, data.RandomInteger) +} + +func (IoTTimeSeriesInsightsEventSourceEventhubResource) update(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} +resource "azurerm_resource_group" "test" { + name = "acctestRG-tsi-%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 = "Standard" +} + +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 + message_retention = 7 +} + +resource "azurerm_eventhub_consumer_group" "test" { + name = "acctesteventhubcg-%d" + namespace_name = azurerm_eventhub_namespace.test.name + eventhub_name = azurerm_eventhub.test.name + resource_group_name = azurerm_resource_group.test.name +} + +resource "azurerm_eventhub_authorization_rule" "test" { + name = "acctest-%d" + namespace_name = azurerm_eventhub_namespace.test.name + eventhub_name = azurerm_eventhub.test.name + resource_group_name = azurerm_resource_group.test.name + + listen = true + send = false + manage = false +} + +resource "azurerm_storage_account" "storage" { + name = "acctestsatsi%s" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + account_tier = "Standard" + account_replication_type = "LRS" +} + +resource "azurerm_iot_time_series_insights_gen2_environment" "test" { + name = "acctest_tsie%d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + sku_name = "L1" + id_properties = ["id"] + + storage { + name = azurerm_storage_account.storage.name + key = azurerm_storage_account.storage.primary_access_key + } +} + +resource "azurerm_iot_time_series_insights_event_source_eventhub" "test" { + name = "acctest_tsiesi%d" + location = azurerm_resource_group.test.location + environment_id = azurerm_iot_time_series_insights_gen2_environment.test.id + eventhub_name = azurerm_eventhub.test.name + namespace_name = azurerm_eventhub_namespace.test.name + shared_access_key = azurerm_eventhub_authorization_rule.test.primary_key + shared_access_key_name = azurerm_eventhub_authorization_rule.test.name + consumer_group_name = azurerm_eventhub_consumer_group.test.name + event_source_resource_id = azurerm_eventhub.test.id + timestamp_property_name = "test" +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomString, data.RandomInteger, data.RandomInteger) +} diff --git a/internal/services/iottimeseriesinsights/registration.go b/internal/services/iottimeseriesinsights/registration.go index 460bb3c121ea..6ca0a4aab3cd 100644 --- a/internal/services/iottimeseriesinsights/registration.go +++ b/internal/services/iottimeseriesinsights/registration.go @@ -26,10 +26,11 @@ func (r Registration) SupportedDataSources() map[string]*pluginsdk.Resource { // SupportedResources returns the supported Resources supported by this Service func (r Registration) SupportedResources() map[string]*pluginsdk.Resource { return map[string]*pluginsdk.Resource{ - "azurerm_iot_time_series_insights_access_policy": resourceIoTTimeSeriesInsightsAccessPolicy(), - "azurerm_iot_time_series_insights_event_source_iothub": resourceIoTTimeSeriesInsightsEventSourceIoTHub(), - "azurerm_iot_time_series_insights_standard_environment": resourceIoTTimeSeriesInsightsStandardEnvironment(), - "azurerm_iot_time_series_insights_gen2_environment": resourceIoTTimeSeriesInsightsGen2Environment(), - "azurerm_iot_time_series_insights_reference_data_set": resourceIoTTimeSeriesInsightsReferenceDataSet(), + "azurerm_iot_time_series_insights_access_policy": resourceIoTTimeSeriesInsightsAccessPolicy(), + "azurerm_iot_time_series_insights_event_source_eventhub": resourceIoTTimeSeriesInsightsEventSourceEventhub(), + "azurerm_iot_time_series_insights_event_source_iothub": resourceIoTTimeSeriesInsightsEventSourceIoTHub(), + "azurerm_iot_time_series_insights_standard_environment": resourceIoTTimeSeriesInsightsStandardEnvironment(), + "azurerm_iot_time_series_insights_gen2_environment": resourceIoTTimeSeriesInsightsGen2Environment(), + "azurerm_iot_time_series_insights_reference_data_set": resourceIoTTimeSeriesInsightsReferenceDataSet(), } } diff --git a/website/docs/r/iot_time_series_insights_event_source_eventhub.html.markdown b/website/docs/r/iot_time_series_insights_event_source_eventhub.html.markdown new file mode 100644 index 000000000000..287c4029ed2e --- /dev/null +++ b/website/docs/r/iot_time_series_insights_event_source_eventhub.html.markdown @@ -0,0 +1,136 @@ +--- +subcategory: "Time Series Insights" +layout: "azurerm" +page_title: "Azure Resource Manager: azurerm_iot_time_series_insights_event_source_eventhub" +description: |- + Manages an Azure IoT Time Series Insights EventHub Event Source. +--- + +# azurerm_time_series_insights_event_source_eventhub + +Manages an Azure IoT Time Series Insights EventHub Event Source. + +## Example Usage + +```hcl +resource "azurerm_resource_group" "example" { + name = "example" + location = "West Europe" +} + +resource "azurerm_eventhub_namespace" "example" { + name = "example" + location = azurerm_resource_group.example.location + resource_group_name = azurerm_resource_group.example.name + sku = "Standard" +} + +resource "azurerm_eventhub" "example" { + name = "example" + namespace_name = azurerm_eventhub_namespace.example.name + resource_group_name = azurerm_resource_group.example.name + partition_count = 2 + message_retention = 7 +} + +resource "azurerm_eventhub_consumer_group" "example" { + name = "example" + namespace_name = azurerm_eventhub_namespace.example.name + eventhub_name = azurerm_eventhub.example.name + resource_group_name = azurerm_resource_group.example.name +} + +resource "azurerm_eventhub_authorization_rule" "example" { + name = "example" + namespace_name = azurerm_eventhub_namespace.example.name + eventhub_name = azurerm_eventhub.example.name + resource_group_name = azurerm_resource_group.example.name + + listen = true + send = false + manage = false +} + +resource "azurerm_storage_account" "example" { + name = "example" + location = azurerm_resource_group.example.location + resource_group_name = azurerm_resource_group.example.name + account_tier = "Standard" + account_replication_type = "LRS" +} + +resource "azurerm_iot_time_series_insights_gen2_environment" "example" { + name = "example" + location = azurerm_resource_group.example.location + resource_group_name = azurerm_resource_group.example.name + sku_name = "L1" + id_properties = ["id"] + + storage { + name = azurerm_storage_account.example.name + key = azurerm_storage_account.example.primary_access_key + } +} + +resource "azurerm_iot_time_series_insights_event_source_eventhub" "example" { + name = "example" + location = azurerm_resource_group.example.location + environment_id = azurerm_iot_time_series_insights_gen2_environment.example.id + eventhub_name = azurerm_eventhub.example.name + namespace_name = azurerm_eventhub_namespace.example.name + shared_access_key = azurerm_eventhub_authorization_rule.example.primary_key + shared_access_key_name = azurerm_eventhub_authorization_rule.example.name + consumer_group_name = azurerm_eventhub_consumer_group.example.name + event_source_resource_id = azurerm_eventhub.example.id +} + +``` + +## Argument Reference + +The following arguments are supported: + +* `name` - (Required) Specifies the name of the Azure IoT Time Series Insights EventHub Event Source. Changing this forces a new resource to be created. Must be globally unique. + +* `environment_id` - (Required) Specifies the id of the IoT Time Series Insights Environment that the Event Source should be associated with. Changing this forces a new resource to created. + +* `location` - (Required) Specifies the supported Azure location where the resource exists. Changing this forces a new resource to be created. + +* `eventhub_name` - (Required) Specifies the name of the EventHub which will be associated with this resource. + +* `consumer_group_name` - (Required) Specifies the name of the EventHub Consumer Group that holds the partitions from which events will be read. + +* `event_source_resource_id` - (Required) Specifies the resource id where events will be coming from. + +* `namespace_name` - (Required) Specifies the EventHub Namespace name. + +* `shared_access_key_name` - (Required) Specifies the name of the Shared Access key that grants the Event Source access to the EventHub. + +* `shared_access_key` - (Required) Specifies the value of the Shared Access Policy key that grants the Time Series Insights service read access to the EventHub. + +* `timestamp_property_name` - (Optional) Specifies the value that will be used as the event source's timestamp. This value defaults to the event creation time. + +* `tags` - (Optional) A mapping of tags to assign to the resource. + +## Attributes Reference + +The following attributes are exported: + +* `id` - The ID of the IoT Time Series Insights EventHub Event Source. + +## Timeouts + +The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/docs/configuration/resources.html#timeouts) for certain actions: + +* `create` - (Defaults to 30 minutes) Used when creating the IoT Time Series Insights EventHub Event Source. +* `update` - (Defaults to 30 minutes) Used when updating the IoT Time Series Insights EventHub Event Source. +* `read` - (Defaults to 5 minutes) Used when retrieving the IoT Time Series Insights EventHub Event Source. +* `delete` - (Defaults to 30 minutes) Used when deleting the IoT Time Series Insights EventHub Event Source. + +## Import + +Azure IoT Time Series Insights EventHub Event Source can be imported using the `resource id`, e.g. + +```shell +terraform import azurerm_iot_time_series_insights_event_source_eventhub.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/example/providers/Microsoft.TimeSeriesInsights/environments/environment1/eventSources/example +``` From 756b6e5dc54992f7dcaca3458670933396872c3b Mon Sep 17 00:00:00 2001 From: Vladimir Lazarenko Date: Wed, 27 Oct 2021 11:22:28 +0200 Subject: [PATCH 2/4] terrafmt --- .../iot_time_series_insights_event_source_eventhub_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/services/iottimeseriesinsights/iot_time_series_insights_event_source_eventhub_test.go b/internal/services/iottimeseriesinsights/iot_time_series_insights_event_source_eventhub_test.go index bfa54a855b26..d61bde2fa787 100644 --- a/internal/services/iottimeseriesinsights/iot_time_series_insights_event_source_eventhub_test.go +++ b/internal/services/iottimeseriesinsights/iot_time_series_insights_event_source_eventhub_test.go @@ -225,7 +225,7 @@ resource "azurerm_iot_time_series_insights_event_source_eventhub" "test" { shared_access_key_name = azurerm_eventhub_authorization_rule.test.name consumer_group_name = azurerm_eventhub_consumer_group.test.name event_source_resource_id = azurerm_eventhub.test.id - timestamp_property_name = "test" + timestamp_property_name = "test" } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomString, data.RandomInteger, data.RandomInteger) } From e2cd09e75418ad207c8c7686d66b954518f3c238 Mon Sep 17 00:00:00 2001 From: kt Date: Wed, 27 Oct 2021 14:52:58 -0700 Subject: [PATCH 3/4] Update internal/services/iottimeseriesinsights/iot_time_series_insights_event_source_eventhub.go --- .../iot_time_series_insights_event_source_eventhub.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/internal/services/iottimeseriesinsights/iot_time_series_insights_event_source_eventhub.go b/internal/services/iottimeseriesinsights/iot_time_series_insights_event_source_eventhub.go index 457686228a92..dd369d45d513 100644 --- a/internal/services/iottimeseriesinsights/iot_time_series_insights_event_source_eventhub.go +++ b/internal/services/iottimeseriesinsights/iot_time_series_insights_event_source_eventhub.go @@ -159,8 +159,7 @@ func resourceIoTTimeSeriesInsightsEventSourceEventhubCreateUpdate(d *pluginsdk.R return fmt.Errorf("retrieving IoT Time Series Insights EventHub EventSource %q: %+v", id, err) } - _, ok := resp.Value.AsEventHubEventSourceResource() - if !ok { + if _, ok := resp.Value.AsEventHubEventSourceResource(); !ok { return fmt.Errorf("created resource was not an IoT Time Series Insights EventHub Event Source %q", id) } From 1e9cdbbeae2afbc06b9ed9cddc50c3075adeb52d Mon Sep 17 00:00:00 2001 From: kt Date: Wed, 27 Oct 2021 14:53:02 -0700 Subject: [PATCH 4/4] Update internal/services/iottimeseriesinsights/iot_time_series_insights_event_source_eventhub.go --- .../iot_time_series_insights_event_source_eventhub.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/internal/services/iottimeseriesinsights/iot_time_series_insights_event_source_eventhub.go b/internal/services/iottimeseriesinsights/iot_time_series_insights_event_source_eventhub.go index dd369d45d513..92e6e6e97c2b 100644 --- a/internal/services/iottimeseriesinsights/iot_time_series_insights_event_source_eventhub.go +++ b/internal/services/iottimeseriesinsights/iot_time_series_insights_event_source_eventhub.go @@ -149,8 +149,7 @@ func resourceIoTTimeSeriesInsightsEventSourceEventhubCreateUpdate(d *pluginsdk.R }, } - _, err = client.CreateOrUpdate(ctx, id.ResourceGroup, id.EnvironmentName, id.Name, eventSource) - if err != nil { + if _, err = client.CreateOrUpdate(ctx, id.ResourceGroup, id.EnvironmentName, id.Name, eventSource); err != nil { return fmt.Errorf("creating/updating IoT Time Series Insights EventHub Event Source %q: %+v", id, err) }