title: Dumping Terraform output to a local file
body: <p>I want to create a file (<code>credentials.json</code>) within a directory, say <code>content</code> using Terraform.</p>
  
  <p>The contents will be the output of a private service account key.</p>
  
  <p>I am using the following code to create the service account and get its key to <code>data</code>:</p>
  
  <pre><code>resource "google_service_account" "my-account" {
    account_id = "${var.account_id}"
    project    = "${var.project_id}"
  }
  
  resource "google_service_account_key" "my-account" {
    service_account_id = "${google_service_account.my-account.name}"
  }
  
  data "google_service_account_key" "my-account" {
    name            = "${google_service_account_key.cd.name}"
    public_key_type = "TYPE_X509_PEM_FILE"
  }
  </code></pre>
  
  <p>How can I then dump it to a local file?</p>
  
  <p>My use case is that I want to create the <code>credentials.json</code> to enable periodic <a href="https://github.com/helm/charts/tree/master/stable/jenkins#backup" rel="nofollow noreferrer">backups</a> of <code>jenkins</code> to a google cloud storage bucket.</p>