title: How do you create a TLS connection to a Cloud SQL database using Go?
body: <p>I'm trying to create a TLS connection to a Cloud SQL database but I'm getting the following error when trying to prepare a statement:</p>
  
  <pre><code>x509: cannot validate certificate for &lt;cloud sql instance ip&gt;
        because it doesn't contain any IP SANs
  </code></pre>
  
  <p>Here is my setup code:</p>
  
  <blockquote>
  <pre><code>rootCertPool := x509.NewCertPool()
  
  pem, err := ioutil.ReadFile("/path/server-ca.pem")
  if err != nil {
      log.Fatal(err)
  }
  
  if ok := rootCertPool.AppendCertsFromPEM(pem); !ok {
      log.Fatal("Failed to append PEM.")
  }
  
  clientCert := make([]tls.Certificate, 0, 1)
  certs, err := tls.LoadX509KeyPair("/path/client-cert.pem",
                                    "/path/client-key.pem")
  if err != nil {
      log.Fatal(err)
  }
  
  clientCert = append(clientCert, certs)
  mysql.RegisterTLSConfig("custom", &amp;tls.Config{
      RootCAs: rootCertPool,
      Certificates: clientCert,
  })
  
  db, err := sql.Open("mysql",
          "&lt;user&gt;:&lt;password&gt;@tcp(&lt;cloud sql ip&gt;:3306)/&lt;db_name&gt;?tls=custom")
  </code></pre>
  </blockquote>