From 7724c2f38abe60c18c370fb2cf85f4ba040cfd43 Mon Sep 17 00:00:00 2001 From: neil-yechenwei Date: Thu, 1 Sep 2022 10:25:18 +0800 Subject: [PATCH 1/8] TestCase: Fix TC for Log Analytics --- .../log_analytics_datasource_windows_event_resource.go | 2 +- .../log_analytics_linked_storage_account_resource.go | 8 +++++--- .../portal/portal_tenant_configuration_resource.go | 5 +++++ 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/internal/services/loganalytics/log_analytics_datasource_windows_event_resource.go b/internal/services/loganalytics/log_analytics_datasource_windows_event_resource.go index 611591e7dc42..753e76ea2113 100644 --- a/internal/services/loganalytics/log_analytics_datasource_windows_event_resource.go +++ b/internal/services/loganalytics/log_analytics_datasource_windows_event_resource.go @@ -77,7 +77,7 @@ func resourceLogAnalyticsDataSourceWindowsEvent() *pluginsdk.Resource { Elem: &pluginsdk.Schema{ Type: pluginsdk.TypeString, // API backend accepts event_types case-insensitively - ValidateFunc: validation.StringInSlice([]string{"Error", "Warning", "Information"}, false), + ValidateFunc: validation.StringInSlice([]string{"Error", "Warning", "Information"}, true), }, }, }, diff --git a/internal/services/loganalytics/log_analytics_linked_storage_account_resource.go b/internal/services/loganalytics/log_analytics_linked_storage_account_resource.go index d3e2ba109ebd..6006be00083b 100644 --- a/internal/services/loganalytics/log_analytics_linked_storage_account_resource.go +++ b/internal/services/loganalytics/log_analytics_linked_storage_account_resource.go @@ -12,6 +12,7 @@ import ( "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" + "github.com/hashicorp/terraform-provider-azurerm/internal/tf/suppress" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation" "github.com/hashicorp/terraform-provider-azurerm/internal/timeouts" "github.com/hashicorp/terraform-provider-azurerm/utils" @@ -38,9 +39,10 @@ func resourceLogAnalyticsLinkedStorageAccount() *pluginsdk.Resource { Schema: map[string]*pluginsdk.Schema{ "data_source_type": { - Type: pluginsdk.TypeString, - Required: true, - ForceNew: true, + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + DiffSuppressFunc: suppress.CaseDifference, ValidateFunc: validation.StringInSlice([]string{ strings.ToLower(string(linkedstorageaccounts.DataSourceTypeCustomLogs)), strings.ToLower(string(linkedstorageaccounts.DataSourceTypeAzureWatson)), diff --git a/internal/services/portal/portal_tenant_configuration_resource.go b/internal/services/portal/portal_tenant_configuration_resource.go index 1281fa1e6cd0..1eb815213a1f 100644 --- a/internal/services/portal/portal_tenant_configuration_resource.go +++ b/internal/services/portal/portal_tenant_configuration_resource.go @@ -52,6 +52,11 @@ func resourcePortalTenantConfigurationCreateUpdate(d *pluginsdk.ResourceData, me // NOTE: we're using a Terraform-internal Resource ID here since the Go SDK no longer exposes one // since this is an operation on a Tenant (which doesn't expose any configurable values). id := parse.NewPortalTenantConfigurationID("default") + + if _, err := client.TenantConfigurationsDelete(ctx); err != nil { + return fmt.Errorf("deleting %s: %+v", id, err) + } + if d.IsNewResource() { existing, err := client.TenantConfigurationsGet(ctx) if err != nil { From 0d81c6512b661b4e1708b58a7847fca1426dba6a Mon Sep 17 00:00:00 2001 From: neil-yechenwei Date: Thu, 1 Sep 2022 10:35:14 +0800 Subject: [PATCH 2/8] update code --- .../services/portal/portal_tenant_configuration_resource.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/internal/services/portal/portal_tenant_configuration_resource.go b/internal/services/portal/portal_tenant_configuration_resource.go index 1eb815213a1f..1281fa1e6cd0 100644 --- a/internal/services/portal/portal_tenant_configuration_resource.go +++ b/internal/services/portal/portal_tenant_configuration_resource.go @@ -52,11 +52,6 @@ func resourcePortalTenantConfigurationCreateUpdate(d *pluginsdk.ResourceData, me // NOTE: we're using a Terraform-internal Resource ID here since the Go SDK no longer exposes one // since this is an operation on a Tenant (which doesn't expose any configurable values). id := parse.NewPortalTenantConfigurationID("default") - - if _, err := client.TenantConfigurationsDelete(ctx); err != nil { - return fmt.Errorf("deleting %s: %+v", id, err) - } - if d.IsNewResource() { existing, err := client.TenantConfigurationsGet(ctx) if err != nil { From e6a89aaa76d837d4da5ae12b044c56894d1ce0f6 Mon Sep 17 00:00:00 2001 From: neil-yechenwei Date: Thu, 1 Sep 2022 11:21:20 +0800 Subject: [PATCH 3/8] update code --- .../log_analytics_linked_storage_account_resource.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/services/loganalytics/log_analytics_linked_storage_account_resource.go b/internal/services/loganalytics/log_analytics_linked_storage_account_resource.go index 6006be00083b..50a699fac24a 100644 --- a/internal/services/loganalytics/log_analytics_linked_storage_account_resource.go +++ b/internal/services/loganalytics/log_analytics_linked_storage_account_resource.go @@ -50,7 +50,7 @@ func resourceLogAnalyticsLinkedStorageAccount() *pluginsdk.Resource { strings.ToLower(string(linkedstorageaccounts.DataSourceTypeAlerts)), // Value removed from enum in 2020-08-01, but effectively still works "ingestion", - }, false), + }, true), }, "resource_group_name": azure.SchemaResourceGroupName(), From 9817c4c79d08348accff5cccf9d45e0a554494bd Mon Sep 17 00:00:00 2001 From: neil-yechenwei Date: Fri, 2 Sep 2022 17:20:09 +0800 Subject: [PATCH 4/8] update code --- .../log_analytics_linked_storage_account_resource.go | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/internal/services/loganalytics/log_analytics_linked_storage_account_resource.go b/internal/services/loganalytics/log_analytics_linked_storage_account_resource.go index 50a699fac24a..c66fa6bd448d 100644 --- a/internal/services/loganalytics/log_analytics_linked_storage_account_resource.go +++ b/internal/services/loganalytics/log_analytics_linked_storage_account_resource.go @@ -12,7 +12,6 @@ import ( "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" - "github.com/hashicorp/terraform-provider-azurerm/internal/tf/suppress" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation" "github.com/hashicorp/terraform-provider-azurerm/internal/timeouts" "github.com/hashicorp/terraform-provider-azurerm/utils" @@ -39,10 +38,9 @@ func resourceLogAnalyticsLinkedStorageAccount() *pluginsdk.Resource { Schema: map[string]*pluginsdk.Schema{ "data_source_type": { - Type: pluginsdk.TypeString, - Required: true, - ForceNew: true, - DiffSuppressFunc: suppress.CaseDifference, + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, ValidateFunc: validation.StringInSlice([]string{ strings.ToLower(string(linkedstorageaccounts.DataSourceTypeCustomLogs)), strings.ToLower(string(linkedstorageaccounts.DataSourceTypeAzureWatson)), @@ -50,7 +48,7 @@ func resourceLogAnalyticsLinkedStorageAccount() *pluginsdk.Resource { strings.ToLower(string(linkedstorageaccounts.DataSourceTypeAlerts)), // Value removed from enum in 2020-08-01, but effectively still works "ingestion", - }, true), + }, false), }, "resource_group_name": azure.SchemaResourceGroupName(), @@ -144,7 +142,7 @@ func resourceLogAnalyticsLinkedStorageAccountRead(d *pluginsdk.ResourceData, met dataSourceType := "" if props.DataSourceType != nil { - dataSourceType = string(*props.DataSourceType) + dataSourceType = strings.ToLower(string(*props.DataSourceType)) } d.Set("data_source_type", dataSourceType) From b1c70fbc8033c55724eca0adb7949f6cec9fc42a Mon Sep 17 00:00:00 2001 From: neil-yechenwei Date: Mon, 5 Sep 2022 14:53:12 +0800 Subject: [PATCH 5/8] update code --- .../log_analytics_datasource_windows_event_resource.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/internal/services/loganalytics/log_analytics_datasource_windows_event_resource.go b/internal/services/loganalytics/log_analytics_datasource_windows_event_resource.go index 753e76ea2113..755d9bedda96 100644 --- a/internal/services/loganalytics/log_analytics_datasource_windows_event_resource.go +++ b/internal/services/loganalytics/log_analytics_datasource_windows_event_resource.go @@ -4,7 +4,6 @@ import ( "encoding/json" "fmt" "log" - "strings" "time" "github.com/hashicorp/go-azure-helpers/lang/response" @@ -75,9 +74,8 @@ func resourceLogAnalyticsDataSourceWindowsEvent() *pluginsdk.Resource { MinItems: 1, Set: set.HashStringIgnoreCase, Elem: &pluginsdk.Schema{ - Type: pluginsdk.TypeString, - // API backend accepts event_types case-insensitively - ValidateFunc: validation.StringInSlice([]string{"Error", "Warning", "Information"}, true), + Type: pluginsdk.TypeString, + ValidateFunc: validation.StringInSlice([]string{"Error", "Warning", "Information"}, false), }, }, }, @@ -199,7 +197,7 @@ func flattenLogAnalyticsDataSourceWindowsEventEventType(eventTypes []dataSourceW for _, e := range eventTypes { // The casing isn't preserved by the API for event types, so we need to normalise it here until // https://github.com/Azure/azure-rest-api-specs/issues/18163 is fixed - output = append(output, strings.ToLower(e.EventType)) + output = append(output, e.EventType) } return output } From 3f6284c2132d1e58917bf2571b781952c7406834 Mon Sep 17 00:00:00 2001 From: neil-yechenwei Date: Mon, 5 Sep 2022 14:54:30 +0800 Subject: [PATCH 6/8] update code --- .../log_analytics_datasource_windows_event_resource.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/internal/services/loganalytics/log_analytics_datasource_windows_event_resource.go b/internal/services/loganalytics/log_analytics_datasource_windows_event_resource.go index 755d9bedda96..b7f0cdc00795 100644 --- a/internal/services/loganalytics/log_analytics_datasource_windows_event_resource.go +++ b/internal/services/loganalytics/log_analytics_datasource_windows_event_resource.go @@ -74,7 +74,8 @@ func resourceLogAnalyticsDataSourceWindowsEvent() *pluginsdk.Resource { MinItems: 1, Set: set.HashStringIgnoreCase, Elem: &pluginsdk.Schema{ - Type: pluginsdk.TypeString, + Type: pluginsdk.TypeString, + // API backend accepts event_types case-insensitively ValidateFunc: validation.StringInSlice([]string{"Error", "Warning", "Information"}, false), }, }, From 07e36be233c559e934aec7709e1edcba2b8e1d6f Mon Sep 17 00:00:00 2001 From: neil-yechenwei Date: Wed, 7 Sep 2022 11:21:04 +0800 Subject: [PATCH 7/8] update code --- ...alytics_linked_storage_account_resource.go | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/internal/services/loganalytics/log_analytics_linked_storage_account_resource.go b/internal/services/loganalytics/log_analytics_linked_storage_account_resource.go index c66fa6bd448d..e614e9974a01 100644 --- a/internal/services/loganalytics/log_analytics_linked_storage_account_resource.go +++ b/internal/services/loganalytics/log_analytics_linked_storage_account_resource.go @@ -3,7 +3,6 @@ package loganalytics import ( "fmt" "log" - "strings" "time" "github.com/hashicorp/go-azure-helpers/lang/response" @@ -12,6 +11,7 @@ import ( "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" + "github.com/hashicorp/terraform-provider-azurerm/internal/tf/suppress" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation" "github.com/hashicorp/terraform-provider-azurerm/internal/timeouts" "github.com/hashicorp/terraform-provider-azurerm/utils" @@ -41,14 +41,15 @@ func resourceLogAnalyticsLinkedStorageAccount() *pluginsdk.Resource { Type: pluginsdk.TypeString, Required: true, ForceNew: true, + // TODO 4.0: change ignoreCase from true to false and remove diff suppress to respect correct casing ValidateFunc: validation.StringInSlice([]string{ - strings.ToLower(string(linkedstorageaccounts.DataSourceTypeCustomLogs)), - strings.ToLower(string(linkedstorageaccounts.DataSourceTypeAzureWatson)), - strings.ToLower(string(linkedstorageaccounts.DataSourceTypeQuery)), - strings.ToLower(string(linkedstorageaccounts.DataSourceTypeAlerts)), - // Value removed from enum in 2020-08-01, but effectively still works - "ingestion", - }, false), + string(linkedstorageaccounts.DataSourceTypeAlerts), + string(linkedstorageaccounts.DataSourceTypeAzureWatson), + string(linkedstorageaccounts.DataSourceTypeCustomLogs), + string(linkedstorageaccounts.DataSourceTypeIngestion), + string(linkedstorageaccounts.DataSourceTypeQuery), + }, true), + DiffSuppressFunc: suppress.CaseDifference, }, "resource_group_name": azure.SchemaResourceGroupName(), @@ -142,7 +143,7 @@ func resourceLogAnalyticsLinkedStorageAccountRead(d *pluginsdk.ResourceData, met dataSourceType := "" if props.DataSourceType != nil { - dataSourceType = strings.ToLower(string(*props.DataSourceType)) + dataSourceType = string(*props.DataSourceType) } d.Set("data_source_type", dataSourceType) From c682e65aa58cd1fd53bbacdd60e2f9709ed133cc Mon Sep 17 00:00:00 2001 From: neil-yechenwei Date: Fri, 9 Sep 2022 12:10:35 +0800 Subject: [PATCH 8/8] update code --- ...alytics_linked_storage_account_resource.go | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/internal/services/loganalytics/log_analytics_linked_storage_account_resource.go b/internal/services/loganalytics/log_analytics_linked_storage_account_resource.go index e614e9974a01..a15045574197 100644 --- a/internal/services/loganalytics/log_analytics_linked_storage_account_resource.go +++ b/internal/services/loganalytics/log_analytics_linked_storage_account_resource.go @@ -10,6 +10,7 @@ import ( "github.com/hashicorp/terraform-provider-azurerm/helpers/azure" "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" + "github.com/hashicorp/terraform-provider-azurerm/internal/features" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/suppress" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation" @@ -18,7 +19,7 @@ import ( ) func resourceLogAnalyticsLinkedStorageAccount() *pluginsdk.Resource { - return &pluginsdk.Resource{ + resource := &pluginsdk.Resource{ Create: resourceLogAnalyticsLinkedStorageAccountCreateUpdate, Read: resourceLogAnalyticsLinkedStorageAccountRead, Update: resourceLogAnalyticsLinkedStorageAccountCreateUpdate, @@ -41,15 +42,13 @@ func resourceLogAnalyticsLinkedStorageAccount() *pluginsdk.Resource { Type: pluginsdk.TypeString, Required: true, ForceNew: true, - // TODO 4.0: change ignoreCase from true to false and remove diff suppress to respect correct casing ValidateFunc: validation.StringInSlice([]string{ string(linkedstorageaccounts.DataSourceTypeAlerts), string(linkedstorageaccounts.DataSourceTypeAzureWatson), string(linkedstorageaccounts.DataSourceTypeCustomLogs), string(linkedstorageaccounts.DataSourceTypeIngestion), string(linkedstorageaccounts.DataSourceTypeQuery), - }, true), - DiffSuppressFunc: suppress.CaseDifference, + }, false), }, "resource_group_name": azure.SchemaResourceGroupName(), @@ -72,6 +71,25 @@ func resourceLogAnalyticsLinkedStorageAccount() *pluginsdk.Resource { }, }, } + + // TODO 4.0: remove this block to respect correct casing + if !features.FourPointOhBeta() { + resource.Schema["data_source_type"] = &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validation.StringInSlice([]string{ + string(linkedstorageaccounts.DataSourceTypeAlerts), + string(linkedstorageaccounts.DataSourceTypeAzureWatson), + string(linkedstorageaccounts.DataSourceTypeCustomLogs), + string(linkedstorageaccounts.DataSourceTypeIngestion), + string(linkedstorageaccounts.DataSourceTypeQuery), + }, true), + DiffSuppressFunc: suppress.CaseDifference, + } + } + + return resource } func resourceLogAnalyticsLinkedStorageAccountCreateUpdate(d *pluginsdk.ResourceData, meta interface{}) error {