@@ -91,6 +91,40 @@ func ResourceIAMWorkforcePoolWorkforcePool() *schema.Resource {
91
91
digits, or hyphens. It must start with a letter, and cannot have a trailing hyphen.
92
92
The prefix 'gcp-' is reserved for use by Google, and may not be specified.` ,
93
93
},
94
+ "access_restrictions" : {
95
+ Type : schema .TypeList ,
96
+ Optional : true ,
97
+ ForceNew : true ,
98
+ Description : `Configure access restrictions on the workforce pool users. This is an optional field. If specified web
99
+ sign-in can be restricted to given set of services or programmatic sign-in can be disabled for pool users.` ,
100
+ MaxItems : 1 ,
101
+ Elem : & schema.Resource {
102
+ Schema : map [string ]* schema.Schema {
103
+ "allowed_services" : {
104
+ Type : schema .TypeList ,
105
+ Optional : true ,
106
+ Description : `Services allowed for web sign-in with the workforce pool.
107
+ If not set by default there are no restrictions.` ,
108
+ Elem : & schema.Resource {
109
+ Schema : map [string ]* schema.Schema {
110
+ "domain" : {
111
+ Type : schema .TypeString ,
112
+ Optional : true ,
113
+ Description : `Domain name of the service.
114
+ Example: console.cloud.google` ,
115
+ },
116
+ },
117
+ },
118
+ },
119
+ "disable_programmatic_signin" : {
120
+ Type : schema .TypeBool ,
121
+ Optional : true ,
122
+ Description : `Disable programmatic sign-in by disabling token issue via the Security Token API endpoint.
123
+ See [Security Token Service API](https://cloud.google.com/iam/docs/reference/sts/rest).` ,
124
+ },
125
+ },
126
+ },
127
+ },
94
128
"description" : {
95
129
Type : schema .TypeString ,
96
130
Optional : true ,
@@ -180,6 +214,12 @@ func resourceIAMWorkforcePoolWorkforcePoolCreate(d *schema.ResourceData, meta in
180
214
} else if v , ok := d .GetOkExists ("session_duration" ); ! tpgresource .IsEmptyValue (reflect .ValueOf (sessionDurationProp )) && (ok || ! reflect .DeepEqual (v , sessionDurationProp )) {
181
215
obj ["sessionDuration" ] = sessionDurationProp
182
216
}
217
+ accessRestrictionsProp , err := expandIAMWorkforcePoolWorkforcePoolAccessRestrictions (d .Get ("access_restrictions" ), d , config )
218
+ if err != nil {
219
+ return err
220
+ } else if v , ok := d .GetOkExists ("access_restrictions" ); ! tpgresource .IsEmptyValue (reflect .ValueOf (accessRestrictionsProp )) && (ok || ! reflect .DeepEqual (v , accessRestrictionsProp )) {
221
+ obj ["accessRestrictions" ] = accessRestrictionsProp
222
+ }
183
223
184
224
url , err := tpgresource .ReplaceVars (d , config , "{{IAMWorkforcePoolBasePath}}locations/{{location}}/workforcePools?workforcePoolId={{workforce_pool_id}}" )
185
225
if err != nil {
@@ -292,6 +332,9 @@ func resourceIAMWorkforcePoolWorkforcePoolRead(d *schema.ResourceData, meta inte
292
332
if err := d .Set ("session_duration" , flattenIAMWorkforcePoolWorkforcePoolSessionDuration (res ["sessionDuration" ], d , config )); err != nil {
293
333
return fmt .Errorf ("Error reading WorkforcePool: %s" , err )
294
334
}
335
+ if err := d .Set ("access_restrictions" , flattenIAMWorkforcePoolWorkforcePoolAccessRestrictions (res ["accessRestrictions" ], d , config )); err != nil {
336
+ return fmt .Errorf ("Error reading WorkforcePool: %s" , err )
337
+ }
295
338
296
339
return nil
297
340
}
@@ -490,6 +533,47 @@ func flattenIAMWorkforcePoolWorkforcePoolSessionDuration(v interface{}, d *schem
490
533
return v
491
534
}
492
535
536
+ func flattenIAMWorkforcePoolWorkforcePoolAccessRestrictions (v interface {}, d * schema.ResourceData , config * transport_tpg.Config ) interface {} {
537
+ if v == nil {
538
+ return nil
539
+ }
540
+ original := v .(map [string ]interface {})
541
+ if len (original ) == 0 {
542
+ return nil
543
+ }
544
+ transformed := make (map [string ]interface {})
545
+ transformed ["allowed_services" ] =
546
+ flattenIAMWorkforcePoolWorkforcePoolAccessRestrictionsAllowedServices (original ["allowedServices" ], d , config )
547
+ transformed ["disable_programmatic_signin" ] =
548
+ flattenIAMWorkforcePoolWorkforcePoolAccessRestrictionsDisableProgrammaticSignin (original ["disableProgrammaticSignin" ], d , config )
549
+ return []interface {}{transformed }
550
+ }
551
+ func flattenIAMWorkforcePoolWorkforcePoolAccessRestrictionsAllowedServices (v interface {}, d * schema.ResourceData , config * transport_tpg.Config ) interface {} {
552
+ if v == nil {
553
+ return v
554
+ }
555
+ l := v .([]interface {})
556
+ transformed := make ([]interface {}, 0 , len (l ))
557
+ for _ , raw := range l {
558
+ original := raw .(map [string ]interface {})
559
+ if len (original ) < 1 {
560
+ // Do not include empty json objects coming back from the api
561
+ continue
562
+ }
563
+ transformed = append (transformed , map [string ]interface {}{
564
+ "domain" : flattenIAMWorkforcePoolWorkforcePoolAccessRestrictionsAllowedServicesDomain (original ["domain" ], d , config ),
565
+ })
566
+ }
567
+ return transformed
568
+ }
569
+ func flattenIAMWorkforcePoolWorkforcePoolAccessRestrictionsAllowedServicesDomain (v interface {}, d * schema.ResourceData , config * transport_tpg.Config ) interface {} {
570
+ return v
571
+ }
572
+
573
+ func flattenIAMWorkforcePoolWorkforcePoolAccessRestrictionsDisableProgrammaticSignin (v interface {}, d * schema.ResourceData , config * transport_tpg.Config ) interface {} {
574
+ return v
575
+ }
576
+
493
577
func expandIAMWorkforcePoolWorkforcePoolParent (v interface {}, d tpgresource.TerraformResourceData , config * transport_tpg.Config ) (interface {}, error ) {
494
578
return v , nil
495
579
}
@@ -510,6 +594,62 @@ func expandIAMWorkforcePoolWorkforcePoolSessionDuration(v interface{}, d tpgreso
510
594
return v , nil
511
595
}
512
596
597
+ func expandIAMWorkforcePoolWorkforcePoolAccessRestrictions (v interface {}, d tpgresource.TerraformResourceData , config * transport_tpg.Config ) (interface {}, error ) {
598
+ l := v .([]interface {})
599
+ if len (l ) == 0 || l [0 ] == nil {
600
+ return nil , nil
601
+ }
602
+ raw := l [0 ]
603
+ original := raw .(map [string ]interface {})
604
+ transformed := make (map [string ]interface {})
605
+
606
+ transformedAllowedServices , err := expandIAMWorkforcePoolWorkforcePoolAccessRestrictionsAllowedServices (original ["allowed_services" ], d , config )
607
+ if err != nil {
608
+ return nil , err
609
+ } else if val := reflect .ValueOf (transformedAllowedServices ); val .IsValid () && ! tpgresource .IsEmptyValue (val ) {
610
+ transformed ["allowedServices" ] = transformedAllowedServices
611
+ }
612
+
613
+ transformedDisableProgrammaticSignin , err := expandIAMWorkforcePoolWorkforcePoolAccessRestrictionsDisableProgrammaticSignin (original ["disable_programmatic_signin" ], d , config )
614
+ if err != nil {
615
+ return nil , err
616
+ } else if val := reflect .ValueOf (transformedDisableProgrammaticSignin ); val .IsValid () && ! tpgresource .IsEmptyValue (val ) {
617
+ transformed ["disableProgrammaticSignin" ] = transformedDisableProgrammaticSignin
618
+ }
619
+
620
+ return transformed , nil
621
+ }
622
+
623
+ func expandIAMWorkforcePoolWorkforcePoolAccessRestrictionsAllowedServices (v interface {}, d tpgresource.TerraformResourceData , config * transport_tpg.Config ) (interface {}, error ) {
624
+ l := v .([]interface {})
625
+ req := make ([]interface {}, 0 , len (l ))
626
+ for _ , raw := range l {
627
+ if raw == nil {
628
+ continue
629
+ }
630
+ original := raw .(map [string ]interface {})
631
+ transformed := make (map [string ]interface {})
632
+
633
+ transformedDomain , err := expandIAMWorkforcePoolWorkforcePoolAccessRestrictionsAllowedServicesDomain (original ["domain" ], d , config )
634
+ if err != nil {
635
+ return nil , err
636
+ } else if val := reflect .ValueOf (transformedDomain ); val .IsValid () && ! tpgresource .IsEmptyValue (val ) {
637
+ transformed ["domain" ] = transformedDomain
638
+ }
639
+
640
+ req = append (req , transformed )
641
+ }
642
+ return req , nil
643
+ }
644
+
645
+ func expandIAMWorkforcePoolWorkforcePoolAccessRestrictionsAllowedServicesDomain (v interface {}, d tpgresource.TerraformResourceData , config * transport_tpg.Config ) (interface {}, error ) {
646
+ return v , nil
647
+ }
648
+
649
+ func expandIAMWorkforcePoolWorkforcePoolAccessRestrictionsDisableProgrammaticSignin (v interface {}, d tpgresource.TerraformResourceData , config * transport_tpg.Config ) (interface {}, error ) {
650
+ return v , nil
651
+ }
652
+
513
653
func resourceIAMWorkforcePoolWorkforcePoolDecoder (d * schema.ResourceData , meta interface {}, res map [string ]interface {}) (map [string ]interface {}, error ) {
514
654
if v := res ["state" ]; v == "DELETED" {
515
655
return nil , nil
0 commit comments