Skip to content

Commit becda7c

Browse files
fix: (storagetransfer) added logging_config for storage transfer job (#13081) (#9378)
[upstream:31e852f30a175bc5d5ab570b23345e18021745ca] Signed-off-by: Modular Magician <[email protected]>
1 parent 824dac2 commit becda7c

File tree

4 files changed

+402
-0
lines changed

4 files changed

+402
-0
lines changed

Diff for: .changelog/13081.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
storagetransfer: added `logging_config` field to `google_storage_transfer_job` resource
3+
```

Diff for: google-beta/services/storagetransfer/resource_storage_transfer_job.go

+80
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,42 @@ func ResourceStorageTransferJob() *schema.Resource {
295295
},
296296
Description: `Notification configuration.`,
297297
},
298+
"logging_config": {
299+
Type: schema.TypeList,
300+
Optional: true,
301+
MaxItems: 1,
302+
Elem: &schema.Resource{
303+
Schema: map[string]*schema.Schema{
304+
"log_actions": {
305+
Type: schema.TypeList,
306+
Optional: true,
307+
AtLeastOneOf: []string{"logging_config.0.enable_on_prem_gcs_transfer_logs", "logging_config.0.log_actions", "logging_config.0.log_action_states"},
308+
Elem: &schema.Schema{
309+
Type: schema.TypeString,
310+
ValidateFunc: validation.StringInSlice([]string{"FIND", "DELETE", "COPY"}, false),
311+
},
312+
Description: `Specifies the actions to be logged. Not supported for transfers with PosifxFilesystem data sources; use enable_on_prem_gcs_transfer_logs instead.`,
313+
},
314+
"log_action_states": {
315+
Type: schema.TypeList,
316+
Optional: true,
317+
AtLeastOneOf: []string{"logging_config.0.enable_on_prem_gcs_transfer_logs", "logging_config.0.log_actions", "logging_config.0.log_action_states"},
318+
Elem: &schema.Schema{
319+
Type: schema.TypeString,
320+
ValidateFunc: validation.StringInSlice([]string{"SUCCEEDED", "FAILED"}, false),
321+
},
322+
Description: `States in which logActions are logged. Not supported for transfers with PosifxFilesystem data sources; use enable_on_prem_gcs_transfer_logs instead.`,
323+
},
324+
"enable_on_prem_gcs_transfer_logs": {
325+
Type: schema.TypeBool,
326+
Optional: true,
327+
AtLeastOneOf: []string{"logging_config.0.enable_on_prem_gcs_transfer_logs", "logging_config.0.log_actions", "logging_config.0.log_action_states"},
328+
Description: `For transfers with a PosixFilesystem source, this option enables the Cloud Storage transfer logs for this transfer.`,
329+
},
330+
},
331+
},
332+
Description: `Logging configuration.`,
333+
},
298334
"schedule": {
299335
Type: schema.TypeList,
300336
Optional: true,
@@ -692,6 +728,7 @@ func resourceStorageTransferJobCreate(d *schema.ResourceData, meta interface{})
692728
EventStream: expandEventStream(d.Get("event_stream").([]interface{})),
693729
TransferSpec: expandTransferSpecs(d.Get("transfer_spec").([]interface{})),
694730
ReplicationSpec: expandReplicationSpecs(d.Get("replication_spec").([]interface{})),
731+
LoggingConfig: expandTransferJobLoggingConfig(d.Get("logging_config").([]interface{})),
695732
NotificationConfig: expandTransferJobNotificationConfig(d.Get("notification_config").([]interface{})),
696733
}
697734

@@ -786,6 +823,11 @@ func resourceStorageTransferJobRead(d *schema.ResourceData, meta interface{}) er
786823
return err
787824
}
788825

826+
err = d.Set("logging_config", flattenTransferJobLoggingConfig(res.LoggingConfig))
827+
if err != nil {
828+
return err
829+
}
830+
789831
return nil
790832
}
791833

@@ -855,6 +897,15 @@ func resourceStorageTransferJobUpdate(d *schema.ResourceData, meta interface{})
855897
}
856898
}
857899

900+
if d.HasChange("logging_config") {
901+
fieldMask = append(fieldMask, "logging_config")
902+
if v, ok := d.GetOk("logging_config"); ok {
903+
transferJob.LoggingConfig = expandTransferJobLoggingConfig(v.([]interface{}))
904+
} else {
905+
transferJob.LoggingConfig = nil
906+
}
907+
}
908+
858909
if len(fieldMask) == 0 {
859910
return nil
860911
}
@@ -1454,3 +1505,32 @@ func flattenReplicationSpec(replicationSpec *storagetransfer.ReplicationSpec) []
14541505
}
14551506
return []map[string]interface{}{data}
14561507
}
1508+
1509+
func expandTransferJobLoggingConfig(loggingConfigs []interface{}) *storagetransfer.LoggingConfig {
1510+
if len(loggingConfigs) == 0 || loggingConfigs[0] == nil {
1511+
return nil
1512+
}
1513+
1514+
loggingConfig := loggingConfigs[0].(map[string]interface{})
1515+
var apiData = &storagetransfer.LoggingConfig{
1516+
LogActions: tpgresource.ConvertStringArr(loggingConfig["log_actions"].([]interface{})),
1517+
LogActionStates: tpgresource.ConvertStringArr(loggingConfig["log_action_states"].([]interface{})),
1518+
EnableOnpremGcsTransferLogs: loggingConfig["enable_on_prem_gcs_transfer_logs"].(bool),
1519+
}
1520+
1521+
return apiData
1522+
}
1523+
1524+
func flattenTransferJobLoggingConfig(loggingConfig *storagetransfer.LoggingConfig) []map[string]interface{} {
1525+
if loggingConfig == nil {
1526+
return nil
1527+
}
1528+
1529+
data := map[string]interface{}{
1530+
"log_actions": loggingConfig.LogActions,
1531+
"log_action_states": loggingConfig.LogActionStates,
1532+
"enable_on_prem_gcs_transfer_logs": loggingConfig.EnableOnpremGcsTransferLogs,
1533+
}
1534+
1535+
return []map[string]interface{}{data}
1536+
}

0 commit comments

Comments
 (0)