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_servicebus_namespace; Adding support of property public_network_access_enabled, minimum_tls_version #17805

Merged
merged 4 commits into from
Aug 30, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
support new servicebus new properties in preview api
xiaxyi committed Jul 29, 2022
commit 5ddc939d9af707c426ecf92afec5cbefe19c118c
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ require (
github.com/google/go-cmp v0.5.8
github.com/google/uuid v1.1.2
github.com/hashicorp/go-azure-helpers v0.37.0
github.com/hashicorp/go-azure-sdk v0.20220725.1163004
github.com/hashicorp/go-azure-sdk v0.20220728.1092823
github.com/hashicorp/go-multierror v1.1.1
github.com/hashicorp/go-uuid v1.0.3
github.com/hashicorp/go-version v1.6.0
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -216,8 +216,8 @@ github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brv
github.com/hashicorp/go-azure-helpers v0.12.0/go.mod h1:Zc3v4DNeX6PDdy7NljlYpnrdac1++qNW0I4U+ofGwpg=
github.com/hashicorp/go-azure-helpers v0.37.0 h1:6UOoQ9esE4MJ4wHJr21qU81IJQ9zsXQ9FbANYUbeE4U=
github.com/hashicorp/go-azure-helpers v0.37.0/go.mod h1:gcutZ/Hf/O7YN9M3UIvyZ9l0Rxv7Yrc9x5sSfM9cuSw=
github.com/hashicorp/go-azure-sdk v0.20220725.1163004 h1:F6fxwMrEBiroVssWLY3/fIEJ4E6qJQfL1jvsnTYkHpU=
github.com/hashicorp/go-azure-sdk v0.20220725.1163004/go.mod h1:yjQPw8DCOtQR8E8+FNaTxF6yz+tyQGkDNiVAGCNoLOo=
github.com/hashicorp/go-azure-sdk v0.20220728.1092823 h1:+X1Lxb2oBQjRdV7KbhLsS/CS7LS5m/upl5rg4lzGeGI=
github.com/hashicorp/go-azure-sdk v0.20220728.1092823/go.mod h1:yjQPw8DCOtQR8E8+FNaTxF6yz+tyQGkDNiVAGCNoLOo=
github.com/hashicorp/go-checkpoint v0.5.0 h1:MFYpPZCnQqQTE18jFwSII6eUQrD/oxMFp3mlgcqk5mU=
github.com/hashicorp/go-checkpoint v0.5.0/go.mod h1:7nfLNL10NsxqO4iWuW6tWW0HjZuDrwkBuEQsVcpCOgg=
github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
2 changes: 1 addition & 1 deletion internal/services/servicebus/client/client.go
Original file line number Diff line number Diff line change
@@ -2,14 +2,14 @@ package client

import (
"github.com/hashicorp/go-azure-sdk/resource-manager/servicebus/2021-06-01-preview/disasterrecoveryconfigs"
"github.com/hashicorp/go-azure-sdk/resource-manager/servicebus/2021-06-01-preview/namespaces"
"github.com/hashicorp/go-azure-sdk/resource-manager/servicebus/2021-06-01-preview/namespacesauthorizationrule"
"github.com/hashicorp/go-azure-sdk/resource-manager/servicebus/2021-06-01-preview/queues"
"github.com/hashicorp/go-azure-sdk/resource-manager/servicebus/2021-06-01-preview/queuesauthorizationrule"
"github.com/hashicorp/go-azure-sdk/resource-manager/servicebus/2021-06-01-preview/rules"
"github.com/hashicorp/go-azure-sdk/resource-manager/servicebus/2021-06-01-preview/subscriptions"
"github.com/hashicorp/go-azure-sdk/resource-manager/servicebus/2021-06-01-preview/topics"
"github.com/hashicorp/go-azure-sdk/resource-manager/servicebus/2021-06-01-preview/topicsauthorizationrule"
"github.com/hashicorp/go-azure-sdk/resource-manager/servicebus/2022-01-01-preview/namespaces"
"github.com/hashicorp/terraform-provider-azurerm/internal/common"
)

2 changes: 1 addition & 1 deletion internal/services/servicebus/internal.go
Original file line number Diff line number Diff line change
@@ -8,8 +8,8 @@ import (
"time"

"github.com/hashicorp/go-azure-sdk/resource-manager/servicebus/2021-06-01-preview/disasterrecoveryconfigs"
"github.com/hashicorp/go-azure-sdk/resource-manager/servicebus/2021-06-01-preview/namespaces"
"github.com/hashicorp/go-azure-sdk/resource-manager/servicebus/2021-06-01-preview/namespacesauthorizationrule"
"github.com/hashicorp/go-azure-sdk/resource-manager/servicebus/2022-01-01-preview/namespaces"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
)
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ import (
"context"
"strings"

"github.com/hashicorp/go-azure-sdk/resource-manager/servicebus/2021-06-01-preview/namespaces"
"github.com/hashicorp/go-azure-sdk/resource-manager/servicebus/2022-01-01-preview/namespaces"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
)

Original file line number Diff line number Diff line change
@@ -6,8 +6,8 @@ import (

"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-helpers/resourcemanager/resourcegroups"
"github.com/hashicorp/go-azure-sdk/resource-manager/servicebus/2021-06-01-preview/namespaces"
"github.com/hashicorp/go-azure-sdk/resource-manager/servicebus/2021-06-01-preview/namespacesauthorizationrule"
"github.com/hashicorp/go-azure-sdk/resource-manager/servicebus/2022-01-01-preview/namespaces"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/servicebus/validate"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
Original file line number Diff line number Diff line change
@@ -5,8 +5,8 @@ import (
"time"

"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-sdk/resource-manager/servicebus/2021-06-01-preview/namespaces"
"github.com/hashicorp/go-azure-sdk/resource-manager/servicebus/2021-06-01-preview/namespacesauthorizationrule"
"github.com/hashicorp/go-azure-sdk/resource-manager/servicebus/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/services/servicebus/validate"
Original file line number Diff line number Diff line change
@@ -8,8 +8,8 @@ import (
"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema"
"github.com/hashicorp/go-azure-helpers/resourcemanager/location"
"github.com/hashicorp/go-azure-sdk/resource-manager/servicebus/2021-06-01-preview/namespaces"
"github.com/hashicorp/go-azure-sdk/resource-manager/servicebus/2021-06-01-preview/namespacesauthorizationrule"
"github.com/hashicorp/go-azure-sdk/resource-manager/servicebus/2022-01-01-preview/namespaces"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/tags"
"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/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-helpers/resourcemanager/resourcegroups"
"github.com/hashicorp/go-azure-sdk/resource-manager/servicebus/2021-06-01-preview/disasterrecoveryconfigs"
"github.com/hashicorp/go-azure-sdk/resource-manager/servicebus/2021-06-01-preview/namespaces"
"github.com/hashicorp/go-azure-sdk/resource-manager/servicebus/2022-01-01-preview/namespaces"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/servicebus/validate"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ import (
"time"

"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-sdk/resource-manager/servicebus/2021-06-01-preview/namespaces"
"github.com/hashicorp/go-azure-sdk/resource-manager/servicebus/2022-01-01-preview/namespaces"
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
validateNetwork "github.com/hashicorp/terraform-provider-azurerm/internal/services/network/validate"
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ import (
"fmt"
"testing"

"github.com/hashicorp/go-azure-sdk/resource-manager/servicebus/2021-06-01-preview/namespaces"
"github.com/hashicorp/go-azure-sdk/resource-manager/servicebus/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"
84 changes: 67 additions & 17 deletions internal/services/servicebus/servicebus_namespace_resource.go
Original file line number Diff line number Diff line change
@@ -12,8 +12,8 @@ import (
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema"
"github.com/hashicorp/go-azure-helpers/resourcemanager/identity"
"github.com/hashicorp/go-azure-helpers/resourcemanager/location"
"github.com/hashicorp/go-azure-sdk/resource-manager/servicebus/2021-06-01-preview/namespaces"
"github.com/hashicorp/go-azure-sdk/resource-manager/servicebus/2021-06-01-preview/namespacesauthorizationrule"
"github.com/hashicorp/go-azure-sdk/resource-manager/servicebus/2022-01-01-preview/namespaces"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-provider-azurerm/helpers/azure"
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
@@ -124,6 +124,23 @@ func resourceServiceBusNamespace() *pluginsdk.Resource {
Default: true,
},

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

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

"default_primary_connection_string": {
Type: pluginsdk.TypeString,
Computed: true,
@@ -157,21 +174,24 @@ func resourceServiceBusNamespace() *pluginsdk.Resource {
"tags": tags.Schema(),
},

CustomizeDiff: pluginsdk.CustomizeDiffShim(func(ctx context.Context, diff *pluginsdk.ResourceDiff, v interface{}) error {
oldCustomerManagedKey, newCustomerManagedKey := diff.GetChange("customer_managed_key")
if len(oldCustomerManagedKey.([]interface{})) != 0 && len(newCustomerManagedKey.([]interface{})) == 0 {
diff.ForceNew("customer_managed_key")
}
CustomizeDiff: pluginsdk.CustomDiffWithAll(
pluginsdk.CustomizeDiffShim(func(ctx context.Context, diff *pluginsdk.ResourceDiff, v interface{}) error {
oldCustomerManagedKey, newCustomerManagedKey := diff.GetChange("customer_managed_key")
if len(oldCustomerManagedKey.([]interface{})) != 0 && len(newCustomerManagedKey.([]interface{})) == 0 {
diff.ForceNew("customer_managed_key")
}

oldSku, newSku := diff.GetChange("sku")
if diff.HasChange("sku") {
if strings.EqualFold(newSku.(string), string(namespaces.SkuNamePremium)) || strings.EqualFold(oldSku.(string), string(namespaces.SkuNamePremium)) {
log.Printf("[DEBUG] cannot migrate a namespace from or to Premium SKU")
diff.ForceNew("sku")
oldSku, newSku := diff.GetChange("sku")
if diff.HasChange("sku") {
if strings.EqualFold(newSku.(string), string(namespaces.SkuNamePremium)) || strings.EqualFold(oldSku.(string), string(namespaces.SkuNamePremium)) {
log.Printf("[DEBUG] cannot migrate a namespace from or to Premium SKU")
diff.ForceNew("sku")
}
}
}
return nil
}),
return nil
}),
pluginsdk.CustomizeDiffShim(servicebusTLSVersionDiff),
),
}
}

@@ -206,6 +226,11 @@ func resourceServiceBusNamespaceCreateUpdate(d *pluginsdk.ResourceData, meta int
return fmt.Errorf("expanding `identity`: %+v", err)
}

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

s := namespaces.SkuTier(sku)
parameters := namespaces.SBNamespace{
Location: location,
@@ -215,13 +240,19 @@ func resourceServiceBusNamespaceCreateUpdate(d *pluginsdk.ResourceData, meta int
Tier: &s,
},
Properties: &namespaces.SBNamespaceProperties{
ZoneRedundant: utils.Bool(d.Get("zone_redundant").(bool)),
Encryption: expandServiceBusNamespaceEncryption(d.Get("customer_managed_key").([]interface{})),
DisableLocalAuth: utils.Bool(!d.Get("local_auth_enabled").(bool)),
ZoneRedundant: utils.Bool(d.Get("zone_redundant").(bool)),
Encryption: expandServiceBusNamespaceEncryption(d.Get("customer_managed_key").([]interface{})),
DisableLocalAuth: utils.Bool(!d.Get("local_auth_enabled").(bool)),
PublicNetworkAccess: &publicNetworkEnabled,
},
Tags: expandTags(t),
}

if tlsValue := d.Get("minimum_tls_version").(string); tlsValue != "" {
minimumTls := namespaces.TlsVersion(tlsValue)
parameters.Properties.MinimumTlsVersion = &minimumTls
}

if capacity := d.Get("capacity"); capacity != nil {
if !strings.EqualFold(sku, string(namespaces.SkuNamePremium)) && capacity.(int) > 0 {
return fmt.Errorf("Service Bus SKU %q only supports `capacity` of 0", sku)
@@ -298,7 +329,18 @@ func resourceServiceBusNamespaceRead(d *pluginsdk.ResourceData, meta interface{}
localAuthEnabled = !*props.DisableLocalAuth
}
d.Set("local_auth_enabled", localAuthEnabled)

publicNetworkAccess := true
if props.PublicNetworkAccess != nil && *props.PublicNetworkAccess == namespaces.PublicNetworkAccessDisabled {
publicNetworkAccess = false
}
d.Set("public_network_access_enabled", publicNetworkAccess)

if props.MinimumTlsVersion != nil {
d.Set("minimum_tls_version", *props.MinimumTlsVersion)
}
}

}

authRuleId := namespacesauthorizationrule.NewAuthorizationRuleID(id.SubscriptionId, id.ResourceGroupName, id.NamespaceName, serviceBusNamespaceDefaultAuthorizationRule)
@@ -425,3 +467,11 @@ func expandSystemAndUserAssignedMap(input []interface{}) (*identity.SystemAndUse
IdentityIds: identityIds,
}, nil
}

func servicebusTLSVersionDiff(ctx context.Context, d *pluginsdk.ResourceDiff, _ interface{}) (err error) {
old, new := d.GetChange("minimum_tls_version")
if old != "" && new == "" {
err = fmt.Errorf("`minimum_tls_version` has been set before, please set a valid value for this property ")
}
return
}
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ import (
"regexp"
"testing"

"github.com/hashicorp/go-azure-sdk/resource-manager/servicebus/2021-06-01-preview/namespaces"
"github.com/hashicorp/go-azure-sdk/resource-manager/servicebus/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"
@@ -206,6 +206,50 @@ func TestAccAzureRMServiceBusNamespace_customerManagedKey(t *testing.T) {
})
}

func TestAccAzureRMServiceBusNamespace_publicNetworkAccessUpdate(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_servicebus_namespace", "test")
r := ServiceBusNamespaceResource{}

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 TestAccAzureRMServiceBusNamespace_minimumTLSUpdate(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_servicebus_namespace", "test")
r := ServiceBusNamespaceResource{}

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 (t ServiceBusNamespaceResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) {
id, err := namespaces.ParseNamespaceID(state.ID)
if err != nil {
@@ -558,3 +602,45 @@ resource "azurerm_servicebus_namespace" "test" {
}
`, data.Locations.Primary, data.RandomInteger, data.RandomString)
}

func (ServiceBusNamespaceResource) publicNetworkAccessUpdate(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}

resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "%s"
}

resource "azurerm_servicebus_namespace" "test" {
name = "acctestservicebusnamespace-%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 (ServiceBusNamespaceResource) minimumTLSUpdate(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}

resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "%s"
}

resource "azurerm_servicebus_namespace" "test" {
name = "acctestservicebusnamespace-%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)
}
Original file line number Diff line number Diff line change
@@ -6,9 +6,9 @@ import (
"time"

"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-sdk/resource-manager/servicebus/2021-06-01-preview/namespaces"
"github.com/hashicorp/go-azure-sdk/resource-manager/servicebus/2021-06-01-preview/queues"
"github.com/hashicorp/go-azure-sdk/resource-manager/servicebus/2021-06-01-preview/queuesauthorizationrule"
"github.com/hashicorp/go-azure-sdk/resource-manager/servicebus/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/services/servicebus/validate"
Original file line number Diff line number Diff line change
@@ -6,8 +6,8 @@ import (

"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-helpers/resourcemanager/resourcegroups"
"github.com/hashicorp/go-azure-sdk/resource-manager/servicebus/2021-06-01-preview/namespaces"
"github.com/hashicorp/go-azure-sdk/resource-manager/servicebus/2021-06-01-preview/queues"
"github.com/hashicorp/go-azure-sdk/resource-manager/servicebus/2022-01-01-preview/namespaces"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/servicebus/validate"
azValidate "github.com/hashicorp/terraform-provider-azurerm/internal/services/servicebus/validate"
Original file line number Diff line number Diff line change
@@ -5,8 +5,8 @@ import (
"time"

"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-sdk/resource-manager/servicebus/2021-06-01-preview/namespaces"
"github.com/hashicorp/go-azure-sdk/resource-manager/servicebus/2021-06-01-preview/queues"
"github.com/hashicorp/go-azure-sdk/resource-manager/servicebus/2022-01-01-preview/namespaces"
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
"github.com/hashicorp/terraform-provider-azurerm/helpers/validate"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
Original file line number Diff line number Diff line change
@@ -6,9 +6,9 @@ import (
"time"

"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-sdk/resource-manager/servicebus/2021-06-01-preview/namespaces"
"github.com/hashicorp/go-azure-sdk/resource-manager/servicebus/2021-06-01-preview/topics"
"github.com/hashicorp/go-azure-sdk/resource-manager/servicebus/2021-06-01-preview/topicsauthorizationrule"
"github.com/hashicorp/go-azure-sdk/resource-manager/servicebus/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/services/servicebus/validate"
Loading