@@ -75,6 +75,26 @@ func ResourceWorkstationsWorkstationConfig() *schema.Resource {
75
75
ForceNew : true ,
76
76
Description : `The ID to be assigned to the workstation cluster config.` ,
77
77
},
78
+ "allowed_ports" : {
79
+ Type : schema .TypeList ,
80
+ Computed : true ,
81
+ Optional : true ,
82
+ Description : `A list of port ranges specifying single ports or ranges of ports that are externally accessible in the workstation. Allowed ports must be one of 22, 80, or within range 1024-65535. If not specified defaults to ports 22, 80, and ports 1024-65535.` ,
83
+ Elem : & schema.Resource {
84
+ Schema : map [string ]* schema.Schema {
85
+ "first" : {
86
+ Type : schema .TypeInt ,
87
+ Optional : true ,
88
+ Description : `Starting port number for the current range of ports. Valid ports are 22, 80, and ports within the range 1024-65535.` ,
89
+ },
90
+ "last" : {
91
+ Type : schema .TypeInt ,
92
+ Optional : true ,
93
+ Description : `Ending port number for the current range of ports. Valid ports are 22, 80, and ports within the range 1024-65535.` ,
94
+ },
95
+ },
96
+ },
97
+ },
78
98
"annotations" : {
79
99
Type : schema .TypeMap ,
80
100
Optional : true ,
@@ -725,6 +745,12 @@ func resourceWorkstationsWorkstationConfigCreate(d *schema.ResourceData, meta in
725
745
} else if v , ok := d .GetOkExists ("disable_tcp_connections" ); ! tpgresource .IsEmptyValue (reflect .ValueOf (disableTcpConnectionsProp )) && (ok || ! reflect .DeepEqual (v , disableTcpConnectionsProp )) {
726
746
obj ["disableTcpConnections" ] = disableTcpConnectionsProp
727
747
}
748
+ allowedPortsProp , err := expandWorkstationsWorkstationConfigAllowedPorts (d .Get ("allowed_ports" ), d , config )
749
+ if err != nil {
750
+ return err
751
+ } else if v , ok := d .GetOkExists ("allowed_ports" ); ! tpgresource .IsEmptyValue (reflect .ValueOf (allowedPortsProp )) && (ok || ! reflect .DeepEqual (v , allowedPortsProp )) {
752
+ obj ["allowedPorts" ] = allowedPortsProp
753
+ }
728
754
labelsProp , err := expandWorkstationsWorkstationConfigEffectiveLabels (d .Get ("effective_labels" ), d , config )
729
755
if err != nil {
730
756
return err
@@ -890,6 +916,9 @@ func resourceWorkstationsWorkstationConfigRead(d *schema.ResourceData, meta inte
890
916
if err := d .Set ("disable_tcp_connections" , flattenWorkstationsWorkstationConfigDisableTcpConnections (res ["disableTcpConnections" ], d , config )); err != nil {
891
917
return fmt .Errorf ("Error reading WorkstationConfig: %s" , err )
892
918
}
919
+ if err := d .Set ("allowed_ports" , flattenWorkstationsWorkstationConfigAllowedPorts (res ["allowedPorts" ], d , config )); err != nil {
920
+ return fmt .Errorf ("Error reading WorkstationConfig: %s" , err )
921
+ }
893
922
if err := d .Set ("conditions" , flattenWorkstationsWorkstationConfigConditions (res ["conditions" ], d , config )); err != nil {
894
923
return fmt .Errorf ("Error reading WorkstationConfig: %s" , err )
895
924
}
@@ -988,6 +1017,12 @@ func resourceWorkstationsWorkstationConfigUpdate(d *schema.ResourceData, meta in
988
1017
} else if v , ok := d .GetOkExists ("disable_tcp_connections" ); ! tpgresource .IsEmptyValue (reflect .ValueOf (v )) && (ok || ! reflect .DeepEqual (v , disableTcpConnectionsProp )) {
989
1018
obj ["disableTcpConnections" ] = disableTcpConnectionsProp
990
1019
}
1020
+ allowedPortsProp , err := expandWorkstationsWorkstationConfigAllowedPorts (d .Get ("allowed_ports" ), d , config )
1021
+ if err != nil {
1022
+ return err
1023
+ } else if v , ok := d .GetOkExists ("allowed_ports" ); ! tpgresource .IsEmptyValue (reflect .ValueOf (v )) && (ok || ! reflect .DeepEqual (v , allowedPortsProp )) {
1024
+ obj ["allowedPorts" ] = allowedPortsProp
1025
+ }
991
1026
labelsProp , err := expandWorkstationsWorkstationConfigEffectiveLabels (d .Get ("effective_labels" ), d , config )
992
1027
if err != nil {
993
1028
return err
@@ -1072,6 +1107,10 @@ func resourceWorkstationsWorkstationConfigUpdate(d *schema.ResourceData, meta in
1072
1107
updateMask = append (updateMask , "disableTcpConnections" )
1073
1108
}
1074
1109
1110
+ if d .HasChange ("allowed_ports" ) {
1111
+ updateMask = append (updateMask , "allowedPorts" )
1112
+ }
1113
+
1075
1114
if d .HasChange ("effective_labels" ) {
1076
1115
updateMask = append (updateMask , "labels" )
1077
1116
}
@@ -1837,6 +1876,59 @@ func flattenWorkstationsWorkstationConfigDisableTcpConnections(v interface{}, d
1837
1876
return v
1838
1877
}
1839
1878
1879
+ func flattenWorkstationsWorkstationConfigAllowedPorts (v interface {}, d * schema.ResourceData , config * transport_tpg.Config ) interface {} {
1880
+ if v == nil {
1881
+ return v
1882
+ }
1883
+ l := v .([]interface {})
1884
+ transformed := make ([]interface {}, 0 , len (l ))
1885
+ for _ , raw := range l {
1886
+ original := raw .(map [string ]interface {})
1887
+ if len (original ) < 1 {
1888
+ // Do not include empty json objects coming back from the api
1889
+ continue
1890
+ }
1891
+ transformed = append (transformed , map [string ]interface {}{
1892
+ "first" : flattenWorkstationsWorkstationConfigAllowedPortsFirst (original ["first" ], d , config ),
1893
+ "last" : flattenWorkstationsWorkstationConfigAllowedPortsLast (original ["last" ], d , config ),
1894
+ })
1895
+ }
1896
+ return transformed
1897
+ }
1898
+ func flattenWorkstationsWorkstationConfigAllowedPortsFirst (v interface {}, d * schema.ResourceData , config * transport_tpg.Config ) interface {} {
1899
+ // Handles the string fixed64 format
1900
+ if strVal , ok := v .(string ); ok {
1901
+ if intVal , err := tpgresource .StringToFixed64 (strVal ); err == nil {
1902
+ return intVal
1903
+ }
1904
+ }
1905
+
1906
+ // number values are represented as float64
1907
+ if floatVal , ok := v .(float64 ); ok {
1908
+ intVal := int (floatVal )
1909
+ return intVal
1910
+ }
1911
+
1912
+ return v // let terraform core handle it otherwise
1913
+ }
1914
+
1915
+ func flattenWorkstationsWorkstationConfigAllowedPortsLast (v interface {}, d * schema.ResourceData , config * transport_tpg.Config ) interface {} {
1916
+ // Handles the string fixed64 format
1917
+ if strVal , ok := v .(string ); ok {
1918
+ if intVal , err := tpgresource .StringToFixed64 (strVal ); err == nil {
1919
+ return intVal
1920
+ }
1921
+ }
1922
+
1923
+ // number values are represented as float64
1924
+ if floatVal , ok := v .(float64 ); ok {
1925
+ intVal := int (floatVal )
1926
+ return intVal
1927
+ }
1928
+
1929
+ return v // let terraform core handle it otherwise
1930
+ }
1931
+
1840
1932
func flattenWorkstationsWorkstationConfigConditions (v interface {}, d * schema.ResourceData , config * transport_tpg.Config ) interface {} {
1841
1933
if v == nil {
1842
1934
return v
@@ -2673,6 +2765,43 @@ func expandWorkstationsWorkstationConfigDisableTcpConnections(v interface{}, d t
2673
2765
return v , nil
2674
2766
}
2675
2767
2768
+ func expandWorkstationsWorkstationConfigAllowedPorts (v interface {}, d tpgresource.TerraformResourceData , config * transport_tpg.Config ) (interface {}, error ) {
2769
+ l := v .([]interface {})
2770
+ req := make ([]interface {}, 0 , len (l ))
2771
+ for _ , raw := range l {
2772
+ if raw == nil {
2773
+ continue
2774
+ }
2775
+ original := raw .(map [string ]interface {})
2776
+ transformed := make (map [string ]interface {})
2777
+
2778
+ transformedFirst , err := expandWorkstationsWorkstationConfigAllowedPortsFirst (original ["first" ], d , config )
2779
+ if err != nil {
2780
+ return nil , err
2781
+ } else if val := reflect .ValueOf (transformedFirst ); val .IsValid () && ! tpgresource .IsEmptyValue (val ) {
2782
+ transformed ["first" ] = transformedFirst
2783
+ }
2784
+
2785
+ transformedLast , err := expandWorkstationsWorkstationConfigAllowedPortsLast (original ["last" ], d , config )
2786
+ if err != nil {
2787
+ return nil , err
2788
+ } else if val := reflect .ValueOf (transformedLast ); val .IsValid () && ! tpgresource .IsEmptyValue (val ) {
2789
+ transformed ["last" ] = transformedLast
2790
+ }
2791
+
2792
+ req = append (req , transformed )
2793
+ }
2794
+ return req , nil
2795
+ }
2796
+
2797
+ func expandWorkstationsWorkstationConfigAllowedPortsFirst (v interface {}, d tpgresource.TerraformResourceData , config * transport_tpg.Config ) (interface {}, error ) {
2798
+ return v , nil
2799
+ }
2800
+
2801
+ func expandWorkstationsWorkstationConfigAllowedPortsLast (v interface {}, d tpgresource.TerraformResourceData , config * transport_tpg.Config ) (interface {}, error ) {
2802
+ return v , nil
2803
+ }
2804
+
2676
2805
func expandWorkstationsWorkstationConfigEffectiveLabels (v interface {}, d tpgresource.TerraformResourceData , config * transport_tpg.Config ) (map [string ]string , error ) {
2677
2806
if v == nil {
2678
2807
return map [string ]string {}, nil
0 commit comments