Skip to content

Commit

Permalink
azurerm_signalr_service - fix resource update issue (#21270)
Browse files Browse the repository at this point in the history
* fix resource update issue and change log update logic

* Moving kubernetes fleet manager from containers to container category for consistency (#21309)

* Removing containers to use container for consistency

* Moving from containers to container category for consistency

* update log property update

* fix resource update issue and change log update logic

* update log property update

* regenerate

* sync

---------

Co-authored-by: Will Dewhurst <[email protected]>
  • Loading branch information
xiaxyi and dewhurstwill authored Apr 12, 2023
1 parent 4e065b7 commit 9b7fa06
Showing 1 changed file with 69 additions and 84 deletions.
153 changes: 69 additions & 84 deletions internal/services/signalr/signalr_service_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,122 +341,107 @@ func resourceArmSignalRServiceUpdate(d *pluginsdk.ResourceData, meta interface{}
currentSku = resourceType.Sku.Name
}

if d.HasChanges("cors", "features", "upstream_endpoint", "connectivity_logs_enabled", "messaging_logs_enabled", "http_request_logs_enabled", "service_mode", "live_trace_enabled", "live_trace") {
if d.HasChanges("cors", "upstream_endpoint", "serverless_connection_timeout_in_seconds", "identity",
"public_network_access_enabled", "local_auth_enabled", "aad_auth_enabled", "tls_client_cert_enabled",
"features", "connectivity_logs_enabled", "messaging_logs_enabled", "http_request_logs_enabled", "service_mode", "live_trace_enabled", "live_trace") {
resourceType.Properties = &signalr.SignalRProperties{}

if d.HasChange("cors") {
corsRaw := d.Get("cors").([]interface{})
resourceType.Properties.Cors = expandSignalRCors(corsRaw)
}

if d.HasChange("live_trace") {
resourceType.Properties.LiveTraceConfiguration = expandSignalRLiveTraceConfig(d.Get("live_trace").([]interface{}))
if d.HasChange("upstream_endpoint") {
featuresRaw := d.Get("upstream_endpoint").(*pluginsdk.Set).List()
resourceType.Properties.Upstream = expandUpstreamSettings(featuresRaw)
}

if d.HasChanges("connectivity_logs_enabled", "messaging_logs_enabled", "service_mode", "live_trace_enabled", "http_request_logs_enabled") {
if d.HasChange("public_network_access_enabled") {
publicNetworkAcc := "Enabled"
if !d.Get("public_network_access_enabled").(bool) {
publicNetworkAcc = "Disabled"
}
if currentSku == "Free_F1" && publicNetworkAcc == "Disabled" {
return fmt.Errorf("SKU Free_F1 does not support disabling public network access")
}
resourceType.Properties.PublicNetworkAccess = utils.String(publicNetworkAcc)
if d.HasChange("serverless_connection_timeout_in_seconds") {
resourceType.Properties.Serverless = &signalr.ServerlessSettings{
ConnectionTimeoutInSeconds: utils.Int64(int64(d.Get("serverless_connection_timeout_in_seconds").(int))),
}
}

if d.HasChange("local_auth_enabled") {
resourceType.Properties.DisableLocalAuth = utils.Bool(!d.Get("local_auth_enabled").(bool))
if d.HasChange("identity") {
identity, err := identity.ExpandSystemOrUserAssignedMap(d.Get("identity").([]interface{}))
if err != nil {
return fmt.Errorf("expanding `identity`: %+v", err)
}
resourceType.Identity = identity
}

if d.HasChange("aad_auth_enabled") {
resourceType.Properties.DisableAadAuth = utils.Bool(!d.Get("aad_auth_enabled").(bool))
if d.HasChange("public_network_access_enabled") {
publicNetworkAcc := "Enabled"
if !d.Get("public_network_access_enabled").(bool) {
publicNetworkAcc = "Disabled"
}

if d.HasChange("tls_client_cert_enabled") {
tlsClientCertEnabled := d.Get("tls_client_cert_enabled").(bool)
resourceType.Properties.Tls = &signalr.SignalRTlsSettings{
ClientCertEnabled: utils.Bool(tlsClientCertEnabled),
}
if currentSku == "Free_F1" && tlsClientCertEnabled {
return fmt.Errorf("SKU Free_F1 does not support enabling tls client cert")
}
if currentSku == "Free_F1" && publicNetworkAcc == "Disabled" {
return fmt.Errorf("SKU Free_F1 does not support disabling public network access")
}
resourceType.Properties.PublicNetworkAccess = utils.String(publicNetworkAcc)
}

if d.HasChange("serverless_connection_timeout_in_seconds") {
resourceType.Properties.Serverless = &signalr.ServerlessSettings{
ConnectionTimeoutInSeconds: utils.Int64(int64(d.Get("serverless_connection_timeout_in_seconds").(int))),
}
}
if d.HasChange("local_auth_enabled") {
resourceType.Properties.DisableLocalAuth = utils.Bool(!d.Get("local_auth_enabled").(bool))
}

if d.HasChange("identity") {
identity, err := identity.ExpandSystemOrUserAssignedMap(d.Get("identity").([]interface{}))
if err != nil {
return fmt.Errorf("expanding `identity`: %+v", err)
}
resourceType.Identity = identity
if d.HasChange("aad_auth_enabled") {
resourceType.Properties.DisableAadAuth = utils.Bool(!d.Get("aad_auth_enabled").(bool))
}

if d.HasChange("tls_client_cert_enabled") {
tlsClientCertEnabled := d.Get("tls_client_cert_enabled").(bool)
resourceType.Properties.Tls = &signalr.SignalRTlsSettings{
ClientCertEnabled: utils.Bool(tlsClientCertEnabled),
}
if currentSku == "Free_F1" && tlsClientCertEnabled {
return fmt.Errorf("SKU Free_F1 does not support enabling tls client cert")
}
}

if d.HasChanges("connectivity_logs_enabled", "messaging_logs_enabled", "service_mode", "live_trace_enabled", "http_request_logs_enabled") {
features := make([]signalr.SignalRFeature, 0)
logChanged := false
var connectivityLogsEnabled, messagingLogsEnabled, httpLogsEnabled bool
if d.HasChange("connectivity_logs_enabled") {
if v, ok := d.GetOk("connectivity_logs_enabled"); ok {
connectivityLogsEnabled = v.(bool)
}
features = append(features, signalRFeature(signalr.FeatureFlagsEnableConnectivityLogs, strconv.FormatBool(connectivityLogsEnabled)))
logChanged = true
}
if d.HasChanges("connectivity_logs_enabled", "messaging_logs_enabled", "http_request_logs_enabled", "live_trace_enabled", "service_mode") {
features := make([]signalr.SignalRFeature, 0)
if d.HasChange("connectivity_logs_enabled") || d.HasChange("messaging_logs_enabled") || d.HasChange("http_request_logs_enabled") {
connectivityLogsNew := d.Get("connectivity_logs_enabled")
features = append(features, signalRFeature(signalr.FeatureFlagsEnableConnectivityLogs, strconv.FormatBool(connectivityLogsNew.(bool))))

if d.HasChange("messaging_logs_enabled") {
if v, ok := d.GetOk("messaging_logs_enabled"); ok {
messagingLogsEnabled = v.(bool)
}
features = append(features, signalRFeature(signalr.FeatureFlagsEnableMessagingLogs, strconv.FormatBool(messagingLogsEnabled)))
logChanged = true
}
messagingLogsNew := d.Get("messaging_logs_enabled")
features = append(features, signalRFeature(signalr.FeatureFlagsEnableMessagingLogs, strconv.FormatBool(messagingLogsNew.(bool))))

if d.HasChange("http_request_logs_enabled") {
if v, ok := d.GetOk("http_request_logs_enabled"); ok {
httpLogsEnabled = v.(bool)
}
logChanged = true
}
httpLogsNew := d.Get("http_request_logs_enabled")

if logChanged {
resourceType.Properties.ResourceLogConfiguration = expandSignalRResourceLogConfig(connectivityLogsEnabled, messagingLogsEnabled, httpLogsEnabled)
}
resourceType.Properties.ResourceLogConfiguration = expandSignalRResourceLogConfig(connectivityLogsNew.(bool), messagingLogsNew.(bool), httpLogsNew.(bool))
}

if d.HasChange("live_trace_enabled") {
liveTraceEnabled := false
if v, ok := d.GetOk("live_trace_enabled"); ok {
liveTraceEnabled = v.(bool)
}
features = append(features, signalRFeature("EnableLiveTrace", strconv.FormatBool(liveTraceEnabled)))
if d.HasChange("live_trace_enabled") {
liveTraceEnabled := false
if v, ok := d.GetOk("live_trace_enabled"); ok {
liveTraceEnabled = v.(bool)
}
features = append(features, signalRFeature("EnableLiveTrace", strconv.FormatBool(liveTraceEnabled)))
}

if d.HasChange("service_mode") {
serviceMode := "Default"
if v, ok := d.GetOk("service_mode"); ok {
serviceMode = v.(string)
}
features = append(features, signalRFeature(signalr.FeatureFlagsServiceMode, serviceMode))
if d.HasChange("service_mode") {
serviceMode := "Default"
if v, ok := d.GetOk("service_mode"); ok {
serviceMode = v.(string)
}
resourceType.Properties.Features = &features
features = append(features, signalRFeature(signalr.FeatureFlagsServiceMode, serviceMode))
}

if d.HasChange("upstream_endpoint") {
featuresRaw := d.Get("upstream_endpoint").(*pluginsdk.Set).List()
resourceType.Properties.Upstream = expandUpstreamSettings(featuresRaw)
}
resourceType.Properties.Features = &features
}

if d.HasChange("tags") {
tagsRaw := d.Get("tags").(map[string]interface{})
resourceType.Tags = tags.Expand(tagsRaw)
if d.HasChange("live_trace") {
resourceType.Properties.LiveTraceConfiguration = expandSignalRLiveTraceConfig(d.Get("live_trace").([]interface{}))
}
}

if d.HasChange("tags") {
tagsRaw := d.Get("tags").(map[string]interface{})
resourceType.Tags = tags.Expand(tagsRaw)
}

if err := client.UpdateThenPoll(ctx, *id, resourceType); err != nil {
return fmt.Errorf("updating %s: %+v", *id, err)
}
Expand Down

0 comments on commit 9b7fa06

Please sign in to comment.