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
Expand Up @@ -8,8 +8,8 @@ import (
"github.com/hashicorp/go-azure-sdk/resource-manager/eventhub/2021-11-01/disasterrecoveryconfigs"
"github.com/hashicorp/go-azure-sdk/resource-manager/eventhub/2021-11-01/eventhubs"
"github.com/hashicorp/go-azure-sdk/resource-manager/eventhub/2021-11-01/eventhubsclusters"
"github.com/hashicorp/go-azure-sdk/resource-manager/eventhub/2021-11-01/namespaces"
"github.com/hashicorp/go-azure-sdk/resource-manager/eventhub/2021-11-01/networkrulesets"
"github.com/hashicorp/go-azure-sdk/resource-manager/eventhub/2022-01-01-preview/namespaces"
"github.com/hashicorp/terraform-provider-azurerm/internal/common"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"time"

"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-sdk/resource-manager/eventhub/2021-11-01/namespaces"
"github.com/hashicorp/go-azure-sdk/resource-manager/eventhub/2022-01-01-preview/namespaces"
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/locks"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"testing"

"github.com/hashicorp/go-azure-sdk/resource-manager/eventhub/2021-11-01/namespaces"
"github.com/hashicorp/go-azure-sdk/resource-manager/eventhub/2022-01-01-preview/namespaces"
"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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/hashicorp/go-azure-helpers/resourcemanager/location"
"github.com/hashicorp/go-azure-helpers/resourcemanager/tags"
"github.com/hashicorp/go-azure-sdk/resource-manager/eventhub/2021-11-01/authorizationrulesnamespaces"
"github.com/hashicorp/go-azure-sdk/resource-manager/eventhub/2021-11-01/namespaces"
"github.com/hashicorp/go-azure-sdk/resource-manager/eventhub/2022-01-01-preview/namespaces"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/timeouts"
Expand Down
53 changes: 52 additions & 1 deletion internal/services/eventhub/eventhub_namespace_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import (
"github.com/hashicorp/go-azure-helpers/resourcemanager/tags"
"github.com/hashicorp/go-azure-sdk/resource-manager/eventhub/2021-11-01/authorizationrulesnamespaces"
"github.com/hashicorp/go-azure-sdk/resource-manager/eventhub/2021-11-01/eventhubsclusters"
"github.com/hashicorp/go-azure-sdk/resource-manager/eventhub/2021-11-01/namespaces"
"github.com/hashicorp/go-azure-sdk/resource-manager/eventhub/2021-11-01/networkrulesets"
"github.com/hashicorp/go-azure-sdk/resource-manager/eventhub/2022-01-01-preview/namespaces"
"github.com/hashicorp/terraform-provider-azurerm/helpers/azure"
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
Expand Down Expand Up @@ -190,6 +190,29 @@ func resourceEventHubNamespace() *pluginsdk.Resource {
},
},

"local_authentication_enabled": {
Type: pluginsdk.TypeBool,
Optional: true,
Default: true,
Copy link
Contributor

Choose a reason for hiding this comment

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

is this also the default state the API returns when provisioning on an older version and upgrading to a newer api version?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, I tried the older version and the default value is the same

},

"minimum_tls_version": {
Type: pluginsdk.TypeString,
Optional: true,
Default: string(namespaces.TlsVersionOnePointTwo),
ValidateFunc: validation.StringInSlice([]string{
string(namespaces.TlsVersionOnePointZero),
string(namespaces.TlsVersionOnePointOne),
string(namespaces.TlsVersionOnePointTwo),
}, false),
},

"public_network_access_enabled": {
Type: pluginsdk.TypeBool,
Optional: true,
Default: true,
},

"default_primary_connection_string_alias": {
Type: pluginsdk.TypeString,
Computed: true,
Expand Down Expand Up @@ -278,6 +301,13 @@ func resourceEventHubNamespaceCreate(d *pluginsdk.ResourceData, meta interface{}
return fmt.Errorf("expanding `identity`: %+v", err)
}

publicNetworkEnabled := namespaces.PublicNetworkAccessEnabled
if !d.Get("public_network_access_enabled").(bool) {
publicNetworkEnabled = namespaces.PublicNetworkAccessDisabled
}

miniTlsVersion := namespaces.TlsVersion(d.Get("minimum_tls_version").(string))

parameters := namespaces.EHNamespace{
Location: &location,
Sku: &namespaces.Sku{
Expand All @@ -292,6 +322,9 @@ func resourceEventHubNamespaceCreate(d *pluginsdk.ResourceData, meta interface{}
Properties: &namespaces.EHNamespaceProperties{
IsAutoInflateEnabled: utils.Bool(autoInflateEnabled),
ZoneRedundant: utils.Bool(zoneRedundant),
DisableLocalAuth: utils.Bool(!d.Get("local_authentication_enabled").(bool)),
PublicNetworkAccess: &publicNetworkEnabled,
MinimumTlsVersion: &miniTlsVersion,
},
Tags: tags.Expand(t),
}
Expand Down Expand Up @@ -346,6 +379,11 @@ func resourceEventHubNamespaceUpdate(d *pluginsdk.ResourceData, meta interface{}
t := d.Get("tags").(map[string]interface{})
autoInflateEnabled := d.Get("auto_inflate_enabled").(bool)
zoneRedundant := d.Get("zone_redundant").(bool)
publicNetworkEnabled := namespaces.PublicNetworkAccessEnabled
if !d.Get("public_network_access_enabled").(bool) {
publicNetworkEnabled = namespaces.PublicNetworkAccessDisabled
}
miniTlsVersion := namespaces.TlsVersion(d.Get("minimum_tls_version").(string))

identity, err := identity.ExpandSystemAndUserAssignedMap(d.Get("identity").([]interface{}))
if err != nil {
Expand All @@ -366,6 +404,9 @@ func resourceEventHubNamespaceUpdate(d *pluginsdk.ResourceData, meta interface{}
Properties: &namespaces.EHNamespaceProperties{
IsAutoInflateEnabled: utils.Bool(autoInflateEnabled),
ZoneRedundant: utils.Bool(zoneRedundant),
DisableLocalAuth: utils.Bool(!d.Get("local_authentication_enabled").(bool)),
PublicNetworkAccess: &publicNetworkEnabled,
MinimumTlsVersion: &miniTlsVersion,
},
Tags: tags.Expand(t),
}
Expand Down Expand Up @@ -471,6 +512,16 @@ 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_authentication_enabled", !localAuthEnable)
}
if props.PublicNetworkAccess != nil {
d.Set("public_network_access_enabled", *props.PublicNetworkAccess == namespaces.PublicNetworkAccessEnabled)
}
if props.MinimumTlsVersion != nil {
d.Set("minimum_tls_version", *props.MinimumTlsVersion)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

all 3 of these fields need to be set all of the time, with a default value if they're not returned e.g.

publicNetworkAccessEnabled := true
if props.PublicNetworkAccess != nil {
   *props.PublicNetworkAccess == namespaces.PublicNetworkAccessEnabled
}
d.Set("public_network_access_enabled", publicNetworkAccessEnabled)

}

if err := tags.FlattenAndSet(d, model.Tags); err != nil {
Expand Down
123 changes: 122 additions & 1 deletion internal/services/eventhub/eventhub_namespace_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"regexp"
"testing"

"github.com/hashicorp/go-azure-sdk/resource-manager/eventhub/2021-11-01/namespaces"
"github.com/hashicorp/go-azure-sdk/resource-manager/eventhub/2022-01-01-preview/namespaces"
"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"
Expand Down Expand Up @@ -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{}
Expand Down Expand Up @@ -428,6 +442,50 @@ func TestAccEventHubNamespace_maximumThroughputUnitsUpdate(t *testing.T) {
})
}

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

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.basic(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("public_network_access_enabled").HasValue("true"),
),
},
{
Config: r.publicNetworkAccessUpdate(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("public_network_access_enabled").HasValue("false"),
),
},
})
}

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

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.basic(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("minimum_tls_version").HasValue("1.2"),
),
},
{
Config: r.minimumTLSUpdate(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("minimum_tls_version").HasValue("1.1"),
),
},
})
}

func TestAccEventHubNamespace_autoInfalteDisabledWithAutoInflateUnits(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_eventhub_namespace", "test")
r := EventHubNamespaceResource{}
Expand Down Expand Up @@ -924,6 +982,69 @@ 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_authentication_enabled = false
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger)
}

func (EventHubNamespaceResource) publicNetworkAccessUpdate(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"
public_network_access_enabled = false
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger)
}

func (EventHubNamespaceResource) minimumTLSUpdate(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"
minimum_tls_version = "1.1"
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger)
}

func (EventHubNamespaceResource) maximumThroughputUnitsUpdate(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
Expand Down
2 changes: 1 addition & 1 deletion internal/services/eventhub/eventhub_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-sdk/resource-manager/eventhub/2021-11-01/eventhubs"
"github.com/hashicorp/go-azure-sdk/resource-manager/eventhub/2021-11-01/namespaces"
"github.com/hashicorp/go-azure-sdk/resource-manager/eventhub/2022-01-01-preview/namespaces"
"github.com/hashicorp/terraform-provider-azurerm/helpers/azure"
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading