Skip to content

Commit

Permalink
azurerm_sentinel_log_analytics_workspace_onboarding - remove 4.0 fe…
Browse files Browse the repository at this point in the history
…ature flag and update documents (#27370)
  • Loading branch information
ziyeqf authored Sep 19, 2024
1 parent 66658af commit 0619a9a
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
Expand All @@ -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,
},

Expand All @@ -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 {
Expand All @@ -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) {
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down

0 comments on commit 0619a9a

Please sign in to comment.