@@ -252,6 +252,33 @@ https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names`,
252252 },
253253 },
254254 },
255+ "ports" : {
256+ Type : schema .TypeList ,
257+ Computed : true ,
258+ Optional : true ,
259+ Description : `List of open ports in the container.
260+ More Info:
261+ https://cloud.google.com/run/docs/reference/rest/v1/RevisionSpec#ContainerPort` ,
262+ Elem : & schema.Resource {
263+ Schema : map [string ]* schema.Schema {
264+ "container_port" : {
265+ Type : schema .TypeInt ,
266+ Required : true ,
267+ Description : `Port number.` ,
268+ },
269+ "name" : {
270+ Type : schema .TypeString ,
271+ Optional : true ,
272+ Description : `Name of the port.` ,
273+ },
274+ "protocol" : {
275+ Type : schema .TypeString ,
276+ Optional : true ,
277+ Description : `Protocol used on port. Defaults to TCP.` ,
278+ },
279+ },
280+ },
281+ },
255282 "resources" : {
256283 Type : schema .TypeList ,
257284 Computed : true ,
@@ -1028,6 +1055,7 @@ func flattenCloudRunServiceSpecTemplateSpecContainers(v interface{}, d *schema.R
10281055 "image" : flattenCloudRunServiceSpecTemplateSpecContainersImage (original ["image" ], d , config ),
10291056 "command" : flattenCloudRunServiceSpecTemplateSpecContainersCommand (original ["command" ], d , config ),
10301057 "env" : flattenCloudRunServiceSpecTemplateSpecContainersEnv (original ["env" ], d , config ),
1058+ "ports" : flattenCloudRunServiceSpecTemplateSpecContainersPorts (original ["ports" ], d , config ),
10311059 "resources" : flattenCloudRunServiceSpecTemplateSpecContainersResources (original ["resources" ], d , config ),
10321060 })
10331061 }
@@ -1172,6 +1200,51 @@ func flattenCloudRunServiceSpecTemplateSpecContainersEnvValue(v interface{}, d *
11721200 return v
11731201}
11741202
1203+ func flattenCloudRunServiceSpecTemplateSpecContainersPorts (v interface {}, d * schema.ResourceData , config * Config ) interface {} {
1204+ if v == nil {
1205+ return v
1206+ }
1207+ l := v .([]interface {})
1208+ transformed := make ([]interface {}, 0 , len (l ))
1209+ for _ , raw := range l {
1210+ original := raw .(map [string ]interface {})
1211+ if len (original ) < 1 {
1212+ // Do not include empty json objects coming back from the api
1213+ continue
1214+ }
1215+ transformed = append (transformed , map [string ]interface {}{
1216+ "name" : flattenCloudRunServiceSpecTemplateSpecContainersPortsName (original ["name" ], d , config ),
1217+ "protocol" : flattenCloudRunServiceSpecTemplateSpecContainersPortsProtocol (original ["protocol" ], d , config ),
1218+ "container_port" : flattenCloudRunServiceSpecTemplateSpecContainersPortsContainerPort (original ["containerPort" ], d , config ),
1219+ })
1220+ }
1221+ return transformed
1222+ }
1223+ func flattenCloudRunServiceSpecTemplateSpecContainersPortsName (v interface {}, d * schema.ResourceData , config * Config ) interface {} {
1224+ return v
1225+ }
1226+
1227+ func flattenCloudRunServiceSpecTemplateSpecContainersPortsProtocol (v interface {}, d * schema.ResourceData , config * Config ) interface {} {
1228+ return v
1229+ }
1230+
1231+ func flattenCloudRunServiceSpecTemplateSpecContainersPortsContainerPort (v interface {}, d * schema.ResourceData , config * Config ) interface {} {
1232+ // Handles the string fixed64 format
1233+ if strVal , ok := v .(string ); ok {
1234+ if intVal , err := strconv .ParseInt (strVal , 10 , 64 ); err == nil {
1235+ return intVal
1236+ }
1237+ }
1238+
1239+ // number values are represented as float64
1240+ if floatVal , ok := v .(float64 ); ok {
1241+ intVal := int (floatVal )
1242+ return intVal
1243+ }
1244+
1245+ return v // let terraform core handle it otherwise
1246+ }
1247+
11751248func flattenCloudRunServiceSpecTemplateSpecContainersResources (v interface {}, d * schema.ResourceData , config * Config ) interface {} {
11761249 if v == nil {
11771250 return nil
@@ -1706,6 +1779,13 @@ func expandCloudRunServiceSpecTemplateSpecContainers(v interface{}, d TerraformR
17061779 transformed ["env" ] = transformedEnv
17071780 }
17081781
1782+ transformedPorts , err := expandCloudRunServiceSpecTemplateSpecContainersPorts (original ["ports" ], d , config )
1783+ if err != nil {
1784+ return nil , err
1785+ } else if val := reflect .ValueOf (transformedPorts ); val .IsValid () && ! isEmptyValue (val ) {
1786+ transformed ["ports" ] = transformedPorts
1787+ }
1788+
17091789 transformedResources , err := expandCloudRunServiceSpecTemplateSpecContainersResources (original ["resources" ], d , config )
17101790 if err != nil {
17111791 return nil , err
@@ -1917,6 +1997,54 @@ func expandCloudRunServiceSpecTemplateSpecContainersEnvValue(v interface{}, d Te
19171997 return v , nil
19181998}
19191999
2000+ func expandCloudRunServiceSpecTemplateSpecContainersPorts (v interface {}, d TerraformResourceData , config * Config ) (interface {}, error ) {
2001+ l := v .([]interface {})
2002+ req := make ([]interface {}, 0 , len (l ))
2003+ for _ , raw := range l {
2004+ if raw == nil {
2005+ continue
2006+ }
2007+ original := raw .(map [string ]interface {})
2008+ transformed := make (map [string ]interface {})
2009+
2010+ transformedName , err := expandCloudRunServiceSpecTemplateSpecContainersPortsName (original ["name" ], d , config )
2011+ if err != nil {
2012+ return nil , err
2013+ } else if val := reflect .ValueOf (transformedName ); val .IsValid () && ! isEmptyValue (val ) {
2014+ transformed ["name" ] = transformedName
2015+ }
2016+
2017+ transformedProtocol , err := expandCloudRunServiceSpecTemplateSpecContainersPortsProtocol (original ["protocol" ], d , config )
2018+ if err != nil {
2019+ return nil , err
2020+ } else if val := reflect .ValueOf (transformedProtocol ); val .IsValid () && ! isEmptyValue (val ) {
2021+ transformed ["protocol" ] = transformedProtocol
2022+ }
2023+
2024+ transformedContainerPort , err := expandCloudRunServiceSpecTemplateSpecContainersPortsContainerPort (original ["container_port" ], d , config )
2025+ if err != nil {
2026+ return nil , err
2027+ } else if val := reflect .ValueOf (transformedContainerPort ); val .IsValid () && ! isEmptyValue (val ) {
2028+ transformed ["containerPort" ] = transformedContainerPort
2029+ }
2030+
2031+ req = append (req , transformed )
2032+ }
2033+ return req , nil
2034+ }
2035+
2036+ func expandCloudRunServiceSpecTemplateSpecContainersPortsName (v interface {}, d TerraformResourceData , config * Config ) (interface {}, error ) {
2037+ return v , nil
2038+ }
2039+
2040+ func expandCloudRunServiceSpecTemplateSpecContainersPortsProtocol (v interface {}, d TerraformResourceData , config * Config ) (interface {}, error ) {
2041+ return v , nil
2042+ }
2043+
2044+ func expandCloudRunServiceSpecTemplateSpecContainersPortsContainerPort (v interface {}, d TerraformResourceData , config * Config ) (interface {}, error ) {
2045+ return v , nil
2046+ }
2047+
19202048func expandCloudRunServiceSpecTemplateSpecContainersResources (v interface {}, d TerraformResourceData , config * Config ) (interface {}, error ) {
19212049 l := v .([]interface {})
19222050 if len (l ) == 0 || l [0 ] == nil {
0 commit comments