Skip to content

fix: (storagetransfer) added logging_config for storage transfer job #9378

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/13081.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
storagetransfer: added `logging_config` field to `google_storage_transfer_job` resource
```
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,42 @@ func ResourceStorageTransferJob() *schema.Resource {
},
Description: `Notification configuration.`,
},
"logging_config": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"log_actions": {
Type: schema.TypeList,
Optional: true,
AtLeastOneOf: []string{"logging_config.0.enable_on_prem_gcs_transfer_logs", "logging_config.0.log_actions", "logging_config.0.log_action_states"},
Elem: &schema.Schema{
Type: schema.TypeString,
ValidateFunc: validation.StringInSlice([]string{"FIND", "DELETE", "COPY"}, false),
},
Description: `Specifies the actions to be logged. Not supported for transfers with PosifxFilesystem data sources; use enable_on_prem_gcs_transfer_logs instead.`,
},
"log_action_states": {
Type: schema.TypeList,
Optional: true,
AtLeastOneOf: []string{"logging_config.0.enable_on_prem_gcs_transfer_logs", "logging_config.0.log_actions", "logging_config.0.log_action_states"},
Elem: &schema.Schema{
Type: schema.TypeString,
ValidateFunc: validation.StringInSlice([]string{"SUCCEEDED", "FAILED"}, false),
},
Description: `States in which logActions are logged. Not supported for transfers with PosifxFilesystem data sources; use enable_on_prem_gcs_transfer_logs instead.`,
},
"enable_on_prem_gcs_transfer_logs": {
Type: schema.TypeBool,
Optional: true,
AtLeastOneOf: []string{"logging_config.0.enable_on_prem_gcs_transfer_logs", "logging_config.0.log_actions", "logging_config.0.log_action_states"},
Description: `For transfers with a PosixFilesystem source, this option enables the Cloud Storage transfer logs for this transfer.`,
},
},
},
Description: `Logging configuration.`,
},
"schedule": {
Type: schema.TypeList,
Optional: true,
Expand Down Expand Up @@ -692,6 +728,7 @@ func resourceStorageTransferJobCreate(d *schema.ResourceData, meta interface{})
EventStream: expandEventStream(d.Get("event_stream").([]interface{})),
TransferSpec: expandTransferSpecs(d.Get("transfer_spec").([]interface{})),
ReplicationSpec: expandReplicationSpecs(d.Get("replication_spec").([]interface{})),
LoggingConfig: expandTransferJobLoggingConfig(d.Get("logging_config").([]interface{})),
NotificationConfig: expandTransferJobNotificationConfig(d.Get("notification_config").([]interface{})),
}

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

err = d.Set("logging_config", flattenTransferJobLoggingConfig(res.LoggingConfig))
if err != nil {
return err
}

return nil
}

Expand Down Expand Up @@ -855,6 +897,15 @@ func resourceStorageTransferJobUpdate(d *schema.ResourceData, meta interface{})
}
}

if d.HasChange("logging_config") {
fieldMask = append(fieldMask, "logging_config")
if v, ok := d.GetOk("logging_config"); ok {
transferJob.LoggingConfig = expandTransferJobLoggingConfig(v.([]interface{}))
} else {
transferJob.LoggingConfig = nil
}
}

if len(fieldMask) == 0 {
return nil
}
Expand Down Expand Up @@ -1454,3 +1505,32 @@ func flattenReplicationSpec(replicationSpec *storagetransfer.ReplicationSpec) []
}
return []map[string]interface{}{data}
}

func expandTransferJobLoggingConfig(loggingConfigs []interface{}) *storagetransfer.LoggingConfig {
if len(loggingConfigs) == 0 || loggingConfigs[0] == nil {
return nil
}

loggingConfig := loggingConfigs[0].(map[string]interface{})
var apiData = &storagetransfer.LoggingConfig{
LogActions: tpgresource.ConvertStringArr(loggingConfig["log_actions"].([]interface{})),
LogActionStates: tpgresource.ConvertStringArr(loggingConfig["log_action_states"].([]interface{})),
EnableOnpremGcsTransferLogs: loggingConfig["enable_on_prem_gcs_transfer_logs"].(bool),
}

return apiData
}

func flattenTransferJobLoggingConfig(loggingConfig *storagetransfer.LoggingConfig) []map[string]interface{} {
if loggingConfig == nil {
return nil
}

data := map[string]interface{}{
"log_actions": loggingConfig.LogActions,
"log_action_states": loggingConfig.LogActionStates,
"enable_on_prem_gcs_transfer_logs": loggingConfig.EnableOnpremGcsTransferLogs,
}

return []map[string]interface{}{data}
}
Loading