@@ -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,12 +1663,15 @@ func expandMasterAuth(configured interface{}) *containerBeta.MasterAuth {
1660
1663
Username : masterAuth ["username" ].(string ),
1661
1664
Password : masterAuth ["password" ].(string ),
1662
1665
}
1666
+
1663
1667
if _ , ok := masterAuth ["client_certificate_config" ]; ok {
1664
1668
if len (masterAuth ["client_certificate_config" ].([]interface {})) > 0 {
1665
1669
clientCertificateConfig := masterAuth ["client_certificate_config" ].([]interface {})[0 ].(map [string ]interface {})
1666
- if _ , ok := clientCertificateConfig ["issue_client_certificate" ]; ok {
1670
+
1671
+ // The value will be in the map whether true or false
1672
+ if v , ok := clientCertificateConfig ["issue_client_certificate" ]; ok {
1667
1673
result .ClientCertificateConfig = & containerBeta.ClientCertificateConfig {
1668
- IssueClientCertificate : clientCertificateConfig [ "issue_client_certificate" ] .(bool ),
1674
+ IssueClientCertificate : v .(bool ),
1669
1675
}
1670
1676
}
1671
1677
}
@@ -1879,11 +1885,18 @@ func flattenMasterAuth(ma *containerBeta.MasterAuth) []map[string]interface{} {
1879
1885
"cluster_ca_certificate" : ma .ClusterCaCertificate ,
1880
1886
},
1881
1887
}
1882
- if len (ma .ClientCertificate ) == 0 {
1883
- masterAuth [0 ]["client_certificate_config" ] = []map [string ]interface {}{
1884
- {"issue_client_certificate" : false },
1885
- }
1888
+
1889
+ // No version of the GKE API returns the client_certificate_config value.
1890
+ // Instead, we need to infer whether or not it was set based on the
1891
+ // client cert being returned from the API or not.
1892
+ // Previous versions of the provider didn't record anything in state when
1893
+ // a client cert was enabled, only setting the block when it was false.
1894
+ masterAuth [0 ]["client_certificate_config" ] = []map [string ]interface {}{
1895
+ {
1896
+ "issue_client_certificate" : len (ma .ClientCertificate ) != 0 ,
1897
+ },
1886
1898
}
1899
+
1887
1900
return masterAuth
1888
1901
}
1889
1902
@@ -1975,30 +1988,6 @@ func cidrOrSizeDiffSuppress(k, old, new string, d *schema.ResourceData) bool {
1975
1988
return strings .HasPrefix (new , "/" ) && strings .HasSuffix (old , new )
1976
1989
}
1977
1990
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
1991
// We want to suppress diffs for empty/disabled private cluster config.
2003
1992
func containerClusterPrivateClusterConfigSuppress (k , old , new string , d * schema.ResourceData ) bool {
2004
1993
o , n := d .GetChange ("private_cluster_config.0.enable_private_endpoint" )
0 commit comments