@@ -2161,11 +2161,28 @@ func resourceContainerClusterCreate(d *schema.ResourceData, meta interface{}) er
2161
2161
cluster .SecurityPostureConfig = expandSecurityPostureConfig (v )
2162
2162
}
2163
2163
2164
+ needUpdateAfterCreate := false
2165
+
2164
2166
// For now PSC based cluster don't support `enable_private_endpoint` on `create`, but only on `update` API call.
2165
2167
// If cluster is PSC based and enable_private_endpoint is set to true we will ignore it on `create` call and update cluster right after creation.
2166
2168
enablePrivateEndpointPSCCluster := isEnablePrivateEndpointPSCCluster (cluster )
2167
2169
if enablePrivateEndpointPSCCluster {
2168
2170
cluster .PrivateClusterConfig .EnablePrivateEndpoint = false
2171
+ needUpdateAfterCreate = true
2172
+ }
2173
+
2174
+ enablePDCSI := isEnablePDCSI (cluster )
2175
+ if ! enablePDCSI {
2176
+ // GcePersistentDiskCsiDriver cannot be disabled at cluster create, only on cluster update. Ignore on create then update after creation.
2177
+ // If pdcsi is disabled, the config should be defined. But we will be paranoid and double-check.
2178
+ needUpdateAfterCreate = true
2179
+ if cluster .AddonsConfig == nil {
2180
+ cluster .AddonsConfig = & container.AddonsConfig {}
2181
+ }
2182
+ if cluster .AddonsConfig .GcePersistentDiskCsiDriverConfig == nil {
2183
+ cluster .AddonsConfig .GcePersistentDiskCsiDriverConfig = & container.GcePersistentDiskCsiDriverConfig {}
2184
+ }
2185
+ cluster .AddonsConfig .GcePersistentDiskCsiDriverConfig .Enabled = true
2169
2186
}
2170
2187
2171
2188
req := & container.CreateClusterRequest {
@@ -2252,14 +2269,22 @@ func resourceContainerClusterCreate(d *schema.ResourceData, meta interface{}) er
2252
2269
}
2253
2270
}
2254
2271
2255
- if enablePrivateEndpointPSCCluster {
2272
+ if needUpdateAfterCreate {
2256
2273
name := containerClusterFullName (project , location , clusterName )
2257
- req := & container.UpdateClusterRequest {
2258
- Update : & container.ClusterUpdate {
2259
- DesiredEnablePrivateEndpoint : true ,
2260
- ForceSendFields : []string {"DesiredEnablePrivateEndpoint" },
2261
- },
2274
+ update := & container.ClusterUpdate {}
2275
+ if enablePrivateEndpointPSCCluster {
2276
+ update .DesiredEnablePrivateEndpoint = true
2277
+ update .ForceSendFields = append (update .ForceSendFields , "DesiredEnablePrivateEndpoint" )
2278
+ }
2279
+ if ! enablePDCSI {
2280
+ update .DesiredAddonsConfig = & container.AddonsConfig {
2281
+ GcePersistentDiskCsiDriverConfig : & container.GcePersistentDiskCsiDriverConfig {
2282
+ Enabled : false ,
2283
+ },
2284
+ }
2285
+ update .ForceSendFields = append (update .ForceSendFields , "DesiredAddonsConfig.GcePersistentDiskCsiDriverConfig.Enabled" )
2262
2286
}
2287
+ req := & container.UpdateClusterRequest {Update : update }
2263
2288
2264
2289
err = transport_tpg .Retry (transport_tpg.RetryOptions {
2265
2290
RetryFunc : func () error {
@@ -2272,12 +2297,12 @@ func resourceContainerClusterCreate(d *schema.ResourceData, meta interface{}) er
2272
2297
},
2273
2298
})
2274
2299
if err != nil {
2275
- return errwrap .Wrapf ("Error updating enable private endpoint : {{err}}" , err )
2300
+ return errwrap .Wrapf (fmt . Sprintf ( "Error updating cluster for %v : {{err}}" , update . ForceSendFields ) , err )
2276
2301
}
2277
2302
2278
2303
err = ContainerOperationWait (config , op , project , location , "updating enable private endpoint" , userAgent , d .Timeout (schema .TimeoutCreate ))
2279
2304
if err != nil {
2280
- return errwrap .Wrapf ("Error while waiting to enable private endpoint : {{err}}" , err )
2305
+ return errwrap .Wrapf (fmt . Sprintf ( "Error while waiting on cluster update for %v : {{err}}" , update . ForceSendFields ) , err )
2281
2306
}
2282
2307
}
2283
2308
@@ -4511,6 +4536,13 @@ func isEnablePrivateEndpointPSCCluster(cluster *container.Cluster) bool {
4511
4536
return false
4512
4537
}
4513
4538
4539
+ func isEnablePDCSI (cluster * container.Cluster ) bool {
4540
+ if cluster .AddonsConfig == nil || cluster .AddonsConfig .GcePersistentDiskCsiDriverConfig == nil {
4541
+ return true // PDCSI is enabled by default.
4542
+ }
4543
+ return cluster .AddonsConfig .GcePersistentDiskCsiDriverConfig .Enabled
4544
+ }
4545
+
4514
4546
func expandPrivateClusterConfig (configured interface {}) * container.PrivateClusterConfig {
4515
4547
l := configured .([]interface {})
4516
4548
if len (l ) == 0 {
0 commit comments