Skip to content

Commit

Permalink
azurerm_signalr - Add support for property live_trace_enabled (#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
catriona-m authored Dec 16, 2021
1 parent 2e66617 commit 0e89104
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
30 changes: 26 additions & 4 deletions internal/services/signalr/signalr_service_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ func resourceArmSignalRService() *pluginsdk.Resource {
Type: pluginsdk.TypeSet,
Optional: true,
Computed: true,
Deprecated: "Deprecated in favour of `connectivity_logs_enabled`, `messaging_logs_enabled` and `service_mode`",
Deprecated: "Deprecated in favour of `connectivity_logs_enabled`, `messaging_logs_enabled`, `live_trace_enabled` and `service_mode`",
ConflictsWith: []string{
"connectivity_logs_enabled", "messaging_logs_enabled", "service_mode",
"connectivity_logs_enabled", "messaging_logs_enabled", "live_trace_enabled", "service_mode",
},
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
Expand All @@ -101,6 +101,7 @@ func resourceArmSignalRService() *pluginsdk.Resource {
string(signalr.FeatureFlagsEnableConnectivityLogs),
string(signalr.FeatureFlagsEnableMessagingLogs),
string(signalr.FeatureFlagsServiceMode),
"EnableLiveTrace",
}, false),
},

Expand Down Expand Up @@ -130,6 +131,15 @@ func resourceArmSignalRService() *pluginsdk.Resource {
},
},

"live_trace_enabled": {
Type: pluginsdk.TypeBool,
Optional: true,
Computed: true, // TODO remove in 3.0
ConflictsWith: []string{
"features",
},
},

"service_mode": {
Type: pluginsdk.TypeString,
Optional: true,
Expand Down Expand Up @@ -275,6 +285,7 @@ func resourceArmSignalRServiceCreate(d *pluginsdk.ResourceData, meta interface{}
featureFlags := d.Get("features").(*pluginsdk.Set).List()
connectivityLogsEnabled := d.Get("connectivity_logs_enabled").(bool)
messagingLogsEnabled := d.Get("messaging_logs_enabled").(bool)
liveTraceEnabled := d.Get("live_trace_enabled").(bool)
serviceMode := d.Get("service_mode").(string)

cors := d.Get("cors").([]interface{})
Expand All @@ -286,6 +297,7 @@ func resourceArmSignalRServiceCreate(d *pluginsdk.ResourceData, meta interface{}
} else {
expandedFeatures = append(expandedFeatures, signalRFeature(signalr.FeatureFlagsEnableConnectivityLogs, strconv.FormatBool(connectivityLogsEnabled)))
expandedFeatures = append(expandedFeatures, signalRFeature(signalr.FeatureFlagsEnableMessagingLogs, strconv.FormatBool(messagingLogsEnabled)))
expandedFeatures = append(expandedFeatures, signalRFeature("EnableLiveTrace", strconv.FormatBool(liveTraceEnabled)))

if serviceMode == "" {
serviceMode = "Default"
Expand Down Expand Up @@ -366,6 +378,7 @@ func resourceArmSignalRServiceRead(d *pluginsdk.ResourceData, meta interface{})

connectivityLogsEnabled := false
messagingLogsEnabled := false
liveTraceEnabled := false
serviceMode := "Default"
for _, feature := range *props.Features {
if feature.Flag == signalr.FeatureFlagsEnableConnectivityLogs {
Expand All @@ -374,12 +387,16 @@ func resourceArmSignalRServiceRead(d *pluginsdk.ResourceData, meta interface{})
if feature.Flag == signalr.FeatureFlagsEnableMessagingLogs {
messagingLogsEnabled = strings.EqualFold(feature.Value, "True")
}
if feature.Flag == "EnableLiveTrace" {
liveTraceEnabled = strings.EqualFold(feature.Value, "True")
}
if feature.Flag == signalr.FeatureFlagsServiceMode {
serviceMode = feature.Value
}
}
d.Set("connectivity_logs_enabled", connectivityLogsEnabled)
d.Set("messaging_logs_enabled", messagingLogsEnabled)
d.Set("live_trace_enabled", liveTraceEnabled)
d.Set("service_mode", serviceMode)

if err := d.Set("cors", flattenSignalRCors(props.Cors)); err != nil {
Expand Down Expand Up @@ -418,7 +435,7 @@ func resourceArmSignalRServiceUpdate(d *pluginsdk.ResourceData, meta interface{}

resourceType := signalr.SignalRResource{}

if d.HasChanges("cors", "features", "upstream_endpoint", "connectivity_logs_enabled", "messaging_logs_enabled", "service_mode") {
if d.HasChanges("cors", "features", "upstream_endpoint", "connectivity_logs_enabled", "messaging_logs_enabled", "service_mode", "live_trace_enabled") {
resourceType.Properties = &signalr.SignalRProperties{}

if d.HasChange("cors") {
Expand All @@ -431,7 +448,7 @@ func resourceArmSignalRServiceUpdate(d *pluginsdk.ResourceData, meta interface{}
resourceType.Properties.Features = expandSignalRFeatures(featuresRaw)
}

if d.HasChanges("connectivity_logs_enabled", "messaging_logs_enabled", "service_mode") {
if d.HasChanges("connectivity_logs_enabled", "messaging_logs_enabled", "service_mode", "live_trace_enabled") {
features := make([]signalr.SignalRFeature, 0)
if d.HasChange("connectivity_logs_enabled") {
connectivityLogsEnabled := d.Get("connectivity_logs_enabled").(bool)
Expand All @@ -443,6 +460,11 @@ func resourceArmSignalRServiceUpdate(d *pluginsdk.ResourceData, meta interface{}
features = append(features, signalRFeature(signalr.FeatureFlagsEnableMessagingLogs, strconv.FormatBool(messagingLogsEnabled)))
}

if d.HasChange("live_trace_enabled") {
liveTraceEnabled := d.Get("live_trace_enabled").(bool)
features = append(features, signalRFeature("EnableLiveTrace", strconv.FormatBool(liveTraceEnabled)))
}

if d.HasChange("service_mode") {
serviceMode := d.Get("service_mode").(string)
features = append(features, signalRFeature(signalr.FeatureFlagsServiceMode, serviceMode))
Expand Down
4 changes: 4 additions & 0 deletions internal/services/signalr/signalr_service_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ func TestAccSignalRService_featureFlags(t *testing.T) {
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("live_trace_enabled").HasValue("true"),
check.That(data.ResourceName).Key("service_mode").HasValue("Serverless"),
),
},
Expand All @@ -345,6 +346,7 @@ func TestAccSignalRService_featureFlags(t *testing.T) {
check.That(data.ResourceName).Key("secondary_connection_string").Exists(),
check.That(data.ResourceName).Key("connectivity_logs_enabled").HasValue("false"),
check.That(data.ResourceName).Key("messaging_logs_enabled").HasValue("false"),
check.That(data.ResourceName).Key("live_trace_enabled").HasValue("false"),
check.That(data.ResourceName).Key("service_mode").HasValue("Classic"),
),
},
Expand Down Expand Up @@ -632,6 +634,7 @@ resource "azurerm_signalr_service" "test" {
connectivity_logs_enabled = true
messaging_logs_enabled = true
live_trace_enabled = true
service_mode = "Serverless"
}
Expand Down Expand Up @@ -661,6 +664,7 @@ resource "azurerm_signalr_service" "test" {
connectivity_logs_enabled = false
messaging_logs_enabled = false
live_trace_enabled = false
service_mode = "Classic"
}
Expand Down
6 changes: 4 additions & 2 deletions website/docs/r/signalr_service.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +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.
~> **NOTE:** The `features` block is deprecated, use `connectivity_logs_enabled`, `messaging_logs_enabled`, `live_trace_enabled` and `service_mode` instead.

* `connectivity_logs_enabled`- (Optional) Specifies if Connectivity Logs are enabled or not.

* `messaging_logs_enabled`- (Optional) Specifies if Messaging Logs are enabled or not.

* `live_trace_enabled`- (Optional) Specifies if Live Trace is enabled or not.

* `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.
Expand All @@ -83,7 +85,7 @@ A `cors` block supports the following:

A `features` block supports the following:

* `flag` - (Required) The kind of Feature. Possible values are `EnableConnectivityLogs`, `EnableMessagingLogs`, and `ServiceMode`.
* `flag` - (Required) The kind of Feature. Possible values are `EnableConnectivityLogs`, `EnableMessagingLogs`, `EnableLiveTrace` and `ServiceMode`.

* `value` - (Required) A value of a feature flag. Possible values are `Classic`, `Default` and `Serverless`.

Expand Down

0 comments on commit 0e89104

Please sign in to comment.