Skip to content

Commit 7bed792

Browse files
gurusai-voletiDawid212
authored andcommitted
fix: (storagetransfer) added logging_config for storage transfer job (GoogleCloudPlatform#13081)
1 parent d4b4794 commit 7bed792

File tree

3 files changed

+399
-0
lines changed

3 files changed

+399
-0
lines changed

mmv1/third_party/terraform/services/storagetransfer/resource_storage_transfer_job.go.tmpl

+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,
@@ -698,6 +734,7 @@ func resourceStorageTransferJobCreate(d *schema.ResourceData, meta interface{})
698734
EventStream: expandEventStream(d.Get("event_stream").([]interface{})),
699735
TransferSpec: expandTransferSpecs(d.Get("transfer_spec").([]interface{})),
700736
ReplicationSpec: expandReplicationSpecs(d.Get("replication_spec").([]interface{})),
737+
LoggingConfig: expandTransferJobLoggingConfig(d.Get("logging_config").([]interface{})),
701738
NotificationConfig: expandTransferJobNotificationConfig(d.Get("notification_config").([]interface{})),
702739
}
703740

@@ -792,6 +829,11 @@ func resourceStorageTransferJobRead(d *schema.ResourceData, meta interface{}) er
792829
return err
793830
}
794831

832+
err = d.Set("logging_config", flattenTransferJobLoggingConfig(res.LoggingConfig))
833+
if err != nil {
834+
return err
835+
}
836+
795837
return nil
796838
}
797839

@@ -861,6 +903,15 @@ func resourceStorageTransferJobUpdate(d *schema.ResourceData, meta interface{})
861903
}
862904
}
863905

906+
if d.HasChange("logging_config") {
907+
fieldMask = append(fieldMask, "logging_config")
908+
if v, ok := d.GetOk("logging_config"); ok {
909+
transferJob.LoggingConfig = expandTransferJobLoggingConfig(v.([]interface{}))
910+
} else {
911+
transferJob.LoggingConfig = nil
912+
}
913+
}
914+
864915
if len(fieldMask) == 0 {
865916
return nil
866917
}
@@ -1466,3 +1517,32 @@ func flattenReplicationSpec(replicationSpec *storagetransfer.ReplicationSpec) []
14661517
}
14671518
return []map[string]interface{}{data}
14681519
}
1520+
1521+
func expandTransferJobLoggingConfig(loggingConfigs []interface{}) *storagetransfer.LoggingConfig {
1522+
if len(loggingConfigs) == 0 || loggingConfigs[0] == nil {
1523+
return nil
1524+
}
1525+
1526+
loggingConfig := loggingConfigs[0].(map[string]interface{})
1527+
var apiData = &storagetransfer.LoggingConfig{
1528+
LogActions: tpgresource.ConvertStringArr(loggingConfig["log_actions"].([]interface{})),
1529+
LogActionStates: tpgresource.ConvertStringArr(loggingConfig["log_action_states"].([]interface{})),
1530+
EnableOnpremGcsTransferLogs: loggingConfig["enable_on_prem_gcs_transfer_logs"].(bool),
1531+
}
1532+
1533+
return apiData
1534+
}
1535+
1536+
func flattenTransferJobLoggingConfig(loggingConfig *storagetransfer.LoggingConfig) []map[string]interface{} {
1537+
if loggingConfig == nil {
1538+
return nil
1539+
}
1540+
1541+
data := map[string]interface{}{
1542+
"log_actions": loggingConfig.LogActions,
1543+
"log_action_states": loggingConfig.LogActionStates,
1544+
"enable_on_prem_gcs_transfer_logs": loggingConfig.EnableOnpremGcsTransferLogs,
1545+
}
1546+
1547+
return []map[string]interface{}{data}
1548+
}

0 commit comments

Comments
 (0)