title: How do I get a list of s3 objects with the aws_s3_bucket_object data source?
body: <p>My specific problem is the same as <a href="https://stackoverflow.com/questions/44741459/elastic-beanstalk-application-version-in-terraform">this guys</a>, but I found his answer not detailed enough, also terraform has new features now that maybe can solve this better.</p>
  
  <p>The problem is I'm using aws_elastic_beanstalk_application_version to register beanstalk version, but terraform removes the old version before registering the new one. This is because aws_elastic_beanstalk_application_version is replaced each time, what I need to do is generate a new one.</p>
  
  <p>I'm attempting to do this with "count" and the aws_s3_bucket_object data source but I can't figure out how to get s3 objects as a list. I tried wildcards but that doesn't work:</p>
  
  <pre><code>data "aws_s3_bucket_object" "eb-bucket-data" {
    bucket = "mybucket"
    key = "*"
  }
  
  resource "aws_elastic_beanstalk_application_version" "default" {
    count       = "${length(data.aws_s3_bucket_object.eb-bucket-data.id)}"
    name        = "${element(data.aws_s3_bucket_object.eb-bucket-data.key, count.index)}"
    application = "myapp"
    bucket      = "mybucket"
    key        = "${element(data.aws_s3_bucket_object.eb-bucket-data.key, count.index)}"
  }
  </code></pre>