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_signalr_service - deprecate features block in favour of connectivity_logs_enabled, messaging_logs_enabled and service_mode #14360

Merged
merged 6 commits into from
Dec 7, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
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
106 changes: 92 additions & 14 deletions internal/services/signalr/signalr_service_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,15 @@ func resourceArmSignalRService() *pluginsdk.Resource {
},
},

// TODO: Remove in 3.0
"features": {
Type: pluginsdk.TypeSet,
Optional: true,
Computed: true,
Type: pluginsdk.TypeSet,
Optional: true,
Computed: true,
Deprecated: "Deprecated in favour of `connectivity_logs_enabled`, `messaging_logs_enabled` and `service_mode`",
ConflictsWith: []string{
"connectivity_logs_enabled", "messaging_logs_enabled", "service_mode",
},
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"flag": {
Expand All @@ -106,6 +111,46 @@ func resourceArmSignalRService() *pluginsdk.Resource {
},
},

"connectivity_logs_enabled": {
Type: pluginsdk.TypeString,
Optional: true,
Computed: true,
ConflictsWith: []string{
"features",
},
ValidateFunc: validation.StringInSlice([]string{
"True",
"False",
}, false),
catriona-m marked this conversation as resolved.
Show resolved Hide resolved
},

"messaging_logs_enabled": {
Type: pluginsdk.TypeString,
Optional: true,
Computed: true,
ConflictsWith: []string{
"features",
},
ValidateFunc: validation.StringInSlice([]string{
"True",
"False",
}, false),
catriona-m marked this conversation as resolved.
Show resolved Hide resolved
},

"service_mode": {
Type: pluginsdk.TypeString,
Optional: true,
Computed: true,
ConflictsWith: []string{
"features",
},
ValidateFunc: validation.StringInSlice([]string{
"Serverless",
"Classic",
"Default",
}, false),
Copy link
Contributor

Choose a reason for hiding this comment

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

is there a default value for this ("Default"?) - also this shouldn't be computed

Copy link
Member Author

Choose a reason for hiding this comment

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

I've had to make these computed so the deprecation will function correctly, but I've left a note to remove for 3.0

},

"upstream_endpoint": {
Type: pluginsdk.TypeSet,
Optional: true,
Expand Down Expand Up @@ -235,10 +280,14 @@ func resourceArmSignalRServiceCreate(d *pluginsdk.ResourceData, meta interface{}

sku := d.Get("sku").([]interface{})
featureFlags := d.Get("features").(*pluginsdk.Set).List()
connectivityLogsEnabled := d.Get("connectivity_logs_enabled").(string)
messagingLogsEnabled := d.Get("messaging_logs_enabled").(string)
serviceMode := d.Get("service_mode").(string)

cors := d.Get("cors").([]interface{})
upstreamSettings := d.Get("upstream_endpoint").(*pluginsdk.Set).List()

expandedFeatures := expandSignalRFeatures(featureFlags)
expandedFeatures := expandSignalRFeatures(featureFlags, connectivityLogsEnabled, messagingLogsEnabled, serviceMode)

// Upstream configurations are only allowed when the SignalR service is in `Serverless` mode
if len(upstreamSettings) > 0 && !signalRIsInServerlessMode(expandedFeatures) {
Expand Down Expand Up @@ -310,6 +359,18 @@ func resourceArmSignalRServiceRead(d *pluginsdk.ResourceData, meta interface{})
return fmt.Errorf("setting `features`: %+v", err)
}

for _, feature := range *props.Features {
if feature.Flag == signalr.FeatureFlagsEnableConnectivityLogs {
d.Set("connectivity_logs_enabled", feature.Value)
}
if feature.Flag == signalr.FeatureFlagsEnableMessagingLogs {
d.Set("messaging_logs_enabled", feature.Value)
}
if feature.Flag == signalr.FeatureFlagsServiceMode {
d.Set("service_mode", feature.Value)
}
}
catriona-m marked this conversation as resolved.
Show resolved Hide resolved

if err := d.Set("cors", flattenSignalRCors(props.Cors)); err != nil {
return fmt.Errorf("setting `cors`: %+v", err)
}
Expand Down Expand Up @@ -354,9 +415,12 @@ func resourceArmSignalRServiceUpdate(d *pluginsdk.ResourceData, meta interface{}
resourceType.Properties.Cors = expandSignalRCors(corsRaw)
}

if d.HasChange("features") {
if d.HasChange("features") || d.HasChange("connectivity_logs_enabled") || d.HasChange("messaging_logs_enabled") || d.HasChange("service_mode") {
featuresRaw := d.Get("features").(*pluginsdk.Set).List()
resourceType.Properties.Features = expandSignalRFeatures(featuresRaw)
connectivityLogsEnabled := d.Get("connectivity_logs_enabled").(string)
messagingLogsEnabled := d.Get("messaging_logs_enabled").(string)
serviceMode := d.Get("service_mode").(string)
resourceType.Properties.Features = expandSignalRFeatures(featuresRaw, connectivityLogsEnabled, messagingLogsEnabled, serviceMode)
}

if d.HasChange("upstream_endpoint") {
Expand Down Expand Up @@ -421,22 +485,36 @@ func signalRIsInServerlessMode(features *[]signalr.SignalRFeature) bool {
return false
}

func expandSignalRFeatures(input []interface{}) *[]signalr.SignalRFeature {
func expandSignalRFeatures(featureFlags []interface{}, connectivityLogsEnabled string, messagingLogsEnabled string, serviceMode string) *[]signalr.SignalRFeature {
features := make([]signalr.SignalRFeature, 0)
for _, featureValue := range input {
value := featureValue.(map[string]interface{})

feature := signalr.SignalRFeature{
Flag: signalr.FeatureFlags(value["flag"].(string)),
Value: value["value"].(string),
if len(featureFlags) > 0 {
catriona-m marked this conversation as resolved.
Show resolved Hide resolved
for _, featureValue := range featureFlags {
value := featureValue.(map[string]interface{})
features = append(features, signalRFeature(signalr.FeatureFlags(value["flag"].(string)), value["value"].(string)))
}
} else {
if connectivityLogsEnabled != "" {
features = append(features, signalRFeature(signalr.FeatureFlagsEnableConnectivityLogs, connectivityLogsEnabled))
}
if messagingLogsEnabled != "" {
features = append(features, signalRFeature(signalr.FeatureFlagsEnableMessagingLogs, messagingLogsEnabled))
}
catriona-m marked this conversation as resolved.
Show resolved Hide resolved
if serviceMode != "" {
features = append(features, signalRFeature(signalr.FeatureFlagsServiceMode, serviceMode))
}

features = append(features, feature)
}

return &features
}

func signalRFeature(featureFlag signalr.FeatureFlags, value string) signalr.SignalRFeature {
return signalr.SignalRFeature{
Flag: featureFlag,
Value: value,
}
}

func flattenSignalRFeatures(features *[]signalr.SignalRFeature) []interface{} {
if features == nil {
return []interface{}{}
Expand Down
55 changes: 55 additions & 0 deletions internal/services/signalr/signalr_service_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,32 @@ func TestAccSignalRService_serviceMode(t *testing.T) {
})
}

func TestAccSignalRService_featureFlags(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_signalr_service", "test")
r := SignalRServiceResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.withFeatureFlags(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("hostname").Exists(),
check.That(data.ResourceName).Key("ip_address").Exists(),
check.That(data.ResourceName).Key("public_port").Exists(),
check.That(data.ResourceName).Key("server_port").Exists(),
check.That(data.ResourceName).Key("primary_access_key").Exists(),
check.That(data.ResourceName).Key("primary_connection_string").Exists(),
check.That(data.ResourceName).Key("secondary_access_key").Exists(),
check.That(data.ResourceName).Key("secondary_connection_string").Exists(),
check.That(data.ResourceName).Key("connectivity_logs_enabled").HasValue("True"),
check.That(data.ResourceName).Key("messaging_logs_enabled").HasValue("True"),
check.That(data.ResourceName).Key("service_mode").HasValue("Default"),
),
},
data.ImportStep(),
})
}

func TestAccSignalRService_cors(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_signalr_service", "test")
r := SignalRServiceResource{}
Expand Down Expand Up @@ -565,3 +591,32 @@ resource "azurerm_signalr_service" "test" {
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger)
}

func (r SignalRServiceResource) withFeatureFlags(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}

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

resource "azurerm_signalr_service" "test" {
name = "acctestSignalR-%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name

sku {
name = "Free_F1"
capacity = 1
}

connectivity_logs_enabled = "True"
messaging_logs_enabled = "True"
service_mode = "Default"

}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger)
}
15 changes: 11 additions & 4 deletions website/docs/r/signalr_service.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,9 @@ resource "azurerm_signalr_service" "example" {
allowed_origins = ["http://www.example.com"]
}

features {
flag = "ServiceMode"
value = "Default"
}
connectivity_logs_enabled = "True"
messaging_logs_enabled = "True"
service_mode = "Default"

upstream_endpoint {
category_pattern = ["connections", "messages"]
Expand All @@ -62,6 +61,14 @@ The following arguments are supported:

* `features` - (Optional) A `features` block as documented below.

~> **NOTE:** The `features` block is deprecated, use `connectivity_logs_enabled`, `messaging_logs_enabled` and `service_mode` instead.

* `connectivity_logs_enabled`- (Optional) Specifies if Connectivity Logs are enabled. Possible values are `True` and `False`.

* `messaging_logs_enabled`- (Optional) Specifies if Messaging Logs are enabled. Possible values are `True` and `False`.

* `service_mode`- (Optional) Specifies the service mode. Possible values are `Classic`, `Default` and `Serverless`.

* `upstream_endpoint` - (Optional) An `upstream_endpoint` block as documented below. Using this block requires the SignalR service to be Serverless. When creating multiple blocks they will be processed in the order they are defined in.

* `tags` - (Optional) A mapping of tags to assign to the resource.
Expand Down