@@ -110,6 +110,49 @@ Hostname and Ports - ("abc.com" and "22"), ("abc.com" and "22,33") etc`,
110
110
Description : `Optional. An arbitrary user-provided name for the Application resource.
111
111
Cannot exceed 64 characters.` ,
112
112
},
113
+ "upstreams" : {
114
+ Type : schema .TypeList ,
115
+ Optional : true ,
116
+ Description : `Optional. List of which upstream resource(s) to forward traffic to.` ,
117
+ Elem : & schema.Resource {
118
+ Schema : map [string ]* schema.Schema {
119
+ "egress_policy" : {
120
+ Type : schema .TypeList ,
121
+ Optional : true ,
122
+ Description : `Optional. Routing policy information.` ,
123
+ MaxItems : 1 ,
124
+ Elem : & schema.Resource {
125
+ Schema : map [string ]* schema.Schema {
126
+ "regions" : {
127
+ Type : schema .TypeList ,
128
+ Required : true ,
129
+ Description : `Required. List of regions where the application sends traffic to.` ,
130
+ Elem : & schema.Schema {
131
+ Type : schema .TypeString ,
132
+ },
133
+ },
134
+ },
135
+ },
136
+ },
137
+ "network" : {
138
+ Type : schema .TypeList ,
139
+ Optional : true ,
140
+ Description : `Network to forward traffic to.` ,
141
+ MaxItems : 1 ,
142
+ Elem : & schema.Resource {
143
+ Schema : map [string ]* schema.Schema {
144
+ "name" : {
145
+ Type : schema .TypeString ,
146
+ Required : true ,
147
+ Description : `Required. Network name is of the format:
148
+ 'projects/{project}/global/networks/{network}'` ,
149
+ },
150
+ },
151
+ },
152
+ },
153
+ },
154
+ },
155
+ },
113
156
"create_time" : {
114
157
Type : schema .TypeString ,
115
158
Computed : true ,
@@ -156,6 +199,12 @@ func resourceBeyondcorpApplicationCreate(d *schema.ResourceData, meta interface{
156
199
} else if v , ok := d .GetOkExists ("endpoint_matchers" ); ! tpgresource .IsEmptyValue (reflect .ValueOf (endpointMatchersProp )) && (ok || ! reflect .DeepEqual (v , endpointMatchersProp )) {
157
200
obj ["endpointMatchers" ] = endpointMatchersProp
158
201
}
202
+ upstreamsProp , err := expandBeyondcorpApplicationUpstreams (d .Get ("upstreams" ), d , config )
203
+ if err != nil {
204
+ return err
205
+ } else if v , ok := d .GetOkExists ("upstreams" ); ! tpgresource .IsEmptyValue (reflect .ValueOf (upstreamsProp )) && (ok || ! reflect .DeepEqual (v , upstreamsProp )) {
206
+ obj ["upstreams" ] = upstreamsProp
207
+ }
159
208
160
209
url , err := tpgresource .ReplaceVars (d , config , "{{BeyondcorpBasePath}}projects/{{project}}/locations/global/securityGateways/{{security_gateways_id}}/applications?applicationId={{application_id}}" )
161
210
if err != nil {
@@ -278,6 +327,9 @@ func resourceBeyondcorpApplicationRead(d *schema.ResourceData, meta interface{})
278
327
if err := d .Set ("endpoint_matchers" , flattenBeyondcorpApplicationEndpointMatchers (res ["endpointMatchers" ], d , config )); err != nil {
279
328
return fmt .Errorf ("Error reading Application: %s" , err )
280
329
}
330
+ if err := d .Set ("upstreams" , flattenBeyondcorpApplicationUpstreams (res ["upstreams" ], d , config )); err != nil {
331
+ return fmt .Errorf ("Error reading Application: %s" , err )
332
+ }
281
333
if err := d .Set ("name" , flattenBeyondcorpApplicationName (res ["name" ], d , config )); err != nil {
282
334
return fmt .Errorf ("Error reading Application: %s" , err )
283
335
}
@@ -316,6 +368,12 @@ func resourceBeyondcorpApplicationUpdate(d *schema.ResourceData, meta interface{
316
368
} else if v , ok := d .GetOkExists ("endpoint_matchers" ); ! tpgresource .IsEmptyValue (reflect .ValueOf (v )) && (ok || ! reflect .DeepEqual (v , endpointMatchersProp )) {
317
369
obj ["endpointMatchers" ] = endpointMatchersProp
318
370
}
371
+ upstreamsProp , err := expandBeyondcorpApplicationUpstreams (d .Get ("upstreams" ), d , config )
372
+ if err != nil {
373
+ return err
374
+ } else if v , ok := d .GetOkExists ("upstreams" ); ! tpgresource .IsEmptyValue (reflect .ValueOf (v )) && (ok || ! reflect .DeepEqual (v , upstreamsProp )) {
375
+ obj ["upstreams" ] = upstreamsProp
376
+ }
319
377
320
378
url , err := tpgresource .ReplaceVars (d , config , "{{BeyondcorpBasePath}}projects/{{project}}/locations/global/securityGateways/{{security_gateways_id}}/applications/{{application_id}}" )
321
379
if err != nil {
@@ -333,6 +391,10 @@ func resourceBeyondcorpApplicationUpdate(d *schema.ResourceData, meta interface{
333
391
if d .HasChange ("endpoint_matchers" ) {
334
392
updateMask = append (updateMask , "endpointMatchers" )
335
393
}
394
+
395
+ if d .HasChange ("upstreams" ) {
396
+ updateMask = append (updateMask , "upstreams" )
397
+ }
336
398
// updateMask is a URL parameter but not present in the schema, so ReplaceVars
337
399
// won't set it
338
400
url , err = transport_tpg .AddQueryParams (url , map [string ]string {"updateMask" : strings .Join (updateMask , "," )})
@@ -487,6 +549,59 @@ func flattenBeyondcorpApplicationEndpointMatchersPorts(v interface{}, d *schema.
487
549
return v
488
550
}
489
551
552
+ func flattenBeyondcorpApplicationUpstreams (v interface {}, d * schema.ResourceData , config * transport_tpg.Config ) interface {} {
553
+ if v == nil {
554
+ return v
555
+ }
556
+ l := v .([]interface {})
557
+ transformed := make ([]interface {}, 0 , len (l ))
558
+ for _ , raw := range l {
559
+ original := raw .(map [string ]interface {})
560
+ if len (original ) < 1 {
561
+ // Do not include empty json objects coming back from the api
562
+ continue
563
+ }
564
+ transformed = append (transformed , map [string ]interface {}{
565
+ "egress_policy" : flattenBeyondcorpApplicationUpstreamsEgressPolicy (original ["egressPolicy" ], d , config ),
566
+ "network" : flattenBeyondcorpApplicationUpstreamsNetwork (original ["network" ], d , config ),
567
+ })
568
+ }
569
+ return transformed
570
+ }
571
+ func flattenBeyondcorpApplicationUpstreamsEgressPolicy (v interface {}, d * schema.ResourceData , config * transport_tpg.Config ) interface {} {
572
+ if v == nil {
573
+ return nil
574
+ }
575
+ original := v .(map [string ]interface {})
576
+ if len (original ) == 0 {
577
+ return nil
578
+ }
579
+ transformed := make (map [string ]interface {})
580
+ transformed ["regions" ] =
581
+ flattenBeyondcorpApplicationUpstreamsEgressPolicyRegions (original ["regions" ], d , config )
582
+ return []interface {}{transformed }
583
+ }
584
+ func flattenBeyondcorpApplicationUpstreamsEgressPolicyRegions (v interface {}, d * schema.ResourceData , config * transport_tpg.Config ) interface {} {
585
+ return v
586
+ }
587
+
588
+ func flattenBeyondcorpApplicationUpstreamsNetwork (v interface {}, d * schema.ResourceData , config * transport_tpg.Config ) interface {} {
589
+ if v == nil {
590
+ return nil
591
+ }
592
+ original := v .(map [string ]interface {})
593
+ if len (original ) == 0 {
594
+ return nil
595
+ }
596
+ transformed := make (map [string ]interface {})
597
+ transformed ["name" ] =
598
+ flattenBeyondcorpApplicationUpstreamsNetworkName (original ["name" ], d , config )
599
+ return []interface {}{transformed }
600
+ }
601
+ func flattenBeyondcorpApplicationUpstreamsNetworkName (v interface {}, d * schema.ResourceData , config * transport_tpg.Config ) interface {} {
602
+ return v
603
+ }
604
+
490
605
func flattenBeyondcorpApplicationName (v interface {}, d * schema.ResourceData , config * transport_tpg.Config ) interface {} {
491
606
return v
492
607
}
@@ -535,3 +650,78 @@ func expandBeyondcorpApplicationEndpointMatchersHostname(v interface{}, d tpgres
535
650
func expandBeyondcorpApplicationEndpointMatchersPorts (v interface {}, d tpgresource.TerraformResourceData , config * transport_tpg.Config ) (interface {}, error ) {
536
651
return v , nil
537
652
}
653
+
654
+ func expandBeyondcorpApplicationUpstreams (v interface {}, d tpgresource.TerraformResourceData , config * transport_tpg.Config ) (interface {}, error ) {
655
+ l := v .([]interface {})
656
+ req := make ([]interface {}, 0 , len (l ))
657
+ for _ , raw := range l {
658
+ if raw == nil {
659
+ continue
660
+ }
661
+ original := raw .(map [string ]interface {})
662
+ transformed := make (map [string ]interface {})
663
+
664
+ transformedEgressPolicy , err := expandBeyondcorpApplicationUpstreamsEgressPolicy (original ["egress_policy" ], d , config )
665
+ if err != nil {
666
+ return nil , err
667
+ } else if val := reflect .ValueOf (transformedEgressPolicy ); val .IsValid () && ! tpgresource .IsEmptyValue (val ) {
668
+ transformed ["egressPolicy" ] = transformedEgressPolicy
669
+ }
670
+
671
+ transformedNetwork , err := expandBeyondcorpApplicationUpstreamsNetwork (original ["network" ], d , config )
672
+ if err != nil {
673
+ return nil , err
674
+ } else if val := reflect .ValueOf (transformedNetwork ); val .IsValid () && ! tpgresource .IsEmptyValue (val ) {
675
+ transformed ["network" ] = transformedNetwork
676
+ }
677
+
678
+ req = append (req , transformed )
679
+ }
680
+ return req , nil
681
+ }
682
+
683
+ func expandBeyondcorpApplicationUpstreamsEgressPolicy (v interface {}, d tpgresource.TerraformResourceData , config * transport_tpg.Config ) (interface {}, error ) {
684
+ l := v .([]interface {})
685
+ if len (l ) == 0 || l [0 ] == nil {
686
+ return nil , nil
687
+ }
688
+ raw := l [0 ]
689
+ original := raw .(map [string ]interface {})
690
+ transformed := make (map [string ]interface {})
691
+
692
+ transformedRegions , err := expandBeyondcorpApplicationUpstreamsEgressPolicyRegions (original ["regions" ], d , config )
693
+ if err != nil {
694
+ return nil , err
695
+ } else if val := reflect .ValueOf (transformedRegions ); val .IsValid () && ! tpgresource .IsEmptyValue (val ) {
696
+ transformed ["regions" ] = transformedRegions
697
+ }
698
+
699
+ return transformed , nil
700
+ }
701
+
702
+ func expandBeyondcorpApplicationUpstreamsEgressPolicyRegions (v interface {}, d tpgresource.TerraformResourceData , config * transport_tpg.Config ) (interface {}, error ) {
703
+ return v , nil
704
+ }
705
+
706
+ func expandBeyondcorpApplicationUpstreamsNetwork (v interface {}, d tpgresource.TerraformResourceData , config * transport_tpg.Config ) (interface {}, error ) {
707
+ l := v .([]interface {})
708
+ if len (l ) == 0 || l [0 ] == nil {
709
+ return nil , nil
710
+ }
711
+ raw := l [0 ]
712
+ original := raw .(map [string ]interface {})
713
+ transformed := make (map [string ]interface {})
714
+
715
+ transformedName , err := expandBeyondcorpApplicationUpstreamsNetworkName (original ["name" ], d , config )
716
+ if err != nil {
717
+ return nil , err
718
+ } else if val := reflect .ValueOf (transformedName ); val .IsValid () && ! tpgresource .IsEmptyValue (val ) {
719
+ transformed ["name" ] = transformedName
720
+ }
721
+
722
+ return transformed , nil
723
+ }
724
+
725
+ func expandBeyondcorpApplicationUpstreamsNetworkName (v interface {}, d tpgresource.TerraformResourceData , config * transport_tpg.Config ) (interface {}, error ) {
726
+ return v , nil
727
+ }
0 commit comments