@@ -21,21 +21,35 @@ import (
21
21
)
22
22
23
23
var (
24
- objectConditionsKeys = []string {
24
+ transferSpecObjectConditionsKeys = []string {
25
25
"transfer_spec.0.object_conditions.0.min_time_elapsed_since_last_modification" ,
26
26
"transfer_spec.0.object_conditions.0.max_time_elapsed_since_last_modification" ,
27
27
"transfer_spec.0.object_conditions.0.include_prefixes" ,
28
28
"transfer_spec.0.object_conditions.0.exclude_prefixes" ,
29
29
"transfer_spec.0.object_conditions.0.last_modified_since" ,
30
30
"transfer_spec.0.object_conditions.0.last_modified_before" ,
31
31
}
32
+ replicationSpecObjectConditionsKeys = []string {
33
+ "replication_spec.0.object_conditions.0.min_time_elapsed_since_last_modification" ,
34
+ "replication_spec.0.object_conditions.0.max_time_elapsed_since_last_modification" ,
35
+ "replication_spec.0.object_conditions.0.include_prefixes" ,
36
+ "replication_spec.0.object_conditions.0.exclude_prefixes" ,
37
+ "replication_spec.0.object_conditions.0.last_modified_since" ,
38
+ "replication_spec.0.object_conditions.0.last_modified_before" ,
39
+ }
32
40
33
- transferOptionsKeys = []string {
41
+ transferSpecTransferOptionsKeys = []string {
34
42
"transfer_spec.0.transfer_options.0.overwrite_objects_already_existing_in_sink" ,
35
43
"transfer_spec.0.transfer_options.0.delete_objects_unique_in_sink" ,
36
44
"transfer_spec.0.transfer_options.0.delete_objects_from_source_after_transfer" ,
37
45
"transfer_spec.0.transfer_options.0.overwrite_when" ,
38
46
}
47
+ replicationSpecTransferOptionsKeys = []string {
48
+ "replication_spec.0.transfer_options.0.overwrite_objects_already_existing_in_sink" ,
49
+ "replication_spec.0.transfer_options.0.delete_objects_unique_in_sink" ,
50
+ "replication_spec.0.transfer_options.0.delete_objects_from_source_after_transfer" ,
51
+ "replication_spec.0.transfer_options.0.overwrite_when" ,
52
+ }
39
53
40
54
transferSpecDataSourceKeys = []string {
41
55
"transfer_spec.0.gcs_data_source" ,
49
63
"transfer_spec.0.gcs_data_sink" ,
50
64
"transfer_spec.0.posix_data_sink" ,
51
65
}
66
+
67
+ replicationSpecDataSourceKeys = []string {
68
+ "replication_spec.0.gcs_data_source" ,
69
+ }
70
+ replicationSpecDataSinkKeys = []string {
71
+ "replication_spec.0.gcs_data_sink" ,
72
+ }
73
+
52
74
awsS3AuthKeys = []string {
53
75
"transfer_spec.0.aws_s3_data_source.0.aws_access_key" ,
54
76
"transfer_spec.0.aws_s3_data_source.0.role_arn" ,
@@ -90,10 +112,11 @@ func ResourceStorageTransferJob() *schema.Resource {
90
112
Description : `The project in which the resource belongs. If it is not provided, the provider project is used.` ,
91
113
},
92
114
"event_stream" : {
93
- Type : schema .TypeList ,
94
- Optional : true ,
95
- MaxItems : 1 ,
96
- ConflictsWith : []string {"schedule" },
115
+ Type : schema .TypeList ,
116
+ Optional : true ,
117
+ MaxItems : 1 ,
118
+ ConflictsWith : []string {"schedule" },
119
+ DiffSuppressFunc : diffSuppressEventStream ,
97
120
Elem : & schema.Resource {
98
121
Schema : map [string ]* schema.Schema {
99
122
"name" : {
@@ -116,14 +139,46 @@ func ResourceStorageTransferJob() *schema.Resource {
116
139
},
117
140
},
118
141
},
142
+ "replication_spec" : {
143
+ Type : schema .TypeList ,
144
+ MaxItems : 1 ,
145
+ Optional : true ,
146
+ ConflictsWith : []string {"transfer_spec" , "schedule" },
147
+ ExactlyOneOf : []string {"transfer_spec" , "replication_spec" },
148
+ Elem : & schema.Resource {
149
+ Schema : map [string ]* schema.Schema {
150
+ "object_conditions" : objectConditionsSchema (replicationSpecObjectConditionsKeys ),
151
+ "transfer_options" : transferOptionsSchema (replicationSpecTransferOptionsKeys ),
152
+ "gcs_data_sink" : {
153
+ Type : schema .TypeList ,
154
+ Optional : true ,
155
+ MaxItems : 1 ,
156
+ Elem : gcsDataSchema (),
157
+ ExactlyOneOf : replicationSpecDataSinkKeys ,
158
+ Description : `A Google Cloud Storage data sink.` ,
159
+ },
160
+ "gcs_data_source" : {
161
+ Type : schema .TypeList ,
162
+ Optional : true ,
163
+ MaxItems : 1 ,
164
+ Elem : gcsDataSchema (),
165
+ ExactlyOneOf : replicationSpecDataSourceKeys ,
166
+ Description : `A Google Cloud Storage data source.` ,
167
+ },
168
+ },
169
+ },
170
+ Description : `Replication specification.` ,
171
+ },
119
172
"transfer_spec" : {
120
- Type : schema .TypeList ,
121
- Required : true ,
122
- MaxItems : 1 ,
173
+ Type : schema .TypeList ,
174
+ Optional : true ,
175
+ MaxItems : 1 ,
176
+ ConflictsWith : []string {"replication_spec" },
177
+ ExactlyOneOf : []string {"transfer_spec" , "replication_spec" },
123
178
Elem : & schema.Resource {
124
179
Schema : map [string ]* schema.Schema {
125
- "object_conditions" : objectConditionsSchema (),
126
- "transfer_options" : transferOptionsSchema (),
180
+ "object_conditions" : objectConditionsSchema (transferSpecObjectConditionsKeys ),
181
+ "transfer_options" : transferOptionsSchema (transferSpecTransferOptionsKeys ),
127
182
"source_agent_pool_name" : {
128
183
Type : schema .TypeString ,
129
184
Optional : true ,
@@ -303,7 +358,7 @@ func ResourceStorageTransferJob() *schema.Resource {
303
358
}
304
359
}
305
360
306
- func objectConditionsSchema () * schema.Schema {
361
+ func objectConditionsSchema (objectConditionsKeys [] string ) * schema.Schema {
307
362
return & schema.Schema {
308
363
Type : schema .TypeList ,
309
364
Optional : true ,
@@ -364,7 +419,7 @@ func objectConditionsSchema() *schema.Schema {
364
419
}
365
420
}
366
421
367
- func transferOptionsSchema () * schema.Schema {
422
+ func transferOptionsSchema (transferOptionsKeys [] string ) * schema.Schema {
368
423
return & schema.Schema {
369
424
Type : schema .TypeList ,
370
425
Optional : true ,
@@ -625,6 +680,7 @@ func resourceStorageTransferJobCreate(d *schema.ResourceData, meta interface{})
625
680
Schedule : expandTransferSchedules (d .Get ("schedule" ).([]interface {})),
626
681
EventStream : expandEventStream (d .Get ("event_stream" ).([]interface {})),
627
682
TransferSpec : expandTransferSpecs (d .Get ("transfer_spec" ).([]interface {})),
683
+ ReplicationSpec : expandReplicationSpecs (d .Get ("replication_spec" ).([]interface {})),
628
684
NotificationConfig : expandTransferJobNotificationConfig (d .Get ("notification_config" ).([]interface {})),
629
685
}
630
686
@@ -709,6 +765,11 @@ func resourceStorageTransferJobRead(d *schema.ResourceData, meta interface{}) er
709
765
return err
710
766
}
711
767
768
+ err = d .Set ("replication_spec" , flattenReplicationSpec (res .ReplicationSpec ))
769
+ if err != nil {
770
+ return err
771
+ }
772
+
712
773
err = d .Set ("notification_config" , flattenTransferJobNotificationConfig (res .NotificationConfig ))
713
774
if err != nil {
714
775
return err
@@ -767,6 +828,13 @@ func resourceStorageTransferJobUpdate(d *schema.ResourceData, meta interface{})
767
828
}
768
829
}
769
830
831
+ if d .HasChange ("replication_spec" ) {
832
+ fieldMask = append (fieldMask , "replication_spec" )
833
+ if v , ok := d .GetOk ("replication_spec" ); ok {
834
+ transferJob .ReplicationSpec = expandReplicationSpecs (v .([]interface {}))
835
+ }
836
+ }
837
+
770
838
if d .HasChange ("notification_config" ) {
771
839
fieldMask = append (fieldMask , "notification_config" )
772
840
if v , ok := d .GetOk ("notification_config" ); ok {
@@ -1249,6 +1317,9 @@ func expandTransferSpecs(transferSpecs []interface{}) *storagetransfer.TransferS
1249
1317
}
1250
1318
1251
1319
func flattenTransferSpec (transferSpec * storagetransfer.TransferSpec , d * schema.ResourceData ) []map [string ]interface {} {
1320
+ if transferSpec == nil || reflect .DeepEqual (transferSpec , & storagetransfer.TransferSpec {}) {
1321
+ return nil
1322
+ }
1252
1323
1253
1324
data := map [string ]interface {}{}
1254
1325
@@ -1326,3 +1397,44 @@ func flattenTransferJobNotificationConfig(notificationConfig *storagetransfer.No
1326
1397
1327
1398
return []map [string ]interface {}{data }
1328
1399
}
1400
+
1401
+ func diffSuppressEventStream (k , old , new string , d * schema.ResourceData ) bool {
1402
+ // Check if it's a replication job.
1403
+ _ , is_replication := d .GetOk ("replication_spec" )
1404
+ return is_replication
1405
+ }
1406
+
1407
+ func expandReplicationSpecs (replicationSpecs []interface {}) * storagetransfer.ReplicationSpec {
1408
+ if len (replicationSpecs ) == 0 || replicationSpecs [0 ] == nil {
1409
+ return nil
1410
+ }
1411
+
1412
+ replicationSpec := replicationSpecs [0 ].(map [string ]interface {})
1413
+ return & storagetransfer.ReplicationSpec {
1414
+ GcsDataSink : expandGcsData (replicationSpec ["gcs_data_sink" ].([]interface {})),
1415
+ ObjectConditions : expandObjectConditions (replicationSpec ["object_conditions" ].([]interface {})),
1416
+ TransferOptions : expandTransferOptions (replicationSpec ["transfer_options" ].([]interface {})),
1417
+ GcsDataSource : expandGcsData (replicationSpec ["gcs_data_source" ].([]interface {})),
1418
+ }
1419
+ }
1420
+
1421
+ func flattenReplicationSpec (replicationSpec * storagetransfer.ReplicationSpec ) []map [string ]interface {} {
1422
+ if replicationSpec == nil || reflect .DeepEqual (replicationSpec , & storagetransfer.ReplicationSpec {}) {
1423
+ return nil
1424
+ }
1425
+
1426
+ data := map [string ]interface {}{}
1427
+ if replicationSpec .GcsDataSink != nil {
1428
+ data ["gcs_data_sink" ] = flattenGcsData (replicationSpec .GcsDataSink )
1429
+ }
1430
+ if replicationSpec .GcsDataSource != nil {
1431
+ data ["gcs_data_source" ] = flattenGcsData (replicationSpec .GcsDataSource )
1432
+ }
1433
+ if replicationSpec .ObjectConditions != nil {
1434
+ data ["object_conditions" ] = flattenObjectCondition (replicationSpec .ObjectConditions )
1435
+ }
1436
+ if replicationSpec .TransferOptions != nil {
1437
+ data ["transfer_options" ] = flattenTransferOption (replicationSpec .TransferOptions )
1438
+ }
1439
+ return []map [string ]interface {}{data }
1440
+ }
0 commit comments