Skip to content

Commit

Permalink
azurerm_sentinel_data_connector_threat_intelligence - support `look…
Browse files Browse the repository at this point in the history
…back_date` (#20390)

fix #19795
  • Loading branch information
ziyeqf committed Feb 10, 2023
1 parent 7761ae8 commit ddd6a9e
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 7 deletions.
105 changes: 104 additions & 1 deletion internal/services/sentinel/azuresdkhacks/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func unmarshalBasicDataConnector(body []byte) (securityinsight.BasicDataConnecto
err := json.Unmarshal(body, &odc)
return odc, err
case string(securityinsight.KindBasicDataConnectorKindThreatIntelligence):
var tdc securityinsight.TIDataConnector
var tdc TIDataConnector
err := json.Unmarshal(body, &tdc)
return tdc, err
case string(securityinsight.KindBasicDataConnectorKindThreatIntelligenceTaxii):
Expand Down Expand Up @@ -312,6 +312,109 @@ func (ttdc *TiTaxiiDataConnector) UnmarshalJSON(body []byte) error {
return nil
}

var _ securityinsight.BasicDataConnector = TIDataConnector{}

type TIDataConnector struct {
*TIDataConnectorProperties `json:"properties,omitempty"`
Kind securityinsight.KindBasicDataConnector `json:"kind,omitempty"`
Etag *string `json:"etag,omitempty"`
ID *string `json:"id,omitempty"`
Name *string `json:"name,omitempty"`
Type *string `json:"type,omitempty"`
SystemData *securityinsight.SystemData `json:"systemData,omitempty"`
}

func (TIDataConnector) AsAADDataConnector() (*securityinsight.AADDataConnector, bool) {
return nil, false
}

func (TIDataConnector) AsMSTIDataConnector() (*securityinsight.MSTIDataConnector, bool) {
return nil, false
}

func (TIDataConnector) AsMTPDataConnector() (*securityinsight.MTPDataConnector, bool) {
return nil, false
}

func (TIDataConnector) AsAATPDataConnector() (*securityinsight.AATPDataConnector, bool) {
return nil, false
}

func (TIDataConnector) AsASCDataConnector() (*securityinsight.ASCDataConnector, bool) {
return nil, false
}

func (TIDataConnector) AsAwsCloudTrailDataConnector() (*securityinsight.AwsCloudTrailDataConnector, bool) {
return nil, false
}

func (TIDataConnector) AsAwsS3DataConnector() (*securityinsight.AwsS3DataConnector, bool) {
return nil, false
}

func (TIDataConnector) AsMCASDataConnector() (*securityinsight.MCASDataConnector, bool) {
return nil, false
}

func (TIDataConnector) AsDynamics365DataConnector() (*securityinsight.Dynamics365DataConnector, bool) {
return nil, false
}

func (TIDataConnector) AsOfficeATPDataConnector() (*securityinsight.OfficeATPDataConnector, bool) {
return nil, false
}

func (TIDataConnector) AsOffice365ProjectDataConnector() (*securityinsight.Office365ProjectDataConnector, bool) {
return nil, false
}

func (TIDataConnector) AsOfficePowerBIDataConnector() (*securityinsight.OfficePowerBIDataConnector, bool) {
return nil, false
}

func (TIDataConnector) AsOfficeIRMDataConnector() (*securityinsight.OfficeIRMDataConnector, bool) {
return nil, false
}

func (TIDataConnector) AsMDATPDataConnector() (*securityinsight.MDATPDataConnector, bool) {
return nil, false
}

func (TIDataConnector) AsOfficeDataConnector() (*securityinsight.OfficeDataConnector, bool) {
return nil, false
}

func (TIDataConnector) AsTIDataConnector() (*securityinsight.TIDataConnector, bool) {
// This method is not used at all, only for implementing the interface.
return nil, false
}

func (TIDataConnector) AsTiTaxiiDataConnector() (*securityinsight.TiTaxiiDataConnector, bool) {
return nil, false
}

func (TIDataConnector) AsIoTDataConnector() (*securityinsight.IoTDataConnector, bool) {
return nil, false
}

func (TIDataConnector) AsCodelessUIDataConnector() (*securityinsight.CodelessUIDataConnector, bool) {
return nil, false
}

func (TIDataConnector) AsCodelessAPIPollingDataConnector() (*securityinsight.CodelessAPIPollingDataConnector, bool) {
return nil, false
}

func (TIDataConnector) AsDataConnector() (*securityinsight.DataConnector, bool) {
return nil, false
}

type TIDataConnectorProperties struct {
TipLookbackPeriod *Time `json:"tipLookbackPeriod,omitempty"`
DataTypes *securityinsight.TIDataConnectorDataTypes `json:"dataTypes,omitempty"`
TenantID *string `json:"tenantId,omitempty"`
}

type PollingFrequency string

func (freq *PollingFrequency) UnmarshalJSON(body []byte) error {
Expand Down
2 changes: 2 additions & 0 deletions internal/services/sentinel/sentinel_data_connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ func assertDataConnectorKind(dc securityinsight.BasicDataConnector, expectKind s
kind = securityinsight.DataConnectorKindAmazonWebServicesS3
case azuresdkhacks.TiTaxiiDataConnector:
kind = securityinsight.DataConnectorKindThreatIntelligenceTaxii
case azuresdkhacks.TIDataConnector:
kind = securityinsight.DataConnectorKindThreatIntelligence
}
if expectKind != kind {
return fmt.Errorf("Sentinel Data Connector has mismatched kind, expected: %q, got %q", expectKind, kind)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2020-08-01/workspaces"
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/sentinel/azuresdkhacks"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/sentinel/parse"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation"
Expand Down Expand Up @@ -55,12 +56,21 @@ func resourceSentinelDataConnectorThreatIntelligence() *pluginsdk.Resource {
ForceNew: true,
ValidateFunc: validation.IsUUID,
},

"lookback_date": {
Type: pluginsdk.TypeString,
Optional: true,
ForceNew: true,
Default: "1970-01-01T00:00:00Z",
ValidateFunc: validation.IsRFC3339Time,
},
},
}
}

func resourceSentinelDataConnectorThreatIntelligenceCreateUpdate(d *pluginsdk.ResourceData, meta interface{}) error {
client := meta.(*clients.Client).Sentinel.DataConnectorsClient
client := azuresdkhacks.DataConnectorsClient{BaseClient: meta.(*clients.Client).Sentinel.DataConnectorsClient.BaseClient}

ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d)
defer cancel()

Expand Down Expand Up @@ -89,10 +99,15 @@ func resourceSentinelDataConnectorThreatIntelligenceCreateUpdate(d *pluginsdk.Re
tenantId = meta.(*clients.Client).Account.TenantId
}

param := securityinsight.TIDataConnector{
lookbackDate, _ := time.Parse(time.RFC3339, d.Get("lookback_date").(string))

param := azuresdkhacks.TIDataConnector{
Name: &name,
TIDataConnectorProperties: &securityinsight.TIDataConnectorProperties{
TIDataConnectorProperties: &azuresdkhacks.TIDataConnectorProperties{
TenantID: &tenantId,
TipLookbackPeriod: &azuresdkhacks.Time{
Time: lookbackDate,
},
DataTypes: &securityinsight.TIDataConnectorDataTypes{
Indicators: &securityinsight.TIDataConnectorDataTypesIndicators{
State: securityinsight.DataTypeStateEnabled,
Expand All @@ -112,7 +127,7 @@ func resourceSentinelDataConnectorThreatIntelligenceCreateUpdate(d *pluginsdk.Re
}

func resourceSentinelDataConnectorThreatIntelligenceRead(d *pluginsdk.ResourceData, meta interface{}) error {
client := meta.(*clients.Client).Sentinel.DataConnectorsClient
client := azuresdkhacks.DataConnectorsClient{BaseClient: meta.(*clients.Client).Sentinel.DataConnectorsClient.BaseClient}
ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d)
defer cancel()

Expand All @@ -133,14 +148,15 @@ func resourceSentinelDataConnectorThreatIntelligenceRead(d *pluginsdk.ResourceDa
return fmt.Errorf("retrieving %s: %+v", id, err)
}

dc, ok := resp.Value.(securityinsight.TIDataConnector)
dc, ok := resp.Value.(azuresdkhacks.TIDataConnector)
if !ok {
return fmt.Errorf("%s was not a Threat Intelligence Data Connector", id)
}

d.Set("name", id.Name)
d.Set("log_analytics_workspace_id", workspaceId.ID())
d.Set("tenant_id", dc.TenantID)
d.Set("lookback_date", dc.TipLookbackPeriod.Format(time.RFC3339))

return nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance"
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/sentinel/azuresdkhacks"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/sentinel/parse"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/utils"
Expand Down Expand Up @@ -61,7 +62,7 @@ func TestAccAzureRMSentinelDataConnectorThreatIntelligence_requiresImport(t *tes
}

func (r SentinelDataConnectorThreatIntelligenceResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) {
client := clients.Sentinel.DataConnectorsClient
client := azuresdkhacks.DataConnectorsClient{BaseClient: clients.Sentinel.DataConnectorsClient.BaseClient}

id, err := parse.DataConnectorID(state.ID)
if err != nil {
Expand Down Expand Up @@ -103,6 +104,7 @@ resource "azurerm_sentinel_data_connector_threat_intelligence" "test" {
log_analytics_workspace_id = azurerm_log_analytics_workspace.test.id
tenant_id = data.azurerm_client_config.test.tenant_id
depends_on = [azurerm_log_analytics_solution.test]
lookback_date = "1990-01-01T00:00:00Z"
}
`, template, data.RandomInteger)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ The following arguments are supported:

* `name` - (Required) The name which should be used for this Threat Intelligence Data Connector. Changing this forces a new Threat Intelligence Data Connector to be created.

* `lookback_date` - (Optional) The lookback date for the this Threat Intelligence Data Connector in RFC3339. Defaults to `1970-01-01T00:00:00Z`.

---

* `tenant_id` - (Optional) The ID of the tenant that this Threat Intelligence Data Connector connects to. Changing this forces a new Threat Intelligence Data Connector to be created.
Expand Down

0 comments on commit ddd6a9e

Please sign in to comment.