diff --git a/google/resource_container_cluster.go b/google/resource_container_cluster.go index 6ae3682bae6..eeb8c39a615 100644 --- a/google/resource_container_cluster.go +++ b/google/resource_container_cluster.go @@ -342,19 +342,22 @@ func resourceContainerCluster() *schema.Resource { Optional: true, }, + // Ideally, this would be Optional (and not Computed). + // In past versions (incl. 2.X series) of the provider + // though, being unset was considered identical to set + // and the issue_client_certificate value being true. "client_certificate_config": { - Type: schema.TypeList, - MaxItems: 1, - Optional: true, - DiffSuppressFunc: masterAuthClientCertCfgSuppress, - ForceNew: true, + Type: schema.TypeList, + MaxItems: 1, + Optional: true, + Computed: true, + ForceNew: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "issue_client_certificate": { - Type: schema.TypeBool, - Required: true, - ForceNew: true, - DiffSuppressFunc: masterAuthClientCertCfgSuppress, + Type: schema.TypeBool, + Required: true, + ForceNew: true, }, }, }, @@ -1660,16 +1663,17 @@ func expandMasterAuth(configured interface{}) *containerBeta.MasterAuth { Username: masterAuth["username"].(string), Password: masterAuth["password"].(string), } - if _, ok := masterAuth["client_certificate_config"]; ok { - if len(masterAuth["client_certificate_config"].([]interface{})) > 0 { + + if v, ok := masterAuth["client_certificate_config"]; ok { + if len(v.([]interface{})) > 0 { clientCertificateConfig := masterAuth["client_certificate_config"].([]interface{})[0].(map[string]interface{}) - if _, ok := clientCertificateConfig["issue_client_certificate"]; ok { - result.ClientCertificateConfig = &containerBeta.ClientCertificateConfig{ - IssueClientCertificate: clientCertificateConfig["issue_client_certificate"].(bool), - } + + result.ClientCertificateConfig = &containerBeta.ClientCertificateConfig{ + IssueClientCertificate: clientCertificateConfig["issue_client_certificate"].(bool), } } } + return result } @@ -1879,11 +1883,18 @@ func flattenMasterAuth(ma *containerBeta.MasterAuth) []map[string]interface{} { "cluster_ca_certificate": ma.ClusterCaCertificate, }, } - if len(ma.ClientCertificate) == 0 { - masterAuth[0]["client_certificate_config"] = []map[string]interface{}{ - {"issue_client_certificate": false}, - } + + // No version of the GKE API returns the client_certificate_config value. + // Instead, we need to infer whether or not it was set based on the + // client cert being returned from the API or not. + // Previous versions of the provider didn't record anything in state when + // a client cert was enabled, only setting the block when it was false. + masterAuth[0]["client_certificate_config"] = []map[string]interface{}{ + { + "issue_client_certificate": len(ma.ClientCertificate) != 0, + }, } + return masterAuth } @@ -1975,30 +1986,6 @@ func cidrOrSizeDiffSuppress(k, old, new string, d *schema.ResourceData) bool { return strings.HasPrefix(new, "/") && strings.HasSuffix(old, new) } -// We want to suppress diffs for empty or default client certificate configs, i.e: -// [{ "issue_client_certificate": true}] --> [] -// [] -> [{ "issue_client_certificate": true}] -func masterAuthClientCertCfgSuppress(k, old, new string, r *schema.ResourceData) bool { - var clientConfig map[string]interface{} - if v, ok := r.GetOk("master_auth"); ok { - masterAuths := v.([]interface{}) - masterAuth := masterAuths[0].(map[string]interface{}) - cfgs := masterAuth["client_certificate_config"].([]interface{}) - if len(cfgs) > 0 { - clientConfig = cfgs[0].(map[string]interface{}) - } - } - - if strings.HasSuffix(k, "client_certificate_config.#") && old == "0" && new == "1" { - // nil --> { "issue_client_certificate": true } - if issueCert, ok := clientConfig["issue_client_certificate"]; ok { - return issueCert.(bool) - } - } - - return strings.HasSuffix(k, ".issue_client_certificate") && old == "" && new == "true" -} - // We want to suppress diffs for empty/disabled private cluster config. func containerClusterPrivateClusterConfigSuppress(k, old, new string, d *schema.ResourceData) bool { o, n := d.GetChange("private_cluster_config.0.enable_private_endpoint") diff --git a/website/docs/getting_started.html.markdown b/website/docs/getting_started.html.markdown index fea66ac4c20..6bfe5b6be85 100644 --- a/website/docs/getting_started.html.markdown +++ b/website/docs/getting_started.html.markdown @@ -81,7 +81,7 @@ resource "google_compute_instance" "vm_instance" { network_interface { # A default network is created for all GCP projects network = "default" - access_config = { + access_config { } } } @@ -135,7 +135,7 @@ network_interface { - # A default network is created for all GCP projects - network = "default" + network = "${google_compute_network.vpc_network.self_link}" - access_config = { + access_config { ``` This means that when we create the VM instance, it will use @@ -190,7 +190,7 @@ resource "google_compute_instance" "vm_instance" { network_interface { # A default network is created for all GCP projects network = "${google_compute_network.vpc_network.self_link}" - access_config = { + access_config { } } }