Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support alias connection strings for eventhub resources #6708

Merged
merged 7 commits into from May 7, 2020
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 14 additions & 2 deletions azurerm/helpers/azure/eventhub.go
Expand Up @@ -100,7 +100,13 @@ func EventHubAuthorizationRuleSchemaFrom(s map[string]*schema.Schema) map[string
Default: false,
},

"primary_key": {
"primary_connection_string_alias": {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these are not ordered correctly?

Type: schema.TypeString,
Computed: true,
Sensitive: true,
},

"secondary_connection_string_alias": {
Type: schema.TypeString,
Computed: true,
Sensitive: true,
Expand All @@ -112,7 +118,7 @@ func EventHubAuthorizationRuleSchemaFrom(s map[string]*schema.Schema) map[string
Sensitive: true,
},

"secondary_key": {
"primary_key": {
Type: schema.TypeString,
Computed: true,
Sensitive: true,
Expand All @@ -123,6 +129,12 @@ func EventHubAuthorizationRuleSchemaFrom(s map[string]*schema.Schema) map[string
Computed: true,
Sensitive: true,
},

"secondary_key": {
Type: schema.TypeString,
Computed: true,
Sensitive: true,
},
}
return MergeSchema(s, authSchema)
}
Expand Down
Expand Up @@ -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
}
Expand Up @@ -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
}
Expand Down
Expand Up @@ -34,12 +34,19 @@ func dataSourceEventHubNamespaceAuthorizationRule() *schema.Resource {

"resource_group_name": azure.SchemaResourceGroupNameForDataSource(),

"listen": {
Type: schema.TypeBool,
Computed: true,
"primary_connection_string_alias": {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these are not ordered correctly?

Type: schema.TypeString,
Computed: true,
Sensitive: true,
},

"send": {
"secondary_connection_string_alias": {
Type: schema.TypeString,
Computed: true,
Sensitive: true,
},

"listen": {
Type: schema.TypeBool,
Computed: true,
},
Expand All @@ -49,29 +56,34 @@ func dataSourceEventHubNamespaceAuthorizationRule() *schema.Resource {
Computed: true,
},

"primary_key": {
"primary_connection_string": {
Type: schema.TypeString,
Computed: true,
Sensitive: true,
},

"primary_connection_string": {
"primary_key": {
Type: schema.TypeString,
Computed: true,
Sensitive: true,
},

"secondary_key": {
"secondary_connection_string": {
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,
},
},
}
}
Expand Down Expand Up @@ -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
}
Expand Up @@ -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
}
Expand Down
Expand Up @@ -31,21 +31,28 @@ func dataSourceEventHubNamespace() *schema.Resource {

"location": azure.SchemaLocationForDataSource(),

"sku": {
Type: schema.TypeString,
Computed: true,
"alias_default_primary_connection_string": {
Type: schema.TypeString,
Computed: true,
Sensitive: true,
},

"capacity": {
Type: schema.TypeInt,
Computed: true,
"alias_default_secondary_connection_string": {
Type: schema.TypeString,
Computed: true,
Sensitive: true,
},

"auto_inflate_enabled": {
Type: schema.TypeBool,
Computed: true,
},

"capacity": {
Type: schema.TypeInt,
Computed: true,
},

"kafka_enabled": {
Type: schema.TypeBool,
Computed: true,
Expand All @@ -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,
Expand All @@ -80,6 +87,11 @@ func dataSourceEventHubNamespace() *schema.Resource {
Sensitive: true,
},

"sku": {
Type: schema.TypeString,
Computed: true,
},

"tags": tags.SchemaDataSource(),
},
}
Expand Down Expand Up @@ -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("alias_default_primary_connection_string", keys.AliasPrimaryConnectionString)
d.Set("alias_default_secondary_connection_string", 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)
Expand Down
18 changes: 16 additions & 2 deletions azurerm/internal/services/eventhub/eventhub_namespace_resource.go
Expand Up @@ -158,13 +158,19 @@ func resourceArmEventHubNamespace() *schema.Resource {
},
},

"default_primary_connection_string": {
"alias_default_primary_connection_string": {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you missed on here?

Type: schema.TypeString,
Computed: true,
Sensitive: true,
},

"default_secondary_connection_string": {
"alias_default_secondary_connection_string": {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you missed on here?

Type: schema.TypeString,
Computed: true,
Sensitive: true,
},

"default_primary_connection_string": {
Type: schema.TypeString,
Computed: true,
Sensitive: true,
Expand All @@ -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,
Expand Down Expand Up @@ -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("alias_default_primary_connection_string", keys.AliasPrimaryConnectionString)
d.Set("alias_default_secondary_connection_string", 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)
Expand Down
Expand Up @@ -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(`
Expand All @@ -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)
}
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}