forked from hashicorp/terraform-provider-azurerm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sentinel_data_connector.go
59 lines (53 loc) · 2.39 KB
/
sentinel_data_connector.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package sentinel
import (
"context"
"fmt"
"github.com/Azure/azure-sdk-for-go/services/preview/securityinsight/mgmt/2019-01-01-preview/securityinsight"
"github.com/kevinklinger/terraform-provider-azurerm/v2/internal/clients"
"github.com/kevinklinger/terraform-provider-azurerm/v2/internal/services/sentinel/parse"
"github.com/kevinklinger/terraform-provider-azurerm/v2/internal/tf/pluginsdk"
)
func importSentinelDataConnector(expectKind securityinsight.DataConnectorKind) pluginsdk.ImporterFunc {
return func(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) (data []*pluginsdk.ResourceData, err error) {
id, err := parse.DataConnectorID(d.Id())
if err != nil {
return nil, err
}
client := meta.(*clients.Client).Sentinel.DataConnectorsClient
resp, err := client.Get(ctx, id.ResourceGroup, OperationalInsightsResourceProvider, id.WorkspaceName, id.Name)
if err != nil {
return nil, fmt.Errorf("retrieving Sentinel Alert Rule %q: %+v", id, err)
}
if err := assertDataConnectorKind(resp.Value, expectKind); err != nil {
return nil, err
}
return []*pluginsdk.ResourceData{d}, nil
}
}
func assertDataConnectorKind(dc securityinsight.BasicDataConnector, expectKind securityinsight.DataConnectorKind) error {
var kind securityinsight.DataConnectorKind
switch dc.(type) {
case securityinsight.AADDataConnector:
kind = securityinsight.DataConnectorKindAzureActiveDirectory
case securityinsight.AATPDataConnector:
kind = securityinsight.DataConnectorKindAzureAdvancedThreatProtection
case securityinsight.ASCDataConnector:
kind = securityinsight.DataConnectorKindAzureSecurityCenter
case securityinsight.MCASDataConnector:
kind = securityinsight.DataConnectorKindMicrosoftCloudAppSecurity
case securityinsight.TIDataConnector:
kind = securityinsight.DataConnectorKindThreatIntelligence
case securityinsight.OfficeDataConnector:
kind = securityinsight.DataConnectorKindOffice365
case securityinsight.OfficeATPDataConnector:
kind = securityinsight.DataConnectorKindOfficeATP
case securityinsight.AwsCloudTrailDataConnector:
kind = securityinsight.DataConnectorKindAmazonWebServicesCloudTrail
case securityinsight.MDATPDataConnector:
kind = securityinsight.DataConnectorKindMicrosoftDefenderAdvancedThreatProtection
}
if expectKind != kind {
return fmt.Errorf("Sentinel Data Connector has mismatched kind, expected: %q, got %q", expectKind, kind)
}
return nil
}