title: Terraform REST API calls with cURL
body: <p>What is the best way to make REST API calls from Terraform?  I'm currently using a <code>null_resource</code> with the <code>local-exec</code> provisioner to make a cURL call:</p>
  
  <pre><code>resource "null_resource" "cloudability-setup" {
    provisioner "local-exec" {
        command = &lt;&lt;EOT
          curl -s -X POST https://api.cloudability.com/v3/vendors/aws/accounts \
               -H 'Content-Type: application/json' \
               -u "$${CldAbltyAPIToken:?Missing Cloudability API Token Env Variable}:" \
               -d '{"vendorAccountId": "${data.aws_caller_identity.current.account_id}", "type": "aws_role" }'
  EOT
    }
  </code></pre>
  
  <p>However, the cURL return code is successful for HTTP 200 and HTTP 400 responses.  I'd like the resource to be marked as failed if the new account cannot be registered.</p>
  
  <p>I've tried returning just the HTTP Response Code:</p>
  
  <pre><code>resource "null_resource" "cloudability-setup" {
    provisioner "local-exec" {
        command = &lt;&lt;EOT
          curl -s -o /dev/null -w "%{http_code}" \
               -X POST https://api.cloudability.com/v3/vendors/aws/accounts \
               -H 'Content-Type: application/json' \
               -u "$${CldAbltyAPIToken:?Missing Cloudability API Token Env Variable}:" \
               -d '{"vendorAccountId": "${data.aws_caller_identity.current.account_id}", "type": "aws_role" }'
  EOT
    }
  </code></pre>
  
  <p>But then I lose the API response body, which contains valuable information.  There are also times when a HTTP 400 code indicates the account already exists, which I consider a success from the overall setup standpoint.</p>