@@ -123,12 +123,31 @@ func resourceCloudFunctionsFunction() *schema.Resource {
123
123
124
124
"source_archive_bucket" : {
125
125
Type : schema .TypeString ,
126
- Required : true ,
126
+ Optional : true ,
127
127
},
128
128
129
129
"source_archive_object" : {
130
130
Type : schema .TypeString ,
131
- Required : true ,
131
+ Optional : true ,
132
+ },
133
+
134
+ "source_repository" : {
135
+ Type : schema .TypeList ,
136
+ Optional : true ,
137
+ MaxItems : 1 ,
138
+ ConflictsWith : []string {"source_archive_bucket" , "source_archive_object" },
139
+ Elem : & schema.Resource {
140
+ Schema : map [string ]* schema.Schema {
141
+ "url" : {
142
+ Type : schema .TypeString ,
143
+ Required : true ,
144
+ },
145
+ "deployed_url" : {
146
+ Type : schema .TypeString ,
147
+ Computed : true ,
148
+ },
149
+ },
150
+ },
132
151
},
133
152
134
153
"description" : {
@@ -302,9 +321,17 @@ func resourceCloudFunctionsCreate(d *schema.ResourceData, meta interface{}) erro
302
321
ForceSendFields : []string {},
303
322
}
304
323
305
- sourceArchiveBucket := d .Get ("source_archive_bucket" ).(string )
306
- sourceArchiveObj := d .Get ("source_archive_object" ).(string )
307
- function .SourceArchiveUrl = fmt .Sprintf ("gs://%v/%v" , sourceArchiveBucket , sourceArchiveObj )
324
+ sourceRepos := d .Get ("source_repository" ).([]interface {})
325
+ if len (sourceRepos ) > 0 {
326
+ function .SourceRepository = expandSourceRepository (sourceRepos )
327
+ } else {
328
+ sourceArchiveBucket := d .Get ("source_archive_bucket" ).(string )
329
+ sourceArchiveObj := d .Get ("source_archive_object" ).(string )
330
+ if sourceArchiveBucket == "" || sourceArchiveObj == "" {
331
+ return fmt .Errorf ("either source_repository or both of source_archive_bucket+source_archive_object must be set" )
332
+ }
333
+ function .SourceArchiveUrl = fmt .Sprintf ("gs://%v/%v" , sourceArchiveBucket , sourceArchiveObj )
334
+ }
308
335
309
336
if v , ok := d .GetOk ("available_memory_mb" ); ok {
310
337
availableMemoryMb := v .(int )
@@ -396,6 +423,7 @@ func resourceCloudFunctionsRead(d *schema.ResourceData, meta interface{}) error
396
423
d .Set ("source_archive_bucket" , bucket )
397
424
d .Set ("source_archive_object" , object )
398
425
}
426
+ d .Set ("source_repository" , flattenSourceRepository (function .SourceRepository ))
399
427
400
428
if function .HttpsTrigger != nil {
401
429
d .Set ("trigger_http" , true )
@@ -444,6 +472,11 @@ func resourceCloudFunctionsUpdate(d *schema.ResourceData, meta interface{}) erro
444
472
updateMaskArr = append (updateMaskArr , "sourceArchiveUrl" )
445
473
}
446
474
475
+ if d .HasChange ("source_repository" ) {
476
+ function .SourceRepository = expandSourceRepository (d .Get ("source_repository" ).([]interface {}))
477
+ updateMaskArr = append (updateMaskArr , "sourceRepository" )
478
+ }
479
+
447
480
if d .HasChange ("description" ) {
448
481
function .Description = d .Get ("description" ).(string )
449
482
updateMaskArr = append (updateMaskArr , "description" )
@@ -608,3 +641,28 @@ func flattenFailurePolicy(failurePolicy *cloudfunctions.FailurePolicy) []map[str
608
641
609
642
return result
610
643
}
644
+
645
+ func expandSourceRepository (configured []interface {}) * cloudfunctions.SourceRepository {
646
+ if len (configured ) == 0 || configured [0 ] == nil {
647
+ return & cloudfunctions.SourceRepository {}
648
+ }
649
+
650
+ data := configured [0 ].(map [string ]interface {})
651
+ return & cloudfunctions.SourceRepository {
652
+ Url : data ["url" ].(string ),
653
+ }
654
+ }
655
+
656
+ func flattenSourceRepository (sourceRepo * cloudfunctions.SourceRepository ) []map [string ]interface {} {
657
+ result := make ([]map [string ]interface {}, 0 , 1 )
658
+ if sourceRepo == nil {
659
+ return nil
660
+ }
661
+
662
+ result = append (result , map [string ]interface {}{
663
+ "url" : sourceRepo .Url ,
664
+ "deployed_url" : sourceRepo .DeployedUrl ,
665
+ })
666
+
667
+ return result
668
+ }
0 commit comments