@@ -1369,6 +1369,23 @@ func ResourceContainerCluster() *schema.Resource {
1369
1369
},
1370
1370
},
1371
1371
},
1372
+ "additional_pod_ranges_config" : {
1373
+ Type : schema .TypeList ,
1374
+ MaxItems : 1 ,
1375
+ Optional : true ,
1376
+ Description : `AdditionalPodRangesConfig is the configuration for additional pod secondary ranges supporting the ClusterUpdate message.` ,
1377
+ Elem : & schema.Resource {
1378
+ Schema : map [string ]* schema.Schema {
1379
+ "pod_range_names" : {
1380
+ Type : schema .TypeSet ,
1381
+ MinItems : 1 ,
1382
+ Required : true ,
1383
+ Elem : & schema.Schema {Type : schema .TypeString },
1384
+ Description : `Name for pod secondary ipv4 range which has the actual range defined ahead.` ,
1385
+ },
1386
+ },
1387
+ },
1388
+ },
1372
1389
},
1373
1390
},
1374
1391
},
@@ -2149,6 +2166,38 @@ func resourceContainerClusterCreate(d *schema.ResourceData, meta interface{}) er
2149
2166
}
2150
2167
}
2151
2168
2169
+ if names , ok := d .GetOk ("ip_allocation_policy.0.additional_pod_ranges_config.0.pod_range_names" ); ok {
2170
+ name := containerClusterFullName (project , location , clusterName )
2171
+ additionalPodRangesConfig := & container.AdditionalPodRangesConfig {
2172
+ PodRangeNames : tpgresource .ConvertStringSet (names .(* schema.Set )),
2173
+ }
2174
+
2175
+ req := & container.UpdateClusterRequest {
2176
+ Update : & container.ClusterUpdate {
2177
+ AdditionalPodRangesConfig : additionalPodRangesConfig ,
2178
+ },
2179
+ }
2180
+
2181
+ err = transport_tpg .Retry (transport_tpg.RetryOptions {
2182
+ RetryFunc : func () error {
2183
+ clusterUpdateCall := config .NewContainerClient (userAgent ).Projects .Locations .Clusters .Update (name , req )
2184
+ if config .UserProjectOverride {
2185
+ clusterUpdateCall .Header ().Add ("X-Goog-User-Project" , project )
2186
+ }
2187
+ op , err = clusterUpdateCall .Do ()
2188
+ return err
2189
+ },
2190
+ })
2191
+ if err != nil {
2192
+ return errwrap .Wrapf ("Error updating AdditionalPodRangesConfig: {{err}}" , err )
2193
+ }
2194
+
2195
+ err = ContainerOperationWait (config , op , project , location , "updating AdditionalPodRangesConfig" , userAgent , d .Timeout (schema .TimeoutCreate ))
2196
+ if err != nil {
2197
+ return errwrap .Wrapf ("Error while waiting to update AdditionalPodRangesConfig: {{err}}" , err )
2198
+ }
2199
+ }
2200
+
2152
2201
if err := resourceContainerClusterRead (d , meta ); err != nil {
2153
2202
return err
2154
2203
}
@@ -3038,6 +3087,51 @@ func resourceContainerClusterUpdate(d *schema.ResourceData, meta interface{}) er
3038
3087
3039
3088
}
3040
3089
3090
+ if d .HasChange ("ip_allocation_policy.0.additional_pod_ranges_config" ) {
3091
+ o , n := d .GetChange ("ip_allocation_policy.0.additional_pod_ranges_config.0.pod_range_names" )
3092
+ old_names := o .(* schema.Set )
3093
+ new_names := n .(* schema.Set )
3094
+
3095
+ // Filter unchanged names.
3096
+ removed_names := old_names .Difference (new_names )
3097
+ added_names := new_names .Difference (old_names )
3098
+
3099
+ var additional_config * container.AdditionalPodRangesConfig
3100
+ var removed_config * container.AdditionalPodRangesConfig
3101
+ if added_names .Len () > 0 {
3102
+ var names []string
3103
+ for _ , name := range added_names .List () {
3104
+ names = append (names , name .(string ))
3105
+ }
3106
+ additional_config = & container.AdditionalPodRangesConfig {
3107
+ PodRangeNames : names ,
3108
+ }
3109
+ }
3110
+ if removed_names .Len () > 0 {
3111
+ var names []string
3112
+ for _ , name := range removed_names .List () {
3113
+ names = append (names , name .(string ))
3114
+ }
3115
+ removed_config = & container.AdditionalPodRangesConfig {
3116
+ PodRangeNames : names ,
3117
+ }
3118
+ }
3119
+ req := & container.UpdateClusterRequest {
3120
+ Update : & container.ClusterUpdate {
3121
+ AdditionalPodRangesConfig : additional_config ,
3122
+ RemovedAdditionalPodRangesConfig : removed_config ,
3123
+ },
3124
+ }
3125
+
3126
+ updateF := updateFunc (req , "updating AdditionalPodRangesConfig" )
3127
+ // Call update serially.
3128
+ if err := transport_tpg .LockedCall (lockKey , updateF ); err != nil {
3129
+ return err
3130
+ }
3131
+
3132
+ log .Printf ("[INFO] GKE cluster %s's AdditionalPodRangesConfig has been updated" , d .Id ())
3133
+ }
3134
+
3041
3135
if n , ok := d .GetOk ("node_pool.#" ); ok {
3042
3136
for i := 0 ; i < n .(int ); i ++ {
3043
3137
nodePoolInfo , err := extractNodePoolInformationFromCluster (d , config , clusterName )
@@ -4108,6 +4202,25 @@ func flattenSecurityPostureConfig(spc *container.SecurityPostureConfig) []map[st
4108
4202
return []map [string ]interface {}{result }
4109
4203
}
4110
4204
4205
+ func flattenAdditionalPodRangesConfig (ipAllocationPolicy * container.IPAllocationPolicy ) []map [string ]interface {} {
4206
+ if ipAllocationPolicy == nil {
4207
+ return nil
4208
+ }
4209
+ result := make (map [string ]interface {})
4210
+
4211
+ if aprc := ipAllocationPolicy .AdditionalPodRangesConfig ; aprc != nil {
4212
+ if len (aprc .PodRangeNames ) > 0 {
4213
+ result ["pod_range_names" ] = aprc .PodRangeNames
4214
+ } else {
4215
+ return nil
4216
+ }
4217
+ } else {
4218
+ return nil
4219
+ }
4220
+
4221
+ return []map [string ]interface {}{result }
4222
+ }
4223
+
4111
4224
func expandNotificationConfig (configured interface {}) * container.NotificationConfig {
4112
4225
l := configured .([]interface {})
4113
4226
if len (l ) == 0 || l [0 ] == nil {
@@ -4878,6 +4991,7 @@ func flattenIPAllocationPolicy(c *container.Cluster, d *schema.ResourceData, con
4878
4991
"services_secondary_range_name" : p .ServicesSecondaryRangeName ,
4879
4992
"stack_type" : p .StackType ,
4880
4993
"pod_cidr_overprovision_config" : flattenPodCidrOverprovisionConfig (p .PodCidrOverprovisionConfig ),
4994
+ "additional_pod_ranges_config" : flattenAdditionalPodRangesConfig (c .IpAllocationPolicy ),
4881
4995
},
4882
4996
}, nil
4883
4997
}
0 commit comments