From 776a23d4998b79e04d56956ddc287f9ae1073989 Mon Sep 17 00:00:00 2001 From: Neil Ye Date: Fri, 8 May 2020 01:24:07 +0800 Subject: [PATCH] support alias connection strings for eventhub resources (#6708) --- azurerm/helpers/azure/eventhub.go | 28 +++++-- ...eventhub_authorization_rule_data_source.go | 2 + .../eventhub_authorization_rule_resource.go | 2 + ...amespace_authorization_rule_data_source.go | 28 +++++-- ...b_namespace_authorization_rule_resource.go | 2 + .../eventhub_namespace_data_source.go | 30 +++++-- .../eventhub/eventhub_namespace_resource.go | 18 +++- ...hub_authorization_rule_data_source_test.go | 34 ++++++++ ...enthub_authorization_rule_resource_test.go | 84 +++++++++++++++++++ ...ace_authorization_rule_data_source_test.go | 40 ++++++++- ...espace_authorization_rule_resource_test.go | 79 +++++++++++++++++ .../eventhub_namespace_data_source_test.go | 35 ++++++++ .../tests/eventhub_namespace_resource_test.go | 69 +++++++++++++++ .../eventhub_authorization_rule.html.markdown | 8 +- .../docs/d/eventhub_namespace.html.markdown | 8 +- ...namespace_authorization_rule.html.markdown | 13 +-- .../eventhub_authorization_rule.html.markdown | 8 +- .../docs/r/eventhub_namespace.html.markdown | 8 +- ...namespace_authorization_rule.html.markdown | 8 +- 19 files changed, 465 insertions(+), 39 deletions(-) diff --git a/azurerm/helpers/azure/eventhub.go b/azurerm/helpers/azure/eventhub.go index 68bb1bf806ce..45fc49377e6d 100644 --- a/azurerm/helpers/azure/eventhub.go +++ b/azurerm/helpers/azure/eventhub.go @@ -88,16 +88,22 @@ func EventHubAuthorizationRuleSchemaFrom(s map[string]*schema.Schema) map[string Default: false, }, - "send": { + "manage": { Type: schema.TypeBool, Optional: true, Default: false, }, - "manage": { - Type: schema.TypeBool, - Optional: true, - Default: false, + "primary_connection_string": { + Type: schema.TypeString, + Computed: true, + Sensitive: true, + }, + + "primary_connection_string_alias": { + Type: schema.TypeString, + Computed: true, + Sensitive: true, }, "primary_key": { @@ -106,23 +112,29 @@ func EventHubAuthorizationRuleSchemaFrom(s map[string]*schema.Schema) map[string Sensitive: true, }, - "primary_connection_string": { + "secondary_connection_string": { Type: schema.TypeString, Computed: true, Sensitive: true, }, - "secondary_key": { + "secondary_connection_string_alias": { Type: schema.TypeString, Computed: true, Sensitive: true, }, - "secondary_connection_string": { + "secondary_key": { Type: schema.TypeString, Computed: true, Sensitive: true, }, + + "send": { + Type: schema.TypeBool, + Optional: true, + Default: false, + }, } return MergeSchema(s, authSchema) } diff --git a/azurerm/internal/services/eventhub/eventhub_authorization_rule_data_source.go b/azurerm/internal/services/eventhub/eventhub_authorization_rule_data_source.go index 79e64fe3b6f6..180c4184bbbc 100644 --- a/azurerm/internal/services/eventhub/eventhub_authorization_rule_data_source.go +++ b/azurerm/internal/services/eventhub/eventhub_authorization_rule_data_source.go @@ -103,6 +103,8 @@ func dataSourceEventHubAuthorizationRuleRead(d *schema.ResourceData, meta interf d.Set("secondary_key", keysResp.SecondaryKey) d.Set("primary_connection_string", keysResp.PrimaryConnectionString) d.Set("secondary_connection_string", keysResp.SecondaryConnectionString) + d.Set("primary_connection_string_alias", keysResp.AliasPrimaryConnectionString) + d.Set("secondary_connection_string_alias", keysResp.AliasSecondaryConnectionString) return nil } diff --git a/azurerm/internal/services/eventhub/eventhub_authorization_rule_resource.go b/azurerm/internal/services/eventhub/eventhub_authorization_rule_resource.go index b9e8228c908f..1c86a888582d 100644 --- a/azurerm/internal/services/eventhub/eventhub_authorization_rule_resource.go +++ b/azurerm/internal/services/eventhub/eventhub_authorization_rule_resource.go @@ -165,6 +165,8 @@ func resourceArmEventHubAuthorizationRuleRead(d *schema.ResourceData, meta inter d.Set("secondary_key", keysResp.SecondaryKey) d.Set("primary_connection_string", keysResp.PrimaryConnectionString) d.Set("secondary_connection_string", keysResp.SecondaryConnectionString) + d.Set("primary_connection_string_alias", keysResp.AliasPrimaryConnectionString) + d.Set("secondary_connection_string_alias", keysResp.AliasSecondaryConnectionString) return nil } diff --git a/azurerm/internal/services/eventhub/eventhub_namespace_authorization_rule_data_source.go b/azurerm/internal/services/eventhub/eventhub_namespace_authorization_rule_data_source.go index f59ff99958a2..38990f1ae47b 100644 --- a/azurerm/internal/services/eventhub/eventhub_namespace_authorization_rule_data_source.go +++ b/azurerm/internal/services/eventhub/eventhub_namespace_authorization_rule_data_source.go @@ -39,14 +39,21 @@ func dataSourceEventHubNamespaceAuthorizationRule() *schema.Resource { Computed: true, }, - "send": { + "manage": { Type: schema.TypeBool, Computed: true, }, - "manage": { - Type: schema.TypeBool, - Computed: true, + "primary_connection_string": { + Type: schema.TypeString, + Computed: true, + Sensitive: true, + }, + + "primary_connection_string_alias": { + Type: schema.TypeString, + Computed: true, + Sensitive: true, }, "primary_key": { @@ -55,23 +62,28 @@ func dataSourceEventHubNamespaceAuthorizationRule() *schema.Resource { Sensitive: true, }, - "primary_connection_string": { + "secondary_connection_string": { Type: schema.TypeString, Computed: true, Sensitive: true, }, - "secondary_key": { + "secondary_connection_string_alias": { Type: schema.TypeString, Computed: true, Sensitive: true, }, - "secondary_connection_string": { + "secondary_key": { Type: schema.TypeString, Computed: true, Sensitive: true, }, + + "send": { + Type: schema.TypeBool, + Computed: true, + }, }, } } @@ -118,6 +130,8 @@ func dataSourceEventHubNamespaceAuthorizationRuleRead(d *schema.ResourceData, me d.Set("secondary_key", keysResp.SecondaryKey) d.Set("primary_connection_string", keysResp.PrimaryConnectionString) d.Set("secondary_connection_string", keysResp.SecondaryConnectionString) + d.Set("primary_connection_string_alias", keysResp.AliasPrimaryConnectionString) + d.Set("secondary_connection_string_alias", keysResp.AliasSecondaryConnectionString) return nil } diff --git a/azurerm/internal/services/eventhub/eventhub_namespace_authorization_rule_resource.go b/azurerm/internal/services/eventhub/eventhub_namespace_authorization_rule_resource.go index 0bde5790fb4f..7af663e7ad24 100644 --- a/azurerm/internal/services/eventhub/eventhub_namespace_authorization_rule_resource.go +++ b/azurerm/internal/services/eventhub/eventhub_namespace_authorization_rule_resource.go @@ -152,6 +152,8 @@ func resourceArmEventHubNamespaceAuthorizationRuleRead(d *schema.ResourceData, m d.Set("secondary_key", keysResp.SecondaryKey) d.Set("primary_connection_string", keysResp.PrimaryConnectionString) d.Set("secondary_connection_string", keysResp.SecondaryConnectionString) + d.Set("primary_connection_string_alias", keysResp.AliasPrimaryConnectionString) + d.Set("secondary_connection_string_alias", keysResp.AliasSecondaryConnectionString) return nil } diff --git a/azurerm/internal/services/eventhub/eventhub_namespace_data_source.go b/azurerm/internal/services/eventhub/eventhub_namespace_data_source.go index 10577064105a..25b198bc1cb3 100644 --- a/azurerm/internal/services/eventhub/eventhub_namespace_data_source.go +++ b/azurerm/internal/services/eventhub/eventhub_namespace_data_source.go @@ -31,14 +31,16 @@ func dataSourceEventHubNamespace() *schema.Resource { "location": azure.SchemaLocationForDataSource(), - "sku": { - Type: schema.TypeString, - Computed: true, + "default_primary_connection_string_alias": { + Type: schema.TypeString, + Computed: true, + Sensitive: true, }, - "capacity": { - Type: schema.TypeInt, - Computed: true, + "default_secondary_connection_string_alias": { + Type: schema.TypeString, + Computed: true, + Sensitive: true, }, "auto_inflate_enabled": { @@ -46,6 +48,11 @@ func dataSourceEventHubNamespace() *schema.Resource { Computed: true, }, + "capacity": { + Type: schema.TypeInt, + Computed: true, + }, + "kafka_enabled": { Type: schema.TypeBool, Computed: true, @@ -62,13 +69,13 @@ func dataSourceEventHubNamespace() *schema.Resource { Sensitive: true, }, - "default_secondary_connection_string": { + "default_primary_key": { Type: schema.TypeString, Computed: true, Sensitive: true, }, - "default_primary_key": { + "default_secondary_connection_string": { Type: schema.TypeString, Computed: true, Sensitive: true, @@ -80,6 +87,11 @@ func dataSourceEventHubNamespace() *schema.Resource { Sensitive: true, }, + "sku": { + Type: schema.TypeString, + Computed: true, + }, + "tags": tags.SchemaDataSource(), }, } @@ -117,6 +129,8 @@ func dataSourceEventHubNamespaceRead(d *schema.ResourceData, meta interface{}) e if err != nil { log.Printf("[WARN] Unable to List default keys for EventHub Namespace %q (Resource Group %q): %+v", name, resourceGroup, err) } else { + d.Set("default_primary_connection_string_alias", keys.AliasPrimaryConnectionString) + d.Set("default_secondary_connection_string_alias", keys.AliasSecondaryConnectionString) d.Set("default_primary_connection_string", keys.PrimaryConnectionString) d.Set("default_secondary_connection_string", keys.SecondaryConnectionString) d.Set("default_primary_key", keys.PrimaryKey) diff --git a/azurerm/internal/services/eventhub/eventhub_namespace_resource.go b/azurerm/internal/services/eventhub/eventhub_namespace_resource.go index 35b2dbe0c20c..45d7672e3acb 100644 --- a/azurerm/internal/services/eventhub/eventhub_namespace_resource.go +++ b/azurerm/internal/services/eventhub/eventhub_namespace_resource.go @@ -158,13 +158,19 @@ func resourceArmEventHubNamespace() *schema.Resource { }, }, - "default_primary_connection_string": { + "default_primary_connection_string_alias": { Type: schema.TypeString, Computed: true, Sensitive: true, }, - "default_secondary_connection_string": { + "default_secondary_connection_string_alias": { + Type: schema.TypeString, + Computed: true, + Sensitive: true, + }, + + "default_primary_connection_string": { Type: schema.TypeString, Computed: true, Sensitive: true, @@ -176,6 +182,12 @@ func resourceArmEventHubNamespace() *schema.Resource { Sensitive: true, }, + "default_secondary_connection_string": { + Type: schema.TypeString, + Computed: true, + Sensitive: true, + }, + "default_secondary_key": { Type: schema.TypeString, Computed: true, @@ -326,6 +338,8 @@ func resourceArmEventHubNamespaceRead(d *schema.ResourceData, meta interface{}) if err != nil { log.Printf("[WARN] Unable to List default keys for EventHub Namespace %q: %+v", name, err) } else { + d.Set("default_primary_connection_string_alias", keys.AliasPrimaryConnectionString) + d.Set("default_secondary_connection_string_alias", keys.AliasSecondaryConnectionString) d.Set("default_primary_connection_string", keys.PrimaryConnectionString) d.Set("default_secondary_connection_string", keys.SecondaryConnectionString) d.Set("default_primary_key", keys.PrimaryKey) diff --git a/azurerm/internal/services/eventhub/tests/eventhub_authorization_rule_data_source_test.go b/azurerm/internal/services/eventhub/tests/eventhub_authorization_rule_data_source_test.go index b6691fc114d7..4ddb26fac7b3 100644 --- a/azurerm/internal/services/eventhub/tests/eventhub_authorization_rule_data_source_test.go +++ b/azurerm/internal/services/eventhub/tests/eventhub_authorization_rule_data_source_test.go @@ -33,6 +33,26 @@ func TestAccDataSourceAzureRMEventHubAuthorizationRule(t *testing.T) { }) } +func TestAccDataSourceAzureRMEventHubAuthorizationRule_withAliasConnectionString(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_eventhub_authorization_rule", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMEventHubAuthorizationRuleDestroy, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceAzureRMEventHubAuthorizationRule_withAliasConnectionString(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMEventHubAuthorizationRuleExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "primary_connection_string_alias"), + resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_connection_string_alias"), + ), + }, + }, + }) +} + func testAccDataSourceAzureRMEventHubAuthorizationRule_base(data acceptance.TestData, listen, send, manage bool) string { template := testAccAzureRMEventHubAuthorizationRule_base(data, listen, send, manage) return fmt.Sprintf(` @@ -46,3 +66,17 @@ data "azurerm_eventhub_authorization_rule" "test" { } `, template) } + +func testAccDataSourceAzureRMEventHubAuthorizationRule_withAliasConnectionString(data acceptance.TestData) string { + template := testAccAzureRMEventHubAuthorizationRule_withAliasConnectionString(data) + return fmt.Sprintf(` +%s + +data "azurerm_eventhub_authorization_rule" "test" { + name = azurerm_eventhub_authorization_rule.test.name + namespace_name = azurerm_eventhub_namespace.test.name + eventhub_name = azurerm_eventhub.test.name + resource_group_name = azurerm_resource_group.test.name +} +`, template) +} diff --git a/azurerm/internal/services/eventhub/tests/eventhub_authorization_rule_resource_test.go b/azurerm/internal/services/eventhub/tests/eventhub_authorization_rule_resource_test.go index d637f56d6885..d0071dfd3836 100644 --- a/azurerm/internal/services/eventhub/tests/eventhub_authorization_rule_resource_test.go +++ b/azurerm/internal/services/eventhub/tests/eventhub_authorization_rule_resource_test.go @@ -164,6 +164,27 @@ func TestAccAzureRMEventHubAuthorizationRule_rightsUpdate(t *testing.T) { }) } +func TestAccAzureRMEventHubAuthorizationRule_withAliasConnectionString(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_eventhub_authorization_rule", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMEventHubAuthorizationRuleDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMEventHubAuthorizationRule_withAliasConnectionString(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMEventHubAuthorizationRuleExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "primary_connection_string_alias"), + resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_connection_string_alias"), + ), + }, + data.ImportStep(), + }, + }) +} + func testCheckAzureRMEventHubAuthorizationRuleDestroy(s *terraform.State) error { conn := acceptance.AzureProvider.Meta().(*clients.Client).Eventhub.EventHubsClient ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext @@ -312,3 +333,66 @@ resource "azurerm_eventhub_authorization_rule" "import" { } `, template) } + +func testAccAzureRMEventHubAuthorizationRule_withAliasConnectionString(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "test" { + name = "acctestRG-ehar-%[1]d" + location = "%[2]s" +} + +resource "azurerm_resource_group" "test2" { + name = "acctestRG2-ehar-%[1]d" + location = "%[3]s" +} + +resource "azurerm_eventhub_namespace" "test" { + name = "acctesteventhubnamespace-%[1]d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + + sku = "Standard" +} + +resource "azurerm_eventhub_namespace" "test2" { + name = "acctesteventhubnamespace2-%[1]d" + location = azurerm_resource_group.test2.location + resource_group_name = azurerm_resource_group.test2.name + + sku = "Standard" +} + +resource "azurerm_eventhub_namespace_disaster_recovery_config" "test" { + name = "acctest-EHN-DRC-%[1]d" + resource_group_name = azurerm_resource_group.test.name + namespace_name = azurerm_eventhub_namespace.test.name + partner_namespace_id = azurerm_eventhub_namespace.test2.id +} + +resource "azurerm_eventhub" "test" { + name = "acctesteventhub-%[1]d" + namespace_name = azurerm_eventhub_namespace.test.name + resource_group_name = azurerm_resource_group.test.name + + partition_count = 2 + message_retention = 1 +} + +resource "azurerm_eventhub_authorization_rule" "test" { + name = "acctest-%[1]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 = true + manage = true + + depends_on = [azurerm_eventhub_namespace_disaster_recovery_config.test] +} +`, data.RandomInteger, data.Locations.Primary, data.Locations.Secondary) +} diff --git a/azurerm/internal/services/eventhub/tests/eventhub_namespace_authorization_rule_data_source_test.go b/azurerm/internal/services/eventhub/tests/eventhub_namespace_authorization_rule_data_source_test.go index fcc963c67ca5..1d7086c02478 100644 --- a/azurerm/internal/services/eventhub/tests/eventhub_namespace_authorization_rule_data_source_test.go +++ b/azurerm/internal/services/eventhub/tests/eventhub_namespace_authorization_rule_data_source_test.go @@ -9,7 +9,7 @@ import ( ) func TestAccDataSourceAzureRMEventHubNamespaceAuthorizationRule_basic(t *testing.T) { - data := acceptance.BuildTestData(t, "data.eventhub_namespace_authorization_rule", "test") + data := acceptance.BuildTestData(t, "data.azurerm_eventhub_namespace_authorization_rule", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -27,6 +27,31 @@ func TestAccDataSourceAzureRMEventHubNamespaceAuthorizationRule_basic(t *testing }) } +func TestAccDataSourceAzureRMEventHubNamespaceAuthorizationRule_withAliasConnectionString(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_eventhub_namespace_authorization_rule", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + Steps: []resource.TestStep{ + { + // `primary_connection_string_alias` and `secondary_connection_string_alias` are still `nil` while `data.azurerm_eventhub_namespace_authorization_rule` is retrieving resource. since `azurerm_eventhub_namespace_disaster_recovery_config` hasn't been created. + // So these two properties should be checked in the second run. + // And `depends_on` cannot be applied to `azurerm_eventhub_namespace_authorization_rule`. + // Because it would throw error message `BreakPairing operation is only allowed on primary namespace with valid secondary namespace.` while destroying `azurerm_eventhub_namespace_disaster_recovery_config` if `depends_on` is applied. + Config: testAccAzureRMEventHubNamespaceAuthorizationRule_withAliasConnectionString(data), + }, + { + Config: testAccDataSourceEventHubNamespaceAuthorizationRule_withAliasConnectionString(data), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet(data.ResourceName, "primary_connection_string_alias"), + resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_connection_string_alias"), + ), + }, + }, + }) +} + func testAccDataSourceEventHubNamespaceAuthorizationRule_basic(data acceptance.TestData, listen, send, manage bool) string { return fmt.Sprintf(` provider "azurerm" { @@ -63,3 +88,16 @@ data "azurerm_eventhub_namespace_authorization_rule" "test" { } `, data.RandomInteger, data.Locations.Primary, listen, send, manage) } + +func testAccDataSourceEventHubNamespaceAuthorizationRule_withAliasConnectionString(data acceptance.TestData) string { + template := testAccAzureRMEventHubNamespaceAuthorizationRule_withAliasConnectionString(data) + return fmt.Sprintf(` +%s + +data "azurerm_eventhub_namespace_authorization_rule" "test" { + name = azurerm_eventhub_namespace_authorization_rule.test.name + namespace_name = azurerm_eventhub_namespace.test.name + resource_group_name = azurerm_resource_group.test.name +} +`, template) +} diff --git a/azurerm/internal/services/eventhub/tests/eventhub_namespace_authorization_rule_resource_test.go b/azurerm/internal/services/eventhub/tests/eventhub_namespace_authorization_rule_resource_test.go index 5273d778f539..d4c63a2b8b2e 100644 --- a/azurerm/internal/services/eventhub/tests/eventhub_namespace_authorization_rule_resource_test.go +++ b/azurerm/internal/services/eventhub/tests/eventhub_namespace_authorization_rule_resource_test.go @@ -115,6 +115,36 @@ func TestAccAzureRMEventHubNamespaceAuthorizationRule_rightsUpdate(t *testing.T) }) } +func TestAccAzureRMEventHubNamespaceAuthorizationRule_withAliasConnectionString(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_eventhub_namespace_authorization_rule", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMEventHubNamespaceAuthorizationRuleDestroy, + Steps: []resource.TestStep{ + { + // `primary_connection_string_alias` and `secondary_connection_string_alias` are still `nil` in `azurerm_eventhub_namespace_authorization_rule` after created `azurerm_eventhub_namespace` successfully since `azurerm_eventhub_namespace_disaster_recovery_config` hasn't been created. + // So these two properties should be checked in the second run. + // And `depends_on` cannot be applied to `azurerm_eventhub_namespace_authorization_rule`. + // Because it would throw error message `BreakPairing operation is only allowed on primary namespace with valid secondary namespace.` while destroying `azurerm_eventhub_namespace_disaster_recovery_config` if `depends_on` is applied. + Config: testAccAzureRMEventHubNamespaceAuthorizationRule_withAliasConnectionString(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMEventHubNamespaceAuthorizationRuleExists(data.ResourceName), + ), + }, + { + Config: testAccAzureRMEventHubNamespaceAuthorizationRule_withAliasConnectionString(data), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet(data.ResourceName, "primary_connection_string_alias"), + resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_connection_string_alias"), + ), + }, + data.ImportStep(), + }, + }) +} + func TestAccAzureRMEventHubNamespaceAuthorizationRule_multi(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_eventhub_namespace_authorization_rule", "test1") resourceTwoName := "azurerm_eventhub_namespace_authorization_rule.test2" @@ -249,6 +279,55 @@ resource "azurerm_eventhub_namespace_authorization_rule" "test" { `, data.RandomInteger, data.Locations.Primary, listen, send, manage) } +func testAccAzureRMEventHubNamespaceAuthorizationRule_withAliasConnectionString(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "test" { + name = "acctestRG-ehnar-%[1]d" + location = "%[2]s" +} + +resource "azurerm_resource_group" "test2" { + name = "acctestRG2-ehnar-%[1]d" + location = "%[3]s" +} + +resource "azurerm_eventhub_namespace" "test" { + name = "acctesteventhubnamespace-%[1]d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + sku = "Standard" +} + +resource "azurerm_eventhub_namespace" "test2" { + name = "acctesteventhubnamespace2-%[1]d" + location = azurerm_resource_group.test2.location + resource_group_name = azurerm_resource_group.test2.name + sku = "Standard" +} + +resource "azurerm_eventhub_namespace_disaster_recovery_config" "test" { + name = "acctest-EHN-DRC-%[1]d" + resource_group_name = azurerm_resource_group.test.name + namespace_name = azurerm_eventhub_namespace.test.name + partner_namespace_id = azurerm_eventhub_namespace.test2.id +} + +resource "azurerm_eventhub_namespace_authorization_rule" "test" { + name = "acctest-EHN-AR%[1]d" + namespace_name = azurerm_eventhub_namespace.test.name + resource_group_name = azurerm_resource_group.test.name + + listen = true + send = true + manage = true +} +`, data.RandomInteger, data.Locations.Primary, data.Locations.Secondary) +} + func testAccAzureRMEventHubNamespaceAuthorizationRule_requiresImport(data acceptance.TestData, listen, send, manage bool) string { template := testAccAzureRMEventHubNamespaceAuthorizationRule_base(data, listen, send, manage) return fmt.Sprintf(` diff --git a/azurerm/internal/services/eventhub/tests/eventhub_namespace_data_source_test.go b/azurerm/internal/services/eventhub/tests/eventhub_namespace_data_source_test.go index 97a171726f4a..12020c172f8f 100644 --- a/azurerm/internal/services/eventhub/tests/eventhub_namespace_data_source_test.go +++ b/azurerm/internal/services/eventhub/tests/eventhub_namespace_data_source_test.go @@ -45,6 +45,29 @@ func TestAccDataSourceAzureRMEventHubNamespace_complete(t *testing.T) { }) } +func TestAccDataSourceAzureRMEventHubNamespace_withAliasConnectionString(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_eventhub_namespace", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + Steps: []resource.TestStep{ + { + // `default_primary_connection_string_alias` and `default_secondary_connection_string_alias` are still `nil` while `data.azurerm_eventhub_namespace` is retrieving resource. since `azurerm_eventhub_namespace_disaster_recovery_config` hasn't been created. + // So these two properties should be checked in the second run. + Config: testAccAzureRMEventHubNamespace_withAliasConnectionString(data), + }, + { + Config: testAccDataSourceEventHubNamespace_withAliasConnectionString(data), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet(data.ResourceName, "default_primary_connection_string_alias"), + resource.TestCheckResourceAttrSet(data.ResourceName, "default_secondary_connection_string_alias"), + ), + }, + }, + }) +} + func testAccDataSourceEventHubNamespace_basic(data acceptance.TestData) string { return fmt.Sprintf(` provider "azurerm" { @@ -97,3 +120,15 @@ data "azurerm_eventhub_namespace" "test" { } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } + +func testAccDataSourceEventHubNamespace_withAliasConnectionString(data acceptance.TestData) string { + template := testAccAzureRMEventHubNamespace_withAliasConnectionString(data) + return fmt.Sprintf(` +%s + +data "azurerm_eventhub_namespace" "test" { + name = azurerm_eventhub_namespace.test.name + resource_group_name = azurerm_eventhub_namespace.test.resource_group_name +} +`, template) +} diff --git a/azurerm/internal/services/eventhub/tests/eventhub_namespace_resource_test.go b/azurerm/internal/services/eventhub/tests/eventhub_namespace_resource_test.go index e783390ff797..74e724c1dfb1 100644 --- a/azurerm/internal/services/eventhub/tests/eventhub_namespace_resource_test.go +++ b/azurerm/internal/services/eventhub/tests/eventhub_namespace_resource_test.go @@ -153,6 +153,34 @@ func TestAccAzureRMEventHubNamespace_readDefaultKeys(t *testing.T) { }) } +func TestAccAzureRMEventHubNamespace_withAliasConnectionString(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_eventhub_namespace", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMEventHubNamespaceDestroy, + Steps: []resource.TestStep{ + { + // `default_primary_connection_string_alias` and `default_secondary_connection_string_alias` are still `nil` in `azurerm_eventhub_namespace` after created `azurerm_eventhub_namespace` successfully since `azurerm_eventhub_namespace_disaster_recovery_config` hasn't been created. + // So these two properties should be checked in the second run. + Config: testAccAzureRMEventHubNamespace_withAliasConnectionString(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMEventHubNamespaceExists(data.ResourceName), + ), + }, + { + Config: testAccAzureRMEventHubNamespace_withAliasConnectionString(data), + Check: resource.ComposeTestCheckFunc( + resource.TestMatchResourceAttr(data.ResourceName, "default_primary_connection_string_alias", regexp.MustCompile("Endpoint=.+")), + resource.TestMatchResourceAttr(data.ResourceName, "default_secondary_connection_string_alias", regexp.MustCompile("Endpoint=.+")), + ), + }, + data.ImportStep(), + }, + }) +} + func TestAccAzureRMEventHubNamespace_maximumThroughputUnits(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_eventhub_namespace", "test") @@ -414,6 +442,47 @@ resource "azurerm_eventhub_namespace" "test" { `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } +func testAccAzureRMEventHubNamespace_withAliasConnectionString(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "test" { + name = "acctestRG-ehn-%[1]d" + location = "%[2]s" +} + +resource "azurerm_resource_group" "test2" { + name = "acctestRG2-ehn-%[1]d" + location = "%[3]s" +} + +resource "azurerm_eventhub_namespace" "test" { + name = "acctesteventhubnamespace-%[1]d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + + sku = "Standard" +} + +resource "azurerm_eventhub_namespace" "test2" { + name = "acctesteventhubnamespace2-%[1]d" + location = azurerm_resource_group.test2.location + resource_group_name = azurerm_resource_group.test2.name + + sku = "Standard" +} + +resource "azurerm_eventhub_namespace_disaster_recovery_config" "test" { + name = "acctest-EHN-DRC-%[1]d" + resource_group_name = azurerm_resource_group.test.name + namespace_name = azurerm_eventhub_namespace.test.name + partner_namespace_id = azurerm_eventhub_namespace.test2.id +} +`, data.RandomInteger, data.Locations.Primary, data.Locations.Secondary) +} + func testAccAzureRMEventHubNamespace_requiresImport(data acceptance.TestData) string { template := testAccAzureRMEventHubNamespace_basic(data) return fmt.Sprintf(` diff --git a/website/docs/d/eventhub_authorization_rule.html.markdown b/website/docs/d/eventhub_authorization_rule.html.markdown index c19a239f6f1c..33a14a7a69c3 100644 --- a/website/docs/d/eventhub_authorization_rule.html.markdown +++ b/website/docs/d/eventhub_authorization_rule.html.markdown @@ -37,14 +37,18 @@ The following attributes are exported: * `id` - The EventHub ID. -* `primary_key` - The Primary Key for the Event Hubs Authorization Rule. +* `primary_connection_string_alias` - The alias of the Primary Connection String for the Event Hubs Authorization Rule. + +* `secondary_connection_string_alias` - The alias of the Secondary Connection String for the Event Hubs Authorization Rule. * `primary_connection_string` - The Primary Connection String for the Event Hubs Authorization Rule. -* `secondary_key` - The Secondary Key for the Event Hubs Authorization Rule. +* `primary_key` - The Primary Key for the Event Hubs Authorization Rule. * `secondary_connection_string` - The Secondary Connection String for the Event Hubs Authorization Rule. +* `secondary_key` - The Secondary Key for the Event Hubs Authorization Rule. + ## Timeouts The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/docs/configuration/resources.html#timeouts) for certain actions: diff --git a/website/docs/d/eventhub_namespace.html.markdown b/website/docs/d/eventhub_namespace.html.markdown index 9ab563042980..f62ee07863b9 100644 --- a/website/docs/d/eventhub_namespace.html.markdown +++ b/website/docs/d/eventhub_namespace.html.markdown @@ -50,10 +50,16 @@ The following attributes are exported only if there is an authorization rule nam * `default_primary_connection_string` - The primary connection string for the authorization rule `RootManageSharedAccessKey`. +* `default_primary_connection_string_alias` - The alias of the primary connection string for the authorization + rule `RootManageSharedAccessKey`. + +* `default_primary_key` - The primary access key for the authorization rule `RootManageSharedAccessKey`. + * `default_secondary_connection_string` - The secondary connection string for the authorization rule `RootManageSharedAccessKey`. -* `default_primary_key` - The primary access key for the authorization rule `RootManageSharedAccessKey`. +* `default_secondary_connection_string_alias` - The alias of the secondary connection string for the + authorization rule `RootManageSharedAccessKey`. * `default_secondary_key` - The secondary access key for the authorization rule `RootManageSharedAccessKey`. diff --git a/website/docs/d/eventhub_namespace_authorization_rule.html.markdown b/website/docs/d/eventhub_namespace_authorization_rule.html.markdown index a8779443c50e..600fe0d3dd7a 100644 --- a/website/docs/d/eventhub_namespace_authorization_rule.html.markdown +++ b/website/docs/d/eventhub_namespace_authorization_rule.html.markdown @@ -40,20 +40,23 @@ The following attributes are exported: * `id` - The EventHub ID. -* `listen` - Does this Authorization Rule have permissions to Listen to the Event Hub? +* `primary_connection_string_alias` - The alias of the Primary Connection String for the Event Hubs authorization Rule. -* `send` - Does this Authorization Rule have permissions to Send to the Event Hub? +* `secondary_connection_string_alias` - The alias of the Secondary Connection String for the Event Hubs authorization Rule. -* `manage` - Does this Authorization Rule have permissions to Manage to the Event Hub? +* `listen` - Does this Authorization Rule have permissions to Listen to the Event Hub? -* `primary_key` - The Primary Key for the Event Hubs authorization Rule. +* `manage` - Does this Authorization Rule have permissions to Manage to the Event Hub? * `primary_connection_string` - The Primary Connection String for the Event Hubs authorization Rule. -* `secondary_key` - The Secondary Key for the Event Hubs authorization Rule. +* `primary_key` - The Primary Key for the Event Hubs authorization Rule. * `secondary_connection_string` - The Secondary Connection String for the Event Hubs authorization Rule. +* `secondary_key` - The Secondary Key for the Event Hubs authorization Rule. + +* `send` - Does this Authorization Rule have permissions to Send to the Event Hub? ## Timeouts diff --git a/website/docs/r/eventhub_authorization_rule.html.markdown b/website/docs/r/eventhub_authorization_rule.html.markdown index f82030227e12..97830e2a53cb 100644 --- a/website/docs/r/eventhub_authorization_rule.html.markdown +++ b/website/docs/r/eventhub_authorization_rule.html.markdown @@ -75,14 +75,18 @@ The following attributes are exported: * `id` - The EventHub ID. -* `primary_key` - The Primary Key for the Event Hubs authorization Rule. +* `primary_connection_string_alias` - The alias of the Primary Connection String for the Event Hubs authorization Rule, which is generated when disaster recovery is enabled. + +* `secondary_connection_string_alias` - The alias of the Secondary Connection String for the Event Hubs Authorization Rule, which is generated when disaster recovery is enabled. * `primary_connection_string` - The Primary Connection String for the Event Hubs authorization Rule. -* `secondary_key` - The Secondary Key for the Event Hubs Authorization Rule. +* `primary_key` - The Primary Key for the Event Hubs authorization Rule. * `secondary_connection_string` - The Secondary Connection String for the Event Hubs Authorization Rule. +* `secondary_key` - The Secondary Key for the Event Hubs Authorization Rule. + ## Timeouts diff --git a/website/docs/r/eventhub_namespace.html.markdown b/website/docs/r/eventhub_namespace.html.markdown index 387b26daebda..e541c6cab824 100644 --- a/website/docs/r/eventhub_namespace.html.markdown +++ b/website/docs/r/eventhub_namespace.html.markdown @@ -91,10 +91,16 @@ The following attributes are exported only if there is an authorization rule nam * `default_primary_connection_string` - The primary connection string for the authorization rule `RootManageSharedAccessKey`. +* `default_primary_connection_string_alias` - The alias of the primary connection string for the authorization + rule `RootManageSharedAccessKey`, which is generated when disaster recovery is enabled. + +* `default_primary_key` - The primary access key for the authorization rule `RootManageSharedAccessKey`. + * `default_secondary_connection_string` - The secondary connection string for the authorization rule `RootManageSharedAccessKey`. -* `default_primary_key` - The primary access key for the authorization rule `RootManageSharedAccessKey`. +* `default_secondary_connection_string_alias` - The alias of the secondary connection string for the + authorization rule `RootManageSharedAccessKey`, which is generated when disaster recovery is enabled. * `default_secondary_key` - The secondary access key for the authorization rule `RootManageSharedAccessKey`. diff --git a/website/docs/r/eventhub_namespace_authorization_rule.html.markdown b/website/docs/r/eventhub_namespace_authorization_rule.html.markdown index b6060c91accd..850691cc355c 100644 --- a/website/docs/r/eventhub_namespace_authorization_rule.html.markdown +++ b/website/docs/r/eventhub_namespace_authorization_rule.html.markdown @@ -65,14 +65,18 @@ The following attributes are exported: * `id` - The EventHub Namespace Authorization Rule ID. -* `primary_key` - The Primary Key for the Authorization Rule. +* `primary_connection_string_alias` - The alias of the Primary Connection String for the Authorization Rule, which is generated when disaster recovery is enabled. + +* `secondary_connection_string_alias` - The alias of the Secondary Connection String for the Authorization Rule, which is generated when disaster recovery is enabled. * `primary_connection_string` - The Primary Connection String for the Authorization Rule. -* `secondary_key` - The Secondary Key for the Authorization Rule. +* `primary_key` - The Primary Key for the Authorization Rule. * `secondary_connection_string` - The Secondary Connection String for the Authorization Rule. +* `secondary_key` - The Secondary Key for the Authorization Rule. + ## Timeouts