From 0aa18841d2e6ed63339dc901591959a1dab1f230 Mon Sep 17 00:00:00 2001 From: royto Date: Thu, 14 Jan 2021 10:58:46 +0100 Subject: [PATCH] fix after reabse --- .../iothub/iothub_enrichment_resource.go | 2 +- .../iothub/iothub_enrichment_resource_test.go | 16 +- .../services/iothub/iothub_resource_test.go | 131 +++ .../internal/services/iothub/registration.go | 1 + .../iothub/tests/iothub_resource_test.go | 943 ------------------ 5 files changed, 141 insertions(+), 952 deletions(-) delete mode 100644 azurerm/internal/services/iothub/tests/iothub_resource_test.go diff --git a/azurerm/internal/services/iothub/iothub_enrichment_resource.go b/azurerm/internal/services/iothub/iothub_enrichment_resource.go index 47b32e7e38929..7680132f97866 100644 --- a/azurerm/internal/services/iothub/iothub_enrichment_resource.go +++ b/azurerm/internal/services/iothub/iothub_enrichment_resource.go @@ -18,7 +18,7 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) -func resourceArmIotHubEnrichment() *schema.Resource { +func resourceIotHubEnrichment() *schema.Resource { return &schema.Resource{ Create: resourceArmIotHubEnrichmentCreateUpdate, Read: resourceArmIotHubEnrichmentRead, diff --git a/azurerm/internal/services/iothub/iothub_enrichment_resource_test.go b/azurerm/internal/services/iothub/iothub_enrichment_resource_test.go index e5d894c294dc7..5551e146c8e5a 100644 --- a/azurerm/internal/services/iothub/iothub_enrichment_resource_test.go +++ b/azurerm/internal/services/iothub/iothub_enrichment_resource_test.go @@ -13,7 +13,7 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) -func TestAccAzureRMIotHubEnrichment_basic(t *testing.T) { +func TestAccIotHubEnrichment_basic(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_iothub_enrichment", "test") resource.ParallelTest(t, resource.TestCase{ @@ -32,7 +32,7 @@ func TestAccAzureRMIotHubEnrichment_basic(t *testing.T) { }) } -func TestAccAzureRMIotHubEnrichment_requiresImport(t *testing.T) { +func TestAccIotHubEnrichment_requiresImport(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_iothub_enrichment", "test") resource.ParallelTest(t, resource.TestCase{ @@ -54,7 +54,7 @@ func TestAccAzureRMIotHubEnrichment_requiresImport(t *testing.T) { }) } -func TestAccAzureRMIotHubEnrichment_update(t *testing.T) { +func TestAccIotHubEnrichment_update(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_iothub_enrichment", "test") resource.ParallelTest(t, resource.TestCase{ @@ -80,7 +80,7 @@ func TestAccAzureRMIotHubEnrichment_update(t *testing.T) { }) } -func testCheckAzureRMIotHubEnrichmentDestroy(s *terraform.State) error { +func testCheckIotHubEnrichmentDestroy(s *terraform.State) error { client := acceptance.AzureProvider.Meta().(*clients.Client).IoTHub.ResourceClient ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext @@ -119,7 +119,7 @@ func testCheckAzureRMIotHubEnrichmentDestroy(s *terraform.State) error { return nil } -func testCheckAzureRMIotHubEnrichmentExists(resourceName string) resource.TestCheckFunc { +func testCheckIotHubEnrichmentExists(resourceName string) resource.TestCheckFunc { return func(s *terraform.State) error { client := acceptance.AzureProvider.Meta().(*clients.Client).IoTHub.ResourceClient ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext @@ -164,7 +164,7 @@ func testCheckAzureRMIotHubEnrichmentExists(resourceName string) resource.TestCh } } -func testAccAzureRMIotHubEnrichment_requiresImport(data acceptance.TestData) string { +func testAccIotHubEnrichment_requiresImport(data acceptance.TestData) string { template := testAccAzureRMIotHubEnrichment_basic(data) return fmt.Sprintf(` %s @@ -180,7 +180,7 @@ resource "azurerm_iothub_enrichment" "import" { `, template) } -func testAccAzureRMIotHubEnrichment_basic(data acceptance.TestData) string { +func testAccIotHubEnrichment_basic(data acceptance.TestData) string { return fmt.Sprintf(` provider "azurerm" { features {} @@ -244,7 +244,7 @@ resource "azurerm_iothub_enrichment" "test" { `, data.RandomInteger, data.Locations.Primary, data.RandomString) } -func testAccAzureRMIotHubEnrichment_update(data acceptance.TestData) string { +func testAccIotHubEnrichment_update(data acceptance.TestData) string { return fmt.Sprintf(` provider "azurerm" { features {} diff --git a/azurerm/internal/services/iothub/iothub_resource_test.go b/azurerm/internal/services/iothub/iothub_resource_test.go index a29fccc3b6d31..81db055b6dea0 100644 --- a/azurerm/internal/services/iothub/iothub_resource_test.go +++ b/azurerm/internal/services/iothub/iothub_resource_test.go @@ -99,6 +99,30 @@ func TestAccIotHub_customRoutes(t *testing.T) { }) } +func TestAccIotHub_enrichments(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_iothub", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMIotHubDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMIotHub_enrichments(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMIotHubExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "endpoint.#", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "endpoint.0.type", "AzureIotHub.StorageContainer"), + resource.TestCheckResourceAttr(data.ResourceName, "endpoint.1.type", "AzureIotHub.EventHub"), + resource.TestCheckResourceAttr(data.ResourceName, "route.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "enrichment.#", "2"), + ), + }, + data.ImportStep(), + }, + }) +} + func TestAccIotHub_removeEndpointsAndRoutes(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_iothub", "test") r := IotHubResource{} @@ -450,6 +474,113 @@ resource "azurerm_iothub" "test" { `, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomInteger, data.RandomInteger) } +func testAccIotHub_enrichments(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "%s" +} + +resource "azurerm_storage_account" "test" { + name = "acctestsa%s" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + account_tier = "Standard" + account_replication_type = "LRS" +} + +resource "azurerm_storage_container" "test" { + name = "test" + storage_account_name = azurerm_storage_account.test.name + container_access_type = "private" +} + +resource "azurerm_eventhub_namespace" "test" { + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + name = "acctest-%d" + sku = "Basic" +} + +resource "azurerm_eventhub" "test" { + name = "acctest" + resource_group_name = azurerm_resource_group.test.name + namespace_name = azurerm_eventhub_namespace.test.name + partition_count = 2 + message_retention = 1 +} + +resource "azurerm_eventhub_authorization_rule" "test" { + resource_group_name = azurerm_resource_group.test.name + namespace_name = azurerm_eventhub_namespace.test.name + eventhub_name = azurerm_eventhub.test.name + name = "acctest" + send = true +} + +resource "azurerm_iothub" "test" { + name = "acctestIoTHub-%d" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + + sku { + name = "S1" + capacity = "1" + } + + event_hub_retention_in_days = 7 + event_hub_partition_count = 77 + + endpoint { + type = "AzureIotHub.StorageContainer" + connection_string = azurerm_storage_account.test.primary_blob_connection_string + name = "export" + batch_frequency_in_seconds = 60 + max_chunk_size_in_bytes = 10485760 + container_name = azurerm_storage_container.test.name + encoding = "Avro" + file_name_format = "{iothub}/{partition}_{YYYY}_{MM}_{DD}_{HH}_{mm}" + resource_group_name = azurerm_resource_group.test.name + } + + endpoint { + type = "AzureIotHub.EventHub" + connection_string = azurerm_eventhub_authorization_rule.test.primary_connection_string + name = "export2" + resource_group_name = azurerm_resource_group.test.name + } + + route { + name = "export" + source = "DeviceMessages" + condition = "true" + endpoint_names = ["export"] + enabled = true + } + + enrichment { + key = "enrichment" + value = "$twin.tags.Tenant" + endpoint_names = ["export2"] + } + + enrichment { + key = "enrichment2" + value = "Multiple endpoint" + endpoint_names = ["export", "export2"] + } + + tags = { + purpose = "testing" + } +} +`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomInteger, data.RandomInteger) +} + func (IotHubResource) removeEndpointsAndRoutes(data acceptance.TestData) string { return fmt.Sprintf(` provider "azurerm" { diff --git a/azurerm/internal/services/iothub/registration.go b/azurerm/internal/services/iothub/registration.go index 035ffb60f51f2..9277578e37411 100644 --- a/azurerm/internal/services/iothub/registration.go +++ b/azurerm/internal/services/iothub/registration.go @@ -36,6 +36,7 @@ func (r Registration) SupportedResources() map[string]*schema.Resource { "azurerm_iothub_consumer_group": resourceIotHubConsumerGroup(), "azurerm_iothub": resourceIotHub(), "azurerm_iothub_fallback_route": resourceIotHubFallbackRoute(), + "azurerm_iothub_enrichment": resourceIotHubEnrichment(), "azurerm_iothub_route": resourceIotHubRoute(), "azurerm_iothub_endpoint_eventhub": resourceIotHubEndpointEventHub(), "azurerm_iothub_endpoint_servicebus_queue": resourceIotHubEndpointServiceBusQueue(), diff --git a/azurerm/internal/services/iothub/tests/iothub_resource_test.go b/azurerm/internal/services/iothub/tests/iothub_resource_test.go deleted file mode 100644 index 86a25ffd4637c..0000000000000 --- a/azurerm/internal/services/iothub/tests/iothub_resource_test.go +++ /dev/null @@ -1,943 +0,0 @@ -package tests - -import ( - "fmt" - "net/http" - "testing" - - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" -) - -func TestAccAzureRMIotHub_basic(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_iothub", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMIotHubDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMIotHub_basic(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMIotHubExists(data.ResourceName), - ), - }, - data.ImportStep(), - }, - }) -} - -func TestAccAzureRMIotHub_ipFilterRules(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_iothub", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMIotHubDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMIotHub_ipFilterRules(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMIotHubExists(data.ResourceName), - ), - }, - data.ImportStep(), - }, - }) -} - -func TestAccAzureRMIotHub_requiresImport(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_iothub", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMIotHubDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMIotHub_basic(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMIotHubExists(data.ResourceName), - ), - }, - { - Config: testAccAzureRMIotHub_requiresImport(data), - ExpectError: acceptance.RequiresImportError("azurerm_iothub"), - }, - }, - }) -} - -func TestAccAzureRMIotHub_standard(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_iothub", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMIotHubDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMIotHub_standard(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMIotHubExists(data.ResourceName), - ), - }, - data.ImportStep(), - }, - }) -} - -func TestAccAzureRMIotHub_customRoutes(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_iothub", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMIotHubDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMIotHub_customRoutes(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMIotHubExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "endpoint.#", "2"), - resource.TestCheckResourceAttr(data.ResourceName, "endpoint.0.type", "AzureIotHub.StorageContainer"), - resource.TestCheckResourceAttr(data.ResourceName, "endpoint.1.type", "AzureIotHub.EventHub"), - resource.TestCheckResourceAttr(data.ResourceName, "route.#", "2"), - ), - }, - data.ImportStep(), - }, - }) -} - -func TestAccAzureRMIotHub_enrichments(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_iothub", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMIotHubDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMIotHub_enrichments(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMIotHubExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "endpoint.#", "2"), - resource.TestCheckResourceAttr(data.ResourceName, "endpoint.0.type", "AzureIotHub.StorageContainer"), - resource.TestCheckResourceAttr(data.ResourceName, "endpoint.1.type", "AzureIotHub.EventHub"), - resource.TestCheckResourceAttr(data.ResourceName, "route.#", "1"), - resource.TestCheckResourceAttr(data.ResourceName, "enrichment.#", "2"), - ), - }, - data.ImportStep(), - }, - }) -} - -func TestAccAzureRMIotHub_removeEndpointsAndRoutes(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_iothub", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMIotHubDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMIotHub_customRoutes(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMIotHubExists(data.ResourceName), - ), - }, - data.ImportStep(), - { - Config: testAccAzureRMIotHub_removeEndpointsAndRoutes(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMIotHubExists(data.ResourceName), - ), - }, - data.ImportStep(), - }, - }) -} - -func TestAccAzureRMIotHub_fileUpload(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_iothub", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMIotHubDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMIotHub_fileUpload(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMIotHubExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "file_upload.#", "1"), - resource.TestCheckResourceAttr(data.ResourceName, "file_upload.0.lock_duration", "PT5M"), - ), - }, - data.ImportStep(), - }, - }) -} - -func TestAccAzureRMIotHub_withDifferentEndpointResourceGroup(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_iothub", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMIotHubDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMIotHub_withDifferentEndpointResourceGroup(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMIotHubExists(data.ResourceName), - ), - }, - data.ImportStep(), - }, - }) -} - -func TestAccAzureRMIotHub_fallbackRoute(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_iothub", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMIotHubDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMIotHub_fallbackRoute(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMIotHubExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "fallback_route.0.source", "DeviceMessages"), - resource.TestCheckResourceAttr(data.ResourceName, "fallback_route.0.endpoint_names.#", "1"), - resource.TestCheckResourceAttr(data.ResourceName, "fallback_route.0.enabled", "true"), - ), - }, - data.ImportStep(), - }, - }) -} - -func TestAccAzureRMIotHub_publicAccess(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_iothub", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMIotHubDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMIotHub_basic(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMIotHubExists(data.ResourceName), - ), - }, - data.ImportStep(), - { - Config: testAccAzureRMIotHub_publicAccessEnabled(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMIotHubExists(data.ResourceName), - ), - }, - data.ImportStep(), - { - Config: testAccAzureRMIotHub_publicAccessDisabled(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMIotHubExists(data.ResourceName), - ), - }, - data.ImportStep(), - { - Config: testAccAzureRMIotHub_basic(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMIotHubExists(data.ResourceName), - ), - }, - data.ImportStep(), - }, - }) -} - -func testCheckAzureRMIotHubDestroy(s *terraform.State) error { - client := acceptance.AzureProvider.Meta().(*clients.Client).IoTHub.ResourceClient - ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext - - for _, rs := range s.RootModule().Resources { - if rs.Type != "azurerm_iothub" { - continue - } - - name := rs.Primary.Attributes["name"] - resourceGroup := rs.Primary.Attributes["resource_group_name"] - - resp, err := client.Get(ctx, resourceGroup, name) - - if err != nil { - return nil - } - - if resp.StatusCode != http.StatusNotFound { - return fmt.Errorf("IotHub %s still exists in resource group %s", name, resourceGroup) - } - } - return nil -} - -func testCheckAzureRMIotHubExists(resourceName string) resource.TestCheckFunc { - return func(s *terraform.State) error { - client := acceptance.AzureProvider.Meta().(*clients.Client).IoTHub.ResourceClient - ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext - - rs, ok := s.RootModule().Resources[resourceName] - if !ok { - return fmt.Errorf("Not found: %s", resourceName) - } - iothubName := rs.Primary.Attributes["name"] - resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"] - if !hasResourceGroup { - return fmt.Errorf("Bad: no resource group found in state for IotHub: %s", iothubName) - } - - resp, err := client.Get(ctx, resourceGroup, iothubName) - if err != nil { - if resp.StatusCode == http.StatusNotFound { - return fmt.Errorf("Bad: IotHub %q (resource group: %q) does not exist", iothubName, resourceGroup) - } - - return fmt.Errorf("Bad: Get on iothubResourceClient: %+v", err) - } - - return nil - } -} - -func testAccAzureRMIotHub_basic(data acceptance.TestData) string { - return fmt.Sprintf(` -provider "azurerm" { - features {} -} - -resource "azurerm_resource_group" "test" { - name = "acctestRG-iothub-%d" - location = "%s" -} - -resource "azurerm_iothub" "test" { - name = "acctestIoTHub-%d" - resource_group_name = azurerm_resource_group.test.name - location = azurerm_resource_group.test.location - - sku { - name = "B1" - capacity = "1" - } - - tags = { - purpose = "testing" - } -} -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) -} - -func testAccAzureRMIotHub_requiresImport(data acceptance.TestData) string { - template := testAccAzureRMIotHub_basic(data) - return fmt.Sprintf(` -%s - -resource "azurerm_iothub" "import" { - name = azurerm_iothub.test.name - resource_group_name = azurerm_iothub.test.resource_group_name - location = azurerm_iothub.test.location - - sku { - name = "B1" - capacity = "1" - } - - tags = { - purpose = "testing" - } -} -`, template) -} - -func testAccAzureRMIotHub_standard(data acceptance.TestData) string { - return fmt.Sprintf(` -provider "azurerm" { - features {} -} - -resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" - location = "%s" -} - -resource "azurerm_iothub" "test" { - name = "acctestIoTHub-%d" - resource_group_name = azurerm_resource_group.test.name - location = azurerm_resource_group.test.location - - sku { - name = "S1" - capacity = "1" - } - - tags = { - purpose = "testing" - } -} -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) -} - -func testAccAzureRMIotHub_ipFilterRules(data acceptance.TestData) string { - return fmt.Sprintf(` -provider "azurerm" { - features {} -} - -resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" - location = "%s" -} - -resource "azurerm_iothub" "test" { - name = "acctestIoTHub-%d" - resource_group_name = azurerm_resource_group.test.name - location = azurerm_resource_group.test.location - - sku { - name = "S1" - capacity = "1" - } - - ip_filter_rule { - name = "test" - ip_mask = "10.0.0.0/31" - action = "Accept" - } - - tags = { - purpose = "testing" - } -} -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) -} - -func testAccAzureRMIotHub_customRoutes(data acceptance.TestData) string { - return fmt.Sprintf(` -provider "azurerm" { - features {} -} - -resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" - location = "%s" -} - -resource "azurerm_storage_account" "test" { - name = "acctestsa%s" - resource_group_name = azurerm_resource_group.test.name - location = azurerm_resource_group.test.location - account_tier = "Standard" - account_replication_type = "LRS" -} - -resource "azurerm_storage_container" "test" { - name = "test" - storage_account_name = azurerm_storage_account.test.name - container_access_type = "private" -} - -resource "azurerm_eventhub_namespace" "test" { - resource_group_name = azurerm_resource_group.test.name - location = azurerm_resource_group.test.location - name = "acctest-%d" - sku = "Basic" -} - -resource "azurerm_eventhub" "test" { - name = "acctest" - resource_group_name = azurerm_resource_group.test.name - namespace_name = azurerm_eventhub_namespace.test.name - partition_count = 2 - message_retention = 1 -} - -resource "azurerm_eventhub_authorization_rule" "test" { - resource_group_name = azurerm_resource_group.test.name - namespace_name = azurerm_eventhub_namespace.test.name - eventhub_name = azurerm_eventhub.test.name - name = "acctest" - send = true -} - -resource "azurerm_iothub" "test" { - name = "acctestIoTHub-%d" - resource_group_name = azurerm_resource_group.test.name - location = azurerm_resource_group.test.location - - sku { - name = "S1" - capacity = "1" - } - - event_hub_retention_in_days = 7 - event_hub_partition_count = 77 - - endpoint { - type = "AzureIotHub.StorageContainer" - connection_string = azurerm_storage_account.test.primary_blob_connection_string - name = "export" - batch_frequency_in_seconds = 60 - max_chunk_size_in_bytes = 10485760 - container_name = azurerm_storage_container.test.name - encoding = "Avro" - file_name_format = "{iothub}/{partition}_{YYYY}_{MM}_{DD}_{HH}_{mm}" - resource_group_name = azurerm_resource_group.test.name - } - - endpoint { - type = "AzureIotHub.EventHub" - connection_string = azurerm_eventhub_authorization_rule.test.primary_connection_string - name = "export2" - resource_group_name = azurerm_resource_group.test.name - } - - route { - name = "export" - source = "DeviceMessages" - condition = "true" - endpoint_names = ["export"] - enabled = true - } - - route { - name = "export2" - source = "DeviceMessages" - condition = "true" - endpoint_names = ["export2"] - enabled = true - } - - tags = { - purpose = "testing" - } -} -`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomInteger, data.RandomInteger) -} - -func testAccAzureRMIotHub_enrichments(data acceptance.TestData) string { - return fmt.Sprintf(` -provider "azurerm" { - features {} -} - -resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" - location = "%s" -} - -resource "azurerm_storage_account" "test" { - name = "acctestsa%s" - resource_group_name = azurerm_resource_group.test.name - location = azurerm_resource_group.test.location - account_tier = "Standard" - account_replication_type = "LRS" -} - -resource "azurerm_storage_container" "test" { - name = "test" - storage_account_name = azurerm_storage_account.test.name - container_access_type = "private" -} - -resource "azurerm_eventhub_namespace" "test" { - resource_group_name = azurerm_resource_group.test.name - location = azurerm_resource_group.test.location - name = "acctest-%d" - sku = "Basic" -} - -resource "azurerm_eventhub" "test" { - name = "acctest" - resource_group_name = azurerm_resource_group.test.name - namespace_name = azurerm_eventhub_namespace.test.name - partition_count = 2 - message_retention = 1 -} - -resource "azurerm_eventhub_authorization_rule" "test" { - resource_group_name = azurerm_resource_group.test.name - namespace_name = azurerm_eventhub_namespace.test.name - eventhub_name = azurerm_eventhub.test.name - name = "acctest" - send = true -} - -resource "azurerm_iothub" "test" { - name = "acctestIoTHub-%d" - resource_group_name = azurerm_resource_group.test.name - location = azurerm_resource_group.test.location - - sku { - name = "S1" - capacity = "1" - } - - event_hub_retention_in_days = 7 - event_hub_partition_count = 77 - - endpoint { - type = "AzureIotHub.StorageContainer" - connection_string = azurerm_storage_account.test.primary_blob_connection_string - name = "export" - batch_frequency_in_seconds = 60 - max_chunk_size_in_bytes = 10485760 - container_name = azurerm_storage_container.test.name - encoding = "Avro" - file_name_format = "{iothub}/{partition}_{YYYY}_{MM}_{DD}_{HH}_{mm}" - resource_group_name = azurerm_resource_group.test.name - } - - endpoint { - type = "AzureIotHub.EventHub" - connection_string = azurerm_eventhub_authorization_rule.test.primary_connection_string - name = "export2" - resource_group_name = azurerm_resource_group.test.name - } - - route { - name = "export" - source = "DeviceMessages" - condition = "true" - endpoint_names = ["export"] - enabled = true - } - - enrichment { - key = "enrichment" - value = "$twin.tags.Tenant" - endpoint_names = ["export2"] - } - - enrichment { - key = "enrichment2" - value = "Multiple endpoint" - endpoint_names = ["export", "export2"] - } - - tags = { - purpose = "testing" - } -} -`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomInteger, data.RandomInteger) -} - -func testAccAzureRMIotHub_removeEndpointsAndRoutes(data acceptance.TestData) string { - return fmt.Sprintf(` -provider "azurerm" { - features {} -} - -resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" - location = "%s" -} - -resource "azurerm_storage_account" "test" { - name = "acctestsa%s" - resource_group_name = azurerm_resource_group.test.name - location = azurerm_resource_group.test.location - account_tier = "Standard" - account_replication_type = "LRS" -} - -resource "azurerm_storage_container" "test" { - name = "test" - storage_account_name = azurerm_storage_account.test.name - container_access_type = "private" -} - -resource "azurerm_eventhub_namespace" "test" { - resource_group_name = azurerm_resource_group.test.name - location = azurerm_resource_group.test.location - name = "acctest-%d" - sku = "Basic" -} - -resource "azurerm_eventhub" "test" { - name = "acctest" - resource_group_name = azurerm_resource_group.test.name - namespace_name = azurerm_eventhub_namespace.test.name - partition_count = 2 - message_retention = 1 -} - -resource "azurerm_eventhub_authorization_rule" "test" { - resource_group_name = azurerm_resource_group.test.name - namespace_name = azurerm_eventhub_namespace.test.name - eventhub_name = azurerm_eventhub.test.name - name = "acctest" - send = true -} - -resource "azurerm_iothub" "test" { - name = "acctestIoTHub-%d" - resource_group_name = azurerm_resource_group.test.name - location = azurerm_resource_group.test.location - - sku { - name = "S1" - capacity = "1" - } - - event_hub_retention_in_days = 7 - event_hub_partition_count = 77 - - endpoint = [] - - route = [] - - tags = { - purpose = "testing" - } -} -`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomInteger, data.RandomInteger) -} - -func testAccAzureRMIotHub_fallbackRoute(data acceptance.TestData) string { - return fmt.Sprintf(` -provider "azurerm" { - features {} -} - -resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" - location = "%s" -} - -resource "azurerm_iothub" "test" { - name = "acctestIoTHub-%d" - resource_group_name = azurerm_resource_group.test.name - location = azurerm_resource_group.test.location - - sku { - name = "S1" - capacity = "1" - } - - fallback_route { - source = "DeviceMessages" - endpoint_names = ["events"] - enabled = true - } - - tags = { - purpose = "testing" - } -} -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) -} - -func testAccAzureRMIotHub_fileUpload(data acceptance.TestData) string { - return fmt.Sprintf(` -provider "azurerm" { - features {} -} - -resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" - location = "%s" -} - -resource "azurerm_storage_account" "test" { - name = "acctestsa%s" - resource_group_name = azurerm_resource_group.test.name - location = azurerm_resource_group.test.location - account_tier = "Standard" - account_replication_type = "LRS" -} - -resource "azurerm_storage_container" "test" { - name = "test" - storage_account_name = azurerm_storage_account.test.name - container_access_type = "private" -} - -resource "azurerm_iothub" "test" { - name = "acctestIoTHub-%d" - resource_group_name = azurerm_resource_group.test.name - location = azurerm_resource_group.test.location - - sku { - name = "S1" - capacity = "1" - } - - file_upload { - connection_string = azurerm_storage_account.test.primary_blob_connection_string - container_name = azurerm_storage_container.test.name - notifications = true - max_delivery_count = 12 - sas_ttl = "PT2H" - default_ttl = "PT3H" - lock_duration = "PT5M" - } -} -`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomInteger) -} - -func testAccAzureRMIotHub_publicAccessEnabled(data acceptance.TestData) string { - return fmt.Sprintf(` -provider "azurerm" { - features {} -} - -resource "azurerm_resource_group" "test" { - name = "acctestRG-iothub-%d" - location = "%s" -} - -resource "azurerm_iothub" "test" { - name = "acctestIoTHub-%d" - resource_group_name = azurerm_resource_group.test.name - location = azurerm_resource_group.test.location - - sku { - name = "B1" - capacity = "1" - } - - public_network_access_enabled = true - - tags = { - purpose = "testing" - } -} -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) -} - -func testAccAzureRMIotHub_publicAccessDisabled(data acceptance.TestData) string { - return fmt.Sprintf(` -provider "azurerm" { - features {} -} - -resource "azurerm_resource_group" "test" { - name = "acctestRG-iothub-%d" - location = "%s" -} - -resource "azurerm_iothub" "test" { - name = "acctestIoTHub-%d" - resource_group_name = azurerm_resource_group.test.name - location = azurerm_resource_group.test.location - - sku { - name = "B1" - capacity = "1" - } - - public_network_access_enabled = false - - tags = { - purpose = "testing" - } -} -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) -} - -func testAccAzureRMIotHub_withDifferentEndpointResourceGroup(data acceptance.TestData) string { - return fmt.Sprintf(` -provider "azurerm" { - features {} -} - -resource "azurerm_resource_group" "test" { - name = "acctestRG-iothub-%d" - location = "%s" -} - -resource "azurerm_resource_group" "test2" { - name = "acctestRG2-%d" - location = "%s" -} - -resource "azurerm_storage_account" "test" { - name = "acctestsa%s" - resource_group_name = azurerm_resource_group.test.name - location = azurerm_resource_group.test.location - account_tier = "Standard" - account_replication_type = "LRS" -} - -resource "azurerm_storage_container" "test" { - name = "test" - storage_account_name = azurerm_storage_account.test.name - container_access_type = "private" -} - -resource "azurerm_eventhub_namespace" "test" { - resource_group_name = azurerm_resource_group.test2.name - location = azurerm_resource_group.test2.location - name = "acctest-%d" - sku = "Basic" -} - -resource "azurerm_eventhub" "test" { - name = "acctest" - resource_group_name = azurerm_resource_group.test2.name - namespace_name = azurerm_eventhub_namespace.test.name - partition_count = 2 - message_retention = 1 -} - -resource "azurerm_eventhub_authorization_rule" "test" { - resource_group_name = azurerm_resource_group.test2.name - namespace_name = azurerm_eventhub_namespace.test.name - eventhub_name = azurerm_eventhub.test.name - name = "acctest" - send = true -} - -resource "azurerm_iothub" "test" { - name = "acctestIoTHub-%d" - resource_group_name = azurerm_resource_group.test.name - location = azurerm_resource_group.test.location - - sku { - name = "S1" - capacity = "1" - } - - event_hub_retention_in_days = 7 - event_hub_partition_count = 77 - - endpoint { - type = "AzureIotHub.StorageContainer" - connection_string = azurerm_storage_account.test.primary_blob_connection_string - name = "export" - batch_frequency_in_seconds = 60 - max_chunk_size_in_bytes = 10485760 - container_name = azurerm_storage_container.test.name - encoding = "Avro" - file_name_format = "{iothub}/{partition}_{YYYY}_{MM}_{DD}_{HH}_{mm}" - resource_group_name = azurerm_resource_group.test.name - } - - endpoint { - type = "AzureIotHub.EventHub" - connection_string = azurerm_eventhub_authorization_rule.test.primary_connection_string - name = "export2" - resource_group_name = azurerm_resource_group.test2.name - } -} -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomInteger, data.RandomInteger) -}