@@ -342,19 +342,22 @@ func resourceContainerCluster() *schema.Resource {
342
342
Optional : true ,
343
343
},
344
344
345
+ // Ideally, this would be Optional (and not Computed).
346
+ // In past versions (incl. 2.X series) of the provider
347
+ // though, being unset was considered identical to set
348
+ // and the issue_client_certificate value being true.
345
349
"client_certificate_config" : {
346
- Type : schema .TypeList ,
347
- MaxItems : 1 ,
348
- Optional : true ,
349
- DiffSuppressFunc : masterAuthClientCertCfgSuppress ,
350
- ForceNew : true ,
350
+ Type : schema .TypeList ,
351
+ MaxItems : 1 ,
352
+ Optional : true ,
353
+ Computed : true ,
354
+ ForceNew : true ,
351
355
Elem : & schema.Resource {
352
356
Schema : map [string ]* schema.Schema {
353
357
"issue_client_certificate" : {
354
- Type : schema .TypeBool ,
355
- Required : true ,
356
- ForceNew : true ,
357
- DiffSuppressFunc : masterAuthClientCertCfgSuppress ,
358
+ Type : schema .TypeBool ,
359
+ Required : true ,
360
+ ForceNew : true ,
358
361
},
359
362
},
360
363
},
@@ -1660,16 +1663,17 @@ func expandMasterAuth(configured interface{}) *containerBeta.MasterAuth {
1660
1663
Username : masterAuth ["username" ].(string ),
1661
1664
Password : masterAuth ["password" ].(string ),
1662
1665
}
1663
- if _ , ok := masterAuth ["client_certificate_config" ]; ok {
1664
- if len (masterAuth ["client_certificate_config" ].([]interface {})) > 0 {
1666
+
1667
+ if v , ok := masterAuth ["client_certificate_config" ]; ok {
1668
+ if len (v .([]interface {})) > 0 {
1665
1669
clientCertificateConfig := masterAuth ["client_certificate_config" ].([]interface {})[0 ].(map [string ]interface {})
1666
- if _ , ok := clientCertificateConfig ["issue_client_certificate" ]; ok {
1667
- result .ClientCertificateConfig = & containerBeta.ClientCertificateConfig {
1668
- IssueClientCertificate : clientCertificateConfig ["issue_client_certificate" ].(bool ),
1669
- }
1670
+
1671
+ result .ClientCertificateConfig = & containerBeta.ClientCertificateConfig {
1672
+ IssueClientCertificate : clientCertificateConfig ["issue_client_certificate" ].(bool ),
1670
1673
}
1671
1674
}
1672
1675
}
1676
+
1673
1677
return result
1674
1678
}
1675
1679
@@ -1879,11 +1883,18 @@ func flattenMasterAuth(ma *containerBeta.MasterAuth) []map[string]interface{} {
1879
1883
"cluster_ca_certificate" : ma .ClusterCaCertificate ,
1880
1884
},
1881
1885
}
1882
- if len (ma .ClientCertificate ) == 0 {
1883
- masterAuth [0 ]["client_certificate_config" ] = []map [string ]interface {}{
1884
- {"issue_client_certificate" : false },
1885
- }
1886
+
1887
+ // No version of the GKE API returns the client_certificate_config value.
1888
+ // Instead, we need to infer whether or not it was set based on the
1889
+ // client cert being returned from the API or not.
1890
+ // Previous versions of the provider didn't record anything in state when
1891
+ // a client cert was enabled, only setting the block when it was false.
1892
+ masterAuth [0 ]["client_certificate_config" ] = []map [string ]interface {}{
1893
+ {
1894
+ "issue_client_certificate" : len (ma .ClientCertificate ) != 0 ,
1895
+ },
1886
1896
}
1897
+
1887
1898
return masterAuth
1888
1899
}
1889
1900
@@ -1975,30 +1986,6 @@ func cidrOrSizeDiffSuppress(k, old, new string, d *schema.ResourceData) bool {
1975
1986
return strings .HasPrefix (new , "/" ) && strings .HasSuffix (old , new )
1976
1987
}
1977
1988
1978
- // We want to suppress diffs for empty or default client certificate configs, i.e:
1979
- // [{ "issue_client_certificate": true}] --> []
1980
- // [] -> [{ "issue_client_certificate": true}]
1981
- func masterAuthClientCertCfgSuppress (k , old , new string , r * schema.ResourceData ) bool {
1982
- var clientConfig map [string ]interface {}
1983
- if v , ok := r .GetOk ("master_auth" ); ok {
1984
- masterAuths := v .([]interface {})
1985
- masterAuth := masterAuths [0 ].(map [string ]interface {})
1986
- cfgs := masterAuth ["client_certificate_config" ].([]interface {})
1987
- if len (cfgs ) > 0 {
1988
- clientConfig = cfgs [0 ].(map [string ]interface {})
1989
- }
1990
- }
1991
-
1992
- if strings .HasSuffix (k , "client_certificate_config.#" ) && old == "0" && new == "1" {
1993
- // nil --> { "issue_client_certificate": true }
1994
- if issueCert , ok := clientConfig ["issue_client_certificate" ]; ok {
1995
- return issueCert .(bool )
1996
- }
1997
- }
1998
-
1999
- return strings .HasSuffix (k , ".issue_client_certificate" ) && old == "" && new == "true"
2000
- }
2001
-
2002
1989
// We want to suppress diffs for empty/disabled private cluster config.
2003
1990
func containerClusterPrivateClusterConfigSuppress (k , old , new string , d * schema.ResourceData ) bool {
2004
1991
o , n := d .GetChange ("private_cluster_config.0.enable_private_endpoint" )
0 commit comments