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

azurerm_eventhub_namespace: support latest released properties:local_authentication_enabled,public_network_access_enabled,minimum_tls_version #17194

Merged
merged 15 commits into from
Aug 4, 2022
Merged
2 changes: 1 addition & 1 deletion internal/services/eventhub/client/client.go
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ import (
"github.com/hashicorp/terraform-provider-azurerm/internal/services/eventhub/sdk/2017-04-01/eventhubs"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/eventhub/sdk/2018-01-01-preview/eventhubsclusters"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/eventhub/sdk/2018-01-01-preview/networkrulesets"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/eventhub/sdk/2021-01-01-preview/namespaces"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/eventhub/sdk/2021-11-01/namespaces"
)

type Client struct {
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ import (
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/locks"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/eventhub/sdk/2021-01-01-preview/namespaces"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/eventhub/sdk/2021-11-01/namespaces"
keyVaultParse "github.com/hashicorp/terraform-provider-azurerm/internal/services/keyvault/parse"
keyVaultValidate "github.com/hashicorp/terraform-provider-azurerm/internal/services/keyvault/validate"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ import (
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance"
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/eventhub/sdk/2021-01-01-preview/namespaces"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/eventhub/sdk/2021-11-01/namespaces"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/utils"
)
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ import (
"github.com/hashicorp/go-azure-helpers/resourcemanager/tags"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/eventhub/sdk/2017-04-01/authorizationrulesnamespaces"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/eventhub/sdk/2021-01-01-preview/namespaces"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/eventhub/sdk/2021-11-01/namespaces"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/timeouts"
)
34 changes: 22 additions & 12 deletions internal/services/eventhub/eventhub_namespace_resource.go
Original file line number Diff line number Diff line change
@@ -17,11 +17,10 @@ import (
"github.com/hashicorp/terraform-provider-azurerm/helpers/azure"
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
legacyIdentity "github.com/hashicorp/terraform-provider-azurerm/internal/identity"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/eventhub/sdk/2017-04-01/authorizationrulesnamespaces"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/eventhub/sdk/2018-01-01-preview/eventhubsclusters"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/eventhub/sdk/2018-01-01-preview/networkrulesets"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/eventhub/sdk/2021-01-01-preview/namespaces"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/eventhub/sdk/2021-11-01/namespaces"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/eventhub/validate"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/suppress"
@@ -191,6 +190,12 @@ func resourceEventHubNamespace() *pluginsdk.Resource {
},
},

"local_auth_enabled": {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
"local_auth_enabled": {
"local_authentication_enabled": {

Type: pluginsdk.TypeBool,
Optional: true,
Default: true,
},

"default_primary_connection_string_alias": {
Type: pluginsdk.TypeString,
Computed: true,
@@ -293,6 +298,7 @@ func resourceEventHubNamespaceCreate(d *pluginsdk.ResourceData, meta interface{}
Properties: &namespaces.EHNamespaceProperties{
IsAutoInflateEnabled: utils.Bool(autoInflateEnabled),
ZoneRedundant: utils.Bool(zoneRedundant),
DisableLocalAuth: utils.Bool(!d.Get("local_auth_enabled").(bool)),
},
Tags: tags.Expand(t),
}
@@ -373,6 +379,7 @@ func resourceEventHubNamespaceUpdate(d *pluginsdk.ResourceData, meta interface{}
Properties: &namespaces.EHNamespaceProperties{
IsAutoInflateEnabled: utils.Bool(autoInflateEnabled),
ZoneRedundant: utils.Bool(zoneRedundant),
DisableLocalAuth: utils.Bool(!d.Get("local_auth_enabled").(bool)),
},
Tags: tags.Expand(t),
}
@@ -468,6 +475,10 @@ func resourceEventHubNamespaceRead(d *pluginsdk.ResourceData, meta interface{})
d.Set("maximum_throughput_units", int(*props.MaximumThroughputUnits))
d.Set("zone_redundant", props.ZoneRedundant)
d.Set("dedicated_cluster_id", props.ClusterArmId)
if props.DisableLocalAuth != nil {
localAuthEnable := *props.DisableLocalAuth
d.Set("local_auth_enabled", !localAuthEnable)
}
}

if err := tags.FlattenAndSet(d, model.Tags); err != nil {
@@ -674,30 +685,29 @@ func flattenEventHubNamespaceNetworkRuleset(ruleset networkrulesets.NamespacesGe
}}
}

func expandEventHubIdentity(input []interface{}) (*legacyIdentity.SystemUserAssignedIdentityMap, error) {
func expandEventHubIdentity(input []interface{}) (*identity.SystemAndUserAssignedMap, error) {
expanded, err := identity.ExpandSystemAssigned(input)
if err != nil {
return nil, err
}

result := legacyIdentity.SystemUserAssignedIdentityMap{
Type: legacyIdentity.Type(string(expanded.Type)),
PrincipalId: &expanded.PrincipalId,
TenantId: &expanded.TenantId,
result := identity.SystemAndUserAssignedMap{
Type: expanded.Type,
PrincipalId: expanded.PrincipalId,
TenantId: expanded.TenantId,
}
return &result, nil
}

func flattenEventHubIdentity(input *legacyIdentity.SystemUserAssignedIdentityMap) []interface{} {
func flattenEventHubIdentity(input *identity.SystemAndUserAssignedMap) []interface{} {
if input == nil {
return []interface{}{}
}

legacyConfig := input.ToExpandedConfig()
return identity.FlattenSystemAssigned(&identity.SystemAssigned{
Type: identity.Type(string(legacyConfig.Type)),
PrincipalId: legacyConfig.PrincipalId,
TenantId: legacyConfig.TenantId,
Type: input.Type,
PrincipalId: input.PrincipalId,
TenantId: input.TenantId,
})
}

37 changes: 36 additions & 1 deletion internal/services/eventhub/eventhub_namespace_resource_test.go
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ import (
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance"
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/eventhub/sdk/2021-01-01-preview/namespaces"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/eventhub/sdk/2021-11-01/namespaces"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/utils"
)
@@ -326,6 +326,20 @@ func TestAccEventHubNamespace_BasicWithCapacity(t *testing.T) {
})
}

func TestAccEventHubNamespace_BasicWithLocalAuthProperty(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_eventhub_namespace", "test")
r := EventHubNamespaceResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.localAuthProperty(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
})
}

func TestAccEventHubNamespace_BasicWithCapacityUpdate(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_eventhub_namespace", "test")
r := EventHubNamespaceResource{}
@@ -924,6 +938,27 @@ resource "azurerm_eventhub_namespace" "test" {
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, capacity)
}

func (EventHubNamespaceResource) localAuthProperty(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "%s"
}
resource "azurerm_eventhub_namespace" "test" {
name = "acctesteventhubnamespace-%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
sku = "Basic"
local_auth_enabled = false
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger)
}

func (EventHubNamespaceResource) maximumThroughputUnitsUpdate(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
2 changes: 1 addition & 1 deletion internal/services/eventhub/eventhub_resource.go
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ import (
"github.com/hashicorp/terraform-provider-azurerm/helpers/azure"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/eventhub/sdk/2017-04-01/eventhubs"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/eventhub/sdk/2021-01-01-preview/namespaces"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/eventhub/sdk/2021-11-01/namespaces"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/eventhub/validate"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation"

This file was deleted.

Loading