From 0619a9a93d36cd56ce6362d9f4e3bad86030ec52 Mon Sep 17 00:00:00 2001 From: ziyeqf <51212351+ziyeqf@users.noreply.github.com> Date: Fri, 20 Sep 2024 07:22:26 +0800 Subject: [PATCH] `azurerm_sentinel_log_analytics_workspace_onboarding` - remove 4.0 feature flag and update documents (#27370) --- ...og_analytics_workspace_onboard_resource.go | 63 +++---------------- ...alytics_workspace_onboard_resource_test.go | 3 +- ...at_intelligence_indicator_resource_test.go | 3 +- ...hreat_intelligence_indicator.html.markdown | 3 +- 4 files changed, 11 insertions(+), 61 deletions(-) diff --git a/internal/services/sentinel/sentinel_log_analytics_workspace_onboard_resource.go b/internal/services/sentinel/sentinel_log_analytics_workspace_onboard_resource.go index a63ef8cbc96c..efd29f652501 100644 --- a/internal/services/sentinel/sentinel_log_analytics_workspace_onboard_resource.go +++ b/internal/services/sentinel/sentinel_log_analytics_workspace_onboard_resource.go @@ -10,19 +10,13 @@ import ( "time" "github.com/hashicorp/go-azure-helpers/lang/response" - "github.com/hashicorp/go-azure-helpers/resourcemanager/resourcegroups" "github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2022-10-01/workspaces" "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-11-01/sentinelonboardingstates" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-provider-azurerm/internal/features" "github.com/hashicorp/terraform-provider-azurerm/internal/sdk" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" - "github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation" ) type SecurityInsightsSentinelOnboardingStateModel struct { - ResourceGroupName string `tfschema:"resource_group_name,removedInNextMajorVersion"` - WorkspaceName string `tfschema:"workspace_name,removedInNextMajorVersion"` CustomerManagedKeyEnabled bool `tfschema:"customer_managed_key_enabled"` WorkspaceId string `tfschema:"workspace_id"` } @@ -44,20 +38,12 @@ func (r LogAnalyticsWorkspaceOnboardResource) IDValidationFunc() pluginsdk.Schem } func (r LogAnalyticsWorkspaceOnboardResource) Arguments() map[string]*pluginsdk.Schema { - out := map[string]*pluginsdk.Schema{ + return map[string]*pluginsdk.Schema{ // lintignore:S013 "workspace_id": { - Type: pluginsdk.TypeString, - Required: features.FourPointOhBeta(), - Optional: !features.FourPointOhBeta(), - Computed: !features.FourPointOhBeta(), - ForceNew: true, - ConflictsWith: func() []string { - if !features.FourPointOhBeta() { - return []string{"resource_group_name", "workspace_name"} - } - return []string{} - }(), + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, ValidateFunc: workspaces.ValidateWorkspaceID, }, @@ -68,29 +54,6 @@ func (r LogAnalyticsWorkspaceOnboardResource) Arguments() map[string]*pluginsdk. ForceNew: true, }, } - - if !features.FourPointOhBeta() { - out["resource_group_name"] = &pluginsdk.Schema{ - Deprecated: "this property has been deprecated in favour of `workspace_id`", - Type: schema.TypeString, - Optional: true, - Computed: true, - ForceNew: true, - ConflictsWith: []string{"workspace_id"}, - ValidateFunc: resourcegroups.ValidateName, - } - out["workspace_name"] = &pluginsdk.Schema{ - Deprecated: "this property will be removed in favour of `workspace_id` in version 4.0 of the AzureRM Provider", - Type: pluginsdk.TypeString, - Optional: true, - Computed: true, - ForceNew: true, - ConflictsWith: []string{"workspace_id"}, - ValidateFunc: validation.StringIsNotEmpty, - } - } - - return out } func (r LogAnalyticsWorkspaceOnboardResource) Attributes() map[string]*pluginsdk.Schema { @@ -109,16 +72,11 @@ func (r LogAnalyticsWorkspaceOnboardResource) Create() sdk.ResourceFunc { client := metadata.Client.Sentinel.OnboardingStatesClient // the service only support `default` state var id sentinelonboardingstates.OnboardingStateId - if model.WorkspaceId != "" { - parsedWorkspaceId, err := workspaces.ParseWorkspaceID(model.WorkspaceId) - if err != nil { - return fmt.Errorf("parsing `log_analytics_workspace_id`: %+v", err) - } - id = sentinelonboardingstates.NewOnboardingStateID(parsedWorkspaceId.SubscriptionId, parsedWorkspaceId.ResourceGroupName, parsedWorkspaceId.WorkspaceName, "default") - } else { // TODO: remove in 4.0 - subscriptionId := metadata.Client.Account.SubscriptionId - id = sentinelonboardingstates.NewOnboardingStateID(subscriptionId, model.ResourceGroupName, model.WorkspaceName, "default") + parsedWorkspaceId, err := workspaces.ParseWorkspaceID(model.WorkspaceId) + if err != nil { + return fmt.Errorf("parsing `log_analytics_workspace_id`: %+v", err) } + id = sentinelonboardingstates.NewOnboardingStateID(parsedWorkspaceId.SubscriptionId, parsedWorkspaceId.ResourceGroupName, parsedWorkspaceId.WorkspaceName, "default") existing, err := client.Get(ctx, id) if err != nil && !response.WasNotFound(existing.HttpResponse) { @@ -208,11 +166,6 @@ func (r LogAnalyticsWorkspaceOnboardResource) Read() sdk.ResourceFunc { WorkspaceId: workspaceId, } - if !features.FourPointOhBeta() { - state.ResourceGroupName = id.ResourceGroupName - state.WorkspaceName = id.WorkspaceName - } - if properties := model.Properties; properties != nil { if properties.CustomerManagedKey != nil { state.CustomerManagedKeyEnabled = *properties.CustomerManagedKey diff --git a/internal/services/sentinel/sentinel_log_analytics_workspace_onboard_resource_test.go b/internal/services/sentinel/sentinel_log_analytics_workspace_onboard_resource_test.go index d824b503e169..71c59125d14a 100644 --- a/internal/services/sentinel/sentinel_log_analytics_workspace_onboard_resource_test.go +++ b/internal/services/sentinel/sentinel_log_analytics_workspace_onboard_resource_test.go @@ -142,8 +142,7 @@ resource "azurerm_resource_group" "test" { } resource "azurerm_sentinel_log_analytics_workspace_onboarding" "test" { - resource_group_name = azurerm_resource_group.test.name - workspace_name = azurerm_log_analytics_workspace.test.name + workspace_id = azurerm_log_analytics_workspace.test.id } `, data.RandomInteger, data.Locations.Primary) } diff --git a/internal/services/sentinel/sentinel_threat_intelligence_indicator_resource_test.go b/internal/services/sentinel/sentinel_threat_intelligence_indicator_resource_test.go index 497b46a84f69..5575fb70b679 100644 --- a/internal/services/sentinel/sentinel_threat_intelligence_indicator_resource_test.go +++ b/internal/services/sentinel/sentinel_threat_intelligence_indicator_resource_test.go @@ -164,8 +164,7 @@ resource "azurerm_log_analytics_workspace" "test" { } resource "azurerm_sentinel_log_analytics_workspace_onboarding" "test" { - resource_group_name = azurerm_resource_group.test.name - workspace_name = azurerm_log_analytics_workspace.test.name + workspace_id = azurerm_log_analytics_workspace.test.id } `, data.RandomInteger, data.Locations.Primary) } diff --git a/website/docs/r/sentinel_threat_intelligence_indicator.html.markdown b/website/docs/r/sentinel_threat_intelligence_indicator.html.markdown index 287468eb5908..f870a6153e29 100644 --- a/website/docs/r/sentinel_threat_intelligence_indicator.html.markdown +++ b/website/docs/r/sentinel_threat_intelligence_indicator.html.markdown @@ -31,8 +31,7 @@ resource "azurerm_log_analytics_workspace" "example" { } resource "azurerm_sentinel_log_analytics_workspace_onboarding" "example" { - resource_group_name = azurerm_resource_group.example.name - workspace_name = azurerm_log_analytics_workspace.example.name + workspace_id = azurerm_log_analytics_workspace.example.id } resource "azurerm_sentinel_threat_intelligence_indicator" "example" {