title: cloud-sql-proxy for GCP Dataproc fails, nc: connect to localhost port 3306 (tcp) failed: Connection refused
body: <p>I am using Terraform to create a dataproc cluster that uses a GCP cloudsql instance as the hivemetastore, the terrafrm project creates the cluster and all its prerequisites (network, service account, cloudsql instance &amp; user, etc).<br>
  <a href="https://github.com/GoogleCloudPlatform/dataproc-initialization-actions/tree/master/cloud-sql-proxy" rel="nofollow noreferrer"><code>cloud-sql-proxy.sh</code></a> is provided to assist with this however I can't get it to work, when the cluster is created <code>cloud-sql-proxy.sh</code> fails with error:</p>
  
  <blockquote>
    <p>nc: connect to localhost port 3306 (tcp) failed: Connection refused</p>
  </blockquote>
  
  <p>I've banged my head against the wall trying to figure out why but can't get to the bottom of it so am hoping someone here can help. </p>
  
  <p>I've hosted the terraform project at <a href="https://github.com/jamiekt/democratising-dataproc" rel="nofollow noreferrer">https://github.com/jamiekt/democratising-dataproc</a>. Reproducing the problem is very easy, follow these steps:</p>
  
  <ol>
  <li><a href="https://learn.hashicorp.com/terraform/getting-started/install" rel="nofollow noreferrer">Install terraform</a> if you haven't already</li>
  <li>Install <code>gcloud</code> if you haven't already</li>
  <li>Create a new GCP project  </li>
  <li>Enable the <a href="https://console.developers.google.com/apis/library/dataproc.googleapis.com" rel="nofollow noreferrer">Cloud Dataproc API</a> for your new project</li>
  <li><code>gcloud auth application-default login #creates a file containing credentials that terraform will use</code></li>
  <li><code>git clone git@github.com:jamiekt/democratising-dataproc.git &amp;&amp; cd democratising-dataproc</code></li>
  <li><code>export GCP_PROJECT=name-of-project-you-just-created</code></li>
  <li><code>make init</code></li>
  <li><code>make apply</code></li>
  </ol>
  
  <p>That should successfully spin up a network, subnetwork, cloudsql instance, a couple of storage buckets (one of them containing cloud-sql-proxy.sh), a service account, a firewall then fail when attempting to create the dataproc cluster.</p>
  
  <p>if anyone could take a look and tell me why this is failing I'd be very grateful.</p>