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 all 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
28 changes: 20 additions & 8 deletions azurerm/helpers/azure/eventhub.go
Expand Up @@ -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": {
Expand All @@ -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)
}
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 @@ -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": {
Expand All @@ -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,
},
},
}
}
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,
"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": {
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("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)
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": {
"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,
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("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)
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)
}