title: terraform to generate a file, zip and upload to s3
body: <p>I would like to generate a file dynamically, zip it and upload it to s3 using terraform. Below is what I have so far.</p>
  <pre><code>#Setup a local variable with docker container information
  locals {
    file_content = jsonencode({
      &quot;AWSEBDockerrunVersion&quot; : &quot;1&quot;,
      &quot;Image&quot; : {
        &quot;Name&quot; : &quot;${var.aws_account_id}.dkr.ecr.${var.aws_region}.amazonaws.com/vin-${var.application}-api:${var.environment}&quot;,
        &quot;Update&quot; : &quot;true&quot;
      },
      &quot;Ports&quot; : {
        &quot;ContainerPort&quot; : 80,
        &quot;HostPort&quot; : 80
      }
    })
  }
  
  #Generate the Dockerrun.aws.json with the container information and environment tag
  resource &quot;local_file&quot; &quot;docker_container_info&quot; {
    content  = local.file_content
    filename = &quot;./${var.service_name}-${var.environment}-Dockerrun.aws.json&quot;
  }
  
  #Zip the file
  data &quot;archive_file&quot; &quot;source&quot; {
    type        = &quot;zip&quot;
    source_dir  = &quot;./${var.service_name}-${var.environment}-Dockerrun.aws.json&quot;
    output_path = &quot;./${var.service_name}-${var.environment}-Dockerrun.aws.json.zip&quot;
  
    depends_on = [
      local_file.docker_container_info
    ]
  }
  
  /*
  #Upload the zip file to s3 bucket under DockerRunFiles folder
  resource &quot;aws_s3_bucket_object&quot; &quot;file_upload&quot; {
    bucket           = var.run_file_bucket
    key              = &quot;${var.bucket_name}/${var.service_name}-${var.environment}-Dockerrun.aws.json.zip&quot;
    source           = &quot;${data.archive_file.source.output_path}&quot;
  }
  */
  
  
  variable &quot;aws_region&quot; {
    default = &quot;us-east-1&quot;
  }
  
  variable &quot;environment&quot; {
    default = &quot;lab&quot;
  }
  
  variable &quot;aws_environment&quot; {
    default = &quot;lab&quot;
  }
  
  variable &quot;service_name&quot; {
    default = &quot;service_name&quot;
  }
  
  variable &quot;application&quot; {
    default = &quot;application_name&quot;
  }
  
  variable &quot;aws_account_id&quot; {
    default = &quot;1234567890&quot;
  }
  
  variable &quot;bucket_name&quot; {
    default = &quot;my_bucket&quot;
  }
  
  </code></pre>
  <p>I see the <code>service_name-lab-Dockerrun.aws.json</code> file getting generated correctly with json in it. But I am getting the error as <code>Error: error archiving directory: could not archive directory that is a file: ./service_name-lab-Dockerrun.aws.json</code>. Is the terraform <code>data archive_file</code> can only zip a folder and it cannot zip a json file? Appreciate the helps</p>
  <p>Version details:</p>
  <pre><code>Terraform v0.12.28
  + provider.archive v2.0.0
  + provider.local v2.0.0
  </code></pre>