From 4956f95b4d1708cc9dfb34cb96c1b58e794872b2 Mon Sep 17 00:00:00 2001
From: catriona-m <86247157+catriona-m@users.noreply.github.com>
Date: Mon, 9 Sep 2024 14:18:43 +0100
Subject: [PATCH] fix defaults and remove 4.0 flags (#27305)

---
 .../servicebus/servicebus_queue_resource.go   | 133 ++----------------
 .../servicebus_queue_resource_test.go         |   2 +-
 website/docs/r/servicebus_queue.html.markdown |   8 +-
 3 files changed, 17 insertions(+), 126 deletions(-)

diff --git a/internal/services/servicebus/servicebus_queue_resource.go b/internal/services/servicebus/servicebus_queue_resource.go
index 579c5712ceec..b4df3f33be4b 100644
--- a/internal/services/servicebus/servicebus_queue_resource.go
+++ b/internal/services/servicebus/servicebus_queue_resource.go
@@ -16,7 +16,6 @@ import (
 	"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
 	"github.com/hashicorp/terraform-provider-azurerm/helpers/validate"
 	"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
-	"github.com/hashicorp/terraform-provider-azurerm/internal/features"
 	azValidate "github.com/hashicorp/terraform-provider-azurerm/internal/services/servicebus/validate"
 	"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
 	"github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation"
@@ -48,7 +47,7 @@ func resourceServiceBusQueue() *pluginsdk.Resource {
 }
 
 func resourceServicebusQueueSchema() map[string]*pluginsdk.Schema {
-	schema := map[string]*pluginsdk.Schema{
+	return map[string]*pluginsdk.Schema{
 		"name": {
 			Type:         pluginsdk.TypeString,
 			Required:     true,
@@ -65,9 +64,10 @@ func resourceServicebusQueueSchema() map[string]*pluginsdk.Schema {
 		},
 
 		"auto_delete_on_idle": {
-			Type:         pluginsdk.TypeString,
-			Optional:     true,
-			Default:      "P10675199DT2H48M5.4775807S", // Never
+			Type:     pluginsdk.TypeString,
+			Optional: true,
+			// NOTE: O+C this gets a default except when using basic sku and can be updated without issues
+			Computed:     true,
 			ValidateFunc: validate.ISO8601Duration,
 		},
 
@@ -78,9 +78,10 @@ func resourceServicebusQueueSchema() map[string]*pluginsdk.Schema {
 		},
 
 		"default_message_ttl": {
-			Type:         pluginsdk.TypeString,
-			Optional:     true,
-			Default:      "P10675199DT2H48M5.4775807S", // Unbounded
+			Type:     pluginsdk.TypeString,
+			Optional: true,
+			// NOTE: O+C this gets a default of "P10675199DT2H48M5.4775807S" (Unbounded) and "P14D" in Basic sku and can be updated without issues
+			Computed:     true,
 			ValidateFunc: validate.ISO8601Duration,
 		},
 
@@ -181,84 +182,6 @@ func resourceServicebusQueueSchema() map[string]*pluginsdk.Schema {
 			}, false),
 		},
 	}
-
-	if !features.FourPointOhBeta() {
-		schema["auto_delete_on_idle"] = &pluginsdk.Schema{
-			Type:         pluginsdk.TypeString,
-			Optional:     true,
-			Computed:     true,
-			ValidateFunc: validate.ISO8601Duration,
-		}
-
-		schema["default_message_ttl"] = &pluginsdk.Schema{
-			Type:         pluginsdk.TypeString,
-			Optional:     true,
-			Computed:     true,
-			ValidateFunc: validate.ISO8601Duration,
-		}
-
-		schema["duplicate_detection_history_time_window"] = &pluginsdk.Schema{
-			Type:         pluginsdk.TypeString,
-			Optional:     true,
-			Computed:     true,
-			ValidateFunc: validate.ISO8601Duration,
-		}
-
-		schema["enable_batched_operations"] = &pluginsdk.Schema{
-			Type:          pluginsdk.TypeBool,
-			Optional:      true,
-			Default:       true,
-			ConflictsWith: []string{"batched_operations_enabled"},
-			Deprecated:    "The property `enable_batched_operations` has been superseded by `batched_operations_enabled` and will be removed in v4.0 of the AzureRM Provider.",
-		}
-
-		schema["enable_express"] = &pluginsdk.Schema{
-			Type:          pluginsdk.TypeBool,
-			Optional:      true,
-			Default:       false,
-			ConflictsWith: []string{"express_enabled"},
-			Deprecated:    "The property `enable_express` has been superseded by `express_enabled` and will be removed in v4.0 of the AzureRM Provider.",
-		}
-
-		schema["enable_partitioning"] = &pluginsdk.Schema{
-			Type:          pluginsdk.TypeBool,
-			Optional:      true,
-			ForceNew:      true,
-			Default:       false,
-			ConflictsWith: []string{"partitioning_enabled"},
-			Deprecated:    "The property `enable_partitioning` has been superseded by `partitioning_enabled` and will be removed in v4.0 of the AzureRM Provider.",
-		}
-
-		schema["batched_operations_enabled"] = &pluginsdk.Schema{
-			Type:          pluginsdk.TypeBool,
-			Optional:      true,
-			Computed:      true,
-			ConflictsWith: []string{"enable_batched_operations"},
-		}
-
-		schema["express_enabled"] = &pluginsdk.Schema{
-			Type:          pluginsdk.TypeBool,
-			Optional:      true,
-			Computed:      true,
-			ConflictsWith: []string{"enable_express"},
-		}
-
-		schema["partitioning_enabled"] = &pluginsdk.Schema{
-			Type:          pluginsdk.TypeBool,
-			Optional:      true,
-			Computed:      true,
-			ForceNew:      true,
-			ConflictsWith: []string{"enable_partitioning"},
-		}
-
-		schema["lock_duration"] = &pluginsdk.Schema{
-			Type:     pluginsdk.TypeString,
-			Optional: true,
-			Computed: true,
-		}
-	}
-
-	return schema
 }
 
 func resourceServiceBusQueueCreateUpdate(d *pluginsdk.ResourceData, meta interface{}) error {
@@ -323,35 +246,9 @@ func resourceServiceBusQueueCreateUpdate(d *pluginsdk.ResourceData, meta interfa
 	userConfig["autoDeleteOnIdle"] = autoDeleteOnIdle
 	duplicateDetectionHistoryTimeWindow := d.Get("duplicate_detection_history_time_window").(string)
 
-	enableExpress := false
-	enablePartitioning := false
-	enableBatchedOperations := true
-	if v := d.GetRawConfig().AsValueMap()["express_enabled"]; !v.IsNull() {
-		enableExpress = d.Get("express_enabled").(bool)
-	}
-
-	if v := d.GetRawConfig().AsValueMap()["partitioning_enabled"]; !v.IsNull() {
-		enablePartitioning = d.Get("partitioning_enabled").(bool)
-	}
-
-	if v := d.GetRawConfig().AsValueMap()["batched_operations_enabled"]; !v.IsNull() {
-		enableBatchedOperations = d.Get("batched_operations_enabled").(bool)
-	}
-
-	if !features.FourPointOhBeta() {
-
-		if v := d.GetRawConfig().AsValueMap()["enable_express"]; !v.IsNull() {
-			enableExpress = d.Get("enable_express").(bool)
-		}
-
-		if v := d.GetRawConfig().AsValueMap()["enable_partitioning"]; !v.IsNull() {
-			enablePartitioning = d.Get("enable_partitioning").(bool)
-		}
-
-		if v := d.GetRawConfig().AsValueMap()["enable_batched_operations"]; !v.IsNull() {
-			enableBatchedOperations = d.Get("enable_batched_operations").(bool)
-		}
-	}
+	enableExpress := d.Get("express_enabled").(bool)
+	enablePartitioning := d.Get("partitioning_enabled").(bool)
+	enableBatchedOperations := d.Get("batched_operations_enabled").(bool)
 
 	userConfig["enableExpress"] = enableExpress
 	userConfig["enablePartitioning"] = enablePartitioning
@@ -496,12 +393,6 @@ func resourceServiceBusQueueRead(d *pluginsdk.ResourceData, meta interface{}) er
 			d.Set("requires_session", props.RequiresSession)
 			d.Set("status", string(pointer.From(props.Status)))
 
-			if !features.FourPointOhBeta() {
-				d.Set("enable_batched_operations", props.EnableBatchedOperations)
-				d.Set("enable_express", props.EnableExpress)
-				d.Set("enable_partitioning", props.EnablePartitioning)
-			}
-
 			d.Set("batched_operations_enabled", props.EnableBatchedOperations)
 			d.Set("express_enabled", props.EnableExpress)
 			d.Set("partitioning_enabled", props.EnablePartitioning)
diff --git a/internal/services/servicebus/servicebus_queue_resource_test.go b/internal/services/servicebus/servicebus_queue_resource_test.go
index be07c5546c7c..a7fdf7cad532 100644
--- a/internal/services/servicebus/servicebus_queue_resource_test.go
+++ b/internal/services/servicebus/servicebus_queue_resource_test.go
@@ -406,7 +406,7 @@ resource "azurerm_servicebus_namespace" "test" {
   name                = "acctestservicebusnamespace-%d"
   resource_group_name = azurerm_resource_group.test.name
   location            = azurerm_resource_group.test.location
-  sku                 = "Standard"
+  sku                 = "Basic"
 }
 
 resource "azurerm_servicebus_queue" "test" {
diff --git a/website/docs/r/servicebus_queue.html.markdown b/website/docs/r/servicebus_queue.html.markdown
index 82dfc089171e..686b75610757 100644
--- a/website/docs/r/servicebus_queue.html.markdown
+++ b/website/docs/r/servicebus_queue.html.markdown
@@ -47,15 +47,15 @@ The following arguments are supported:
 
 * `lock_duration` - (Optional) The ISO 8601 timespan duration of a peek-lock; that is, the amount of time that the message is locked for other receivers. Maximum value is 5 minutes. Defaults to `PT1M` (1 Minute).
 
-* `max_message_size_in_kilobytes` - (Optional) Integer value which controls the maximum size of a message allowed on the queue for Premium SKU. For supported values see the "Large messages support" section of [this document](https://docs.microsoft.com/azure/service-bus-messaging/service-bus-premium-messaging#large-messages-support-preview). Defaults to `256`.
+* `max_message_size_in_kilobytes` - (Optional) Integer value which controls the maximum size of a message allowed on the queue for Premium SKU. For supported values see the "Large messages support" section of [this document](https://docs.microsoft.com/azure/service-bus-messaging/service-bus-premium-messaging#large-messages-support-preview).
 
-* `max_size_in_megabytes` - (Optional) Integer value which controls the size of memory allocated for the queue. For supported values see the "Queue or topic size" section of [Service Bus Quotas](https://docs.microsoft.com/azure/service-bus-messaging/service-bus-quotas). Defaults to `5120`.
+* `max_size_in_megabytes` - (Optional) Integer value which controls the size of memory allocated for the queue. For supported values see the "Queue or topic size" section of [Service Bus Quotas](https://docs.microsoft.com/azure/service-bus-messaging/service-bus-quotas).
 
 * `requires_duplicate_detection` - (Optional) Boolean flag which controls whether the Queue requires duplicate detection. Changing this forces a new resource to be created. Defaults to `false`.
 
 * `requires_session` - (Optional) Boolean flag which controls whether the Queue requires sessions. This will allow ordered handling of unbounded sequences of related messages. With sessions enabled a queue can guarantee first-in-first-out delivery of messages. Changing this forces a new resource to be created. Defaults to `false`.
 
-* `default_message_ttl` - (Optional) The ISO 8601 timespan duration of the TTL of messages sent to this queue. This is the default value used when TTL is not set on message itself. Defaults to `P10675199DT2H48M5.4775807S`.
+* `default_message_ttl` - (Optional) The ISO 8601 timespan duration of the TTL of messages sent to this queue. This is the default value used when TTL is not set on message itself.
 
 * `dead_lettering_on_message_expiration` - (Optional) Boolean flag which controls whether the Queue has dead letter support when a message expires. Defaults to `false`.
 
@@ -67,7 +67,7 @@ The following arguments are supported:
 
 * `batched_operations_enabled` - (Optional) Boolean flag which controls whether server-side batched operations are enabled. Defaults to `true`.
 
-* `auto_delete_on_idle` - (Optional) The ISO 8601 timespan duration of the idle interval after which the Queue is automatically deleted, minimum of 5 minutes. Defaults to `P10675199DT2H48M5.4775807S`.
+* `auto_delete_on_idle` - (Optional) The ISO 8601 timespan duration of the idle interval after which the Queue is automatically deleted, minimum of 5 minutes.
 
 * `partitioning_enabled` - (Optional) Boolean flag which controls whether to enable the queue to be partitioned across multiple message brokers. Changing this forces a new resource to be created. Defaults to `false` for Basic and Standard.