@@ -61,6 +61,36 @@ func ResourceFirebaseHostingVersion() *schema.Resource {
61
61
MaxItems : 1 ,
62
62
Elem : & schema.Resource {
63
63
Schema : map [string ]* schema.Schema {
64
+ "headers" : {
65
+ Type : schema .TypeList ,
66
+ Optional : true ,
67
+ ForceNew : true ,
68
+ Description : `An array of objects, where each object specifies a URL pattern that, if matched to the request URL path,
69
+ triggers Hosting to apply the specified custom response headers.` ,
70
+ Elem : & schema.Resource {
71
+ Schema : map [string ]* schema.Schema {
72
+ "headers" : {
73
+ Type : schema .TypeMap ,
74
+ Required : true ,
75
+ ForceNew : true ,
76
+ Description : `The additional headers to add to the response. Example: { "name": "wrench", "mass": "1.3kg", "count": "3" }.` ,
77
+ Elem : & schema.Schema {Type : schema .TypeString },
78
+ },
79
+ "glob" : {
80
+ Type : schema .TypeString ,
81
+ Optional : true ,
82
+ ForceNew : true ,
83
+ Description : `The user-supplied glob to match against the request URL path.` ,
84
+ },
85
+ "regex" : {
86
+ Type : schema .TypeString ,
87
+ Optional : true ,
88
+ ForceNew : true ,
89
+ Description : `The user-supplied RE2 regular expression to match against the request URL path.` ,
90
+ },
91
+ },
92
+ },
93
+ },
64
94
"redirects" : {
65
95
Type : schema .TypeList ,
66
96
Optional : true ,
@@ -92,18 +122,16 @@ redirects {
92
122
Description : `The status HTTP code to return in the response. It must be a valid 3xx status code.` ,
93
123
},
94
124
"glob" : {
95
- Type : schema .TypeString ,
96
- Optional : true ,
97
- ForceNew : true ,
98
- Description : `The user-supplied glob to match against the request URL path.` ,
99
- ExactlyOneOf : []string {},
125
+ Type : schema .TypeString ,
126
+ Optional : true ,
127
+ ForceNew : true ,
128
+ Description : `The user-supplied glob to match against the request URL path.` ,
100
129
},
101
130
"regex" : {
102
- Type : schema .TypeString ,
103
- Optional : true ,
104
- ForceNew : true ,
105
- Description : `The user-supplied RE2 regular expression to match against the request URL path.` ,
106
- ExactlyOneOf : []string {},
131
+ Type : schema .TypeString ,
132
+ Optional : true ,
133
+ ForceNew : true ,
134
+ Description : `The user-supplied RE2 regular expression to match against the request URL path.` ,
107
135
},
108
136
},
109
137
},
@@ -117,32 +145,28 @@ request URL path, triggers Hosting to respond as if the service were given the s
117
145
Elem : & schema.Resource {
118
146
Schema : map [string ]* schema.Schema {
119
147
"function" : {
120
- Type : schema .TypeString ,
121
- Optional : true ,
122
- ForceNew : true ,
123
- Description : `The function to proxy requests to. Must match the exported function name exactly.` ,
124
- ExactlyOneOf : []string {},
148
+ Type : schema .TypeString ,
149
+ Optional : true ,
150
+ ForceNew : true ,
151
+ Description : `The function to proxy requests to. Must match the exported function name exactly.` ,
125
152
},
126
153
"glob" : {
127
- Type : schema .TypeString ,
128
- Optional : true ,
129
- ForceNew : true ,
130
- Description : `The user-supplied glob to match against the request URL path.` ,
131
- ExactlyOneOf : []string {},
154
+ Type : schema .TypeString ,
155
+ Optional : true ,
156
+ ForceNew : true ,
157
+ Description : `The user-supplied glob to match against the request URL path.` ,
132
158
},
133
159
"path" : {
134
- Type : schema .TypeString ,
135
- Optional : true ,
136
- ForceNew : true ,
137
- Description : `The URL path to rewrite the request to.` ,
138
- ExactlyOneOf : []string {},
160
+ Type : schema .TypeString ,
161
+ Optional : true ,
162
+ ForceNew : true ,
163
+ Description : `The URL path to rewrite the request to.` ,
139
164
},
140
165
"regex" : {
141
- Type : schema .TypeString ,
142
- Optional : true ,
143
- ForceNew : true ,
144
- Description : `The user-supplied RE2 regular expression to match against the request URL path.` ,
145
- ExactlyOneOf : []string {},
166
+ Type : schema .TypeString ,
167
+ Optional : true ,
168
+ ForceNew : true ,
169
+ Description : `The user-supplied RE2 regular expression to match against the request URL path.` ,
146
170
},
147
171
"run" : {
148
172
Type : schema .TypeList ,
@@ -166,7 +190,6 @@ request URL path, triggers Hosting to respond as if the service were given the s
166
190
},
167
191
},
168
192
},
169
- ExactlyOneOf : []string {},
170
193
},
171
194
},
172
195
},
@@ -387,6 +410,8 @@ func flattenFirebaseHostingVersionConfig(v interface{}, d *schema.ResourceData,
387
410
flattenFirebaseHostingVersionConfigRewrites (original ["rewrites" ], d , config )
388
411
transformed ["redirects" ] =
389
412
flattenFirebaseHostingVersionConfigRedirects (original ["redirects" ], d , config )
413
+ transformed ["headers" ] =
414
+ flattenFirebaseHostingVersionConfigHeaders (original ["headers" ], d , config )
390
415
return []interface {}{transformed }
391
416
}
392
417
func flattenFirebaseHostingVersionConfigRewrites (v interface {}, d * schema.ResourceData , config * transport_tpg.Config ) interface {} {
@@ -500,6 +525,38 @@ func flattenFirebaseHostingVersionConfigRedirectsLocation(v interface{}, d *sche
500
525
return v
501
526
}
502
527
528
+ func flattenFirebaseHostingVersionConfigHeaders (v interface {}, d * schema.ResourceData , config * transport_tpg.Config ) interface {} {
529
+ if v == nil {
530
+ return v
531
+ }
532
+ l := v .([]interface {})
533
+ transformed := make ([]interface {}, 0 , len (l ))
534
+ for _ , raw := range l {
535
+ original := raw .(map [string ]interface {})
536
+ if len (original ) < 1 {
537
+ // Do not include empty json objects coming back from the api
538
+ continue
539
+ }
540
+ transformed = append (transformed , map [string ]interface {}{
541
+ "glob" : flattenFirebaseHostingVersionConfigHeadersGlob (original ["glob" ], d , config ),
542
+ "regex" : flattenFirebaseHostingVersionConfigHeadersRegex (original ["regex" ], d , config ),
543
+ "headers" : flattenFirebaseHostingVersionConfigHeadersHeaders (original ["headers" ], d , config ),
544
+ })
545
+ }
546
+ return transformed
547
+ }
548
+ func flattenFirebaseHostingVersionConfigHeadersGlob (v interface {}, d * schema.ResourceData , config * transport_tpg.Config ) interface {} {
549
+ return v
550
+ }
551
+
552
+ func flattenFirebaseHostingVersionConfigHeadersRegex (v interface {}, d * schema.ResourceData , config * transport_tpg.Config ) interface {} {
553
+ return v
554
+ }
555
+
556
+ func flattenFirebaseHostingVersionConfigHeadersHeaders (v interface {}, d * schema.ResourceData , config * transport_tpg.Config ) interface {} {
557
+ return v
558
+ }
559
+
503
560
func expandFirebaseHostingVersionConfig (v interface {}, d tpgresource.TerraformResourceData , config * transport_tpg.Config ) (interface {}, error ) {
504
561
l := v .([]interface {})
505
562
if len (l ) == 0 || l [0 ] == nil {
@@ -523,6 +580,13 @@ func expandFirebaseHostingVersionConfig(v interface{}, d tpgresource.TerraformRe
523
580
transformed ["redirects" ] = transformedRedirects
524
581
}
525
582
583
+ transformedHeaders , err := expandFirebaseHostingVersionConfigHeaders (original ["headers" ], d , config )
584
+ if err != nil {
585
+ return nil , err
586
+ } else if val := reflect .ValueOf (transformedHeaders ); val .IsValid () && ! tpgresource .IsEmptyValue (val ) {
587
+ transformed ["headers" ] = transformedHeaders
588
+ }
589
+
526
590
return transformed , nil
527
591
}
528
592
@@ -685,6 +749,61 @@ func expandFirebaseHostingVersionConfigRedirectsLocation(v interface{}, d tpgres
685
749
return v , nil
686
750
}
687
751
752
+ func expandFirebaseHostingVersionConfigHeaders (v interface {}, d tpgresource.TerraformResourceData , config * transport_tpg.Config ) (interface {}, error ) {
753
+ l := v .([]interface {})
754
+ req := make ([]interface {}, 0 , len (l ))
755
+ for _ , raw := range l {
756
+ if raw == nil {
757
+ continue
758
+ }
759
+ original := raw .(map [string ]interface {})
760
+ transformed := make (map [string ]interface {})
761
+
762
+ transformedGlob , err := expandFirebaseHostingVersionConfigHeadersGlob (original ["glob" ], d , config )
763
+ if err != nil {
764
+ return nil , err
765
+ } else if val := reflect .ValueOf (transformedGlob ); val .IsValid () && ! tpgresource .IsEmptyValue (val ) {
766
+ transformed ["glob" ] = transformedGlob
767
+ }
768
+
769
+ transformedRegex , err := expandFirebaseHostingVersionConfigHeadersRegex (original ["regex" ], d , config )
770
+ if err != nil {
771
+ return nil , err
772
+ } else if val := reflect .ValueOf (transformedRegex ); val .IsValid () && ! tpgresource .IsEmptyValue (val ) {
773
+ transformed ["regex" ] = transformedRegex
774
+ }
775
+
776
+ transformedHeaders , err := expandFirebaseHostingVersionConfigHeadersHeaders (original ["headers" ], d , config )
777
+ if err != nil {
778
+ return nil , err
779
+ } else if val := reflect .ValueOf (transformedHeaders ); val .IsValid () && ! tpgresource .IsEmptyValue (val ) {
780
+ transformed ["headers" ] = transformedHeaders
781
+ }
782
+
783
+ req = append (req , transformed )
784
+ }
785
+ return req , nil
786
+ }
787
+
788
+ func expandFirebaseHostingVersionConfigHeadersGlob (v interface {}, d tpgresource.TerraformResourceData , config * transport_tpg.Config ) (interface {}, error ) {
789
+ return v , nil
790
+ }
791
+
792
+ func expandFirebaseHostingVersionConfigHeadersRegex (v interface {}, d tpgresource.TerraformResourceData , config * transport_tpg.Config ) (interface {}, error ) {
793
+ return v , nil
794
+ }
795
+
796
+ func expandFirebaseHostingVersionConfigHeadersHeaders (v interface {}, d tpgresource.TerraformResourceData , config * transport_tpg.Config ) (map [string ]string , error ) {
797
+ if v == nil {
798
+ return map [string ]string {}, nil
799
+ }
800
+ m := make (map [string ]string )
801
+ for k , val := range v .(map [string ]interface {}) {
802
+ m [k ] = val .(string )
803
+ }
804
+ return m , nil
805
+ }
806
+
688
807
func resourceFirebaseHostingVersionDecoder (d * schema.ResourceData , meta interface {}, res map [string ]interface {}) (map [string ]interface {}, error ) {
689
808
if err := d .Set ("version_id" , tpgresource .GetResourceNameFromSelfLink (res ["name" ].(string ))); err != nil {
690
809
return nil , err
0 commit comments