Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

provider/AWS: Add new resource for creating objects in an S3 bucket #2079

Closed

Conversation

m-s-austin
Copy link
Contributor

This code adds a new resource that allows you to "preload" a bucket with objects. Usage is as follows:

here is a working example of the format.

resource "aws_s3_bucket" "b" {
    bucket = "ijoin_fork_terraform_distro"
    acl = "private"
    tags {
        Name = "My bucket"
        Environment = "Dev"
    }
    force_destroy = true
}

resource "aws_s3_bucket_object" "darwin" {
    depends_on = "aws_s3_bucket.b"       # Optional??
    bucket = "ijoin_fork_terraform_distro"
    key = "darwin_amd64.zip"
    source = "./darwin_amd64.1.zip"
}


resource "aws_s3_bucket_object" "linux" {
    depends_on = "aws_s3_bucket.b"
    bucket = "ijoin_fork_terraform_distro"
    key = "linux_amd64.zip"
    source = "./linux_amd64.1.zip"
}

Acceptance test is also working now :)

@m-s-austin m-s-austin changed the title added new provider for creating objects in an s3 bucket Provider/AWS: added new provider for creating objects in an s3 bucket May 27, 2015
@catsby
Copy link
Contributor

catsby commented Jun 1, 2015

depends_on = "aws_s3_bucket.b"       # Optional??
bucket = "ijoin_fork_terraform_distro"

You can likely remove the depends_on if you reference ijoin_fork_terraform_distro directly:

resource "aws_s3_bucket_object" "darwin" {
  bucket = "${aws_s3_bucket.b.id}"
  key = "darwin_amd64.zip"
  source = "./darwin_amd64.1.zip"
}

@radeksimko radeksimko changed the title Provider/AWS: added new provider for creating objects in an s3 bucket provider/AWS: Added new resource for creating objects in an S3 bucket Jun 1, 2015
@radeksimko radeksimko changed the title provider/AWS: Added new resource for creating objects in an S3 bucket provider/AWS: Add new resource for creating objects in an S3 bucket Jun 1, 2015
@m-s-austin
Copy link
Contributor Author

m-s-austin commented Jun 2, 2015 via email

@catsby
Copy link
Contributor

catsby commented Jun 30, 2015

Hey @m-s-austin is this something you're still working on? Following up to see if you are, or need someone to try and take up the reins. Thanks!

@catsby catsby added the waiting-response An issue/pull request is waiting for a response from the community label Jun 30, 2015
@tyro89
Copy link

tyro89 commented Jul 8, 2015

@catsby @m-s-austin I'm very interested in having this feature. Let me know if you need any help in getting it ready.

@m-s-austin
Copy link
Contributor Author

@catsby sorry I have been slammed. we are just using it in our fork as it is. It's been working great!

@m-s-austin
Copy link
Contributor Author

and also to verify

resource "aws_s3_bucket_object" "darwin" {
  bucket = "${aws_s3_bucket.b.id}"
  key = "darwin_amd64.zip"
  source = "./darwin_amd64.1.zip"
}

that format does work and removes needing the depends_on

@phinze
Copy link
Contributor

phinze commented Jul 29, 2015

I see code, acceptance test, and docs - looks like maybe this is good to go?

What do you think, @catsby?

return fmt.Errorf("Error putting object in S3 bucket (%s): %s", bucket, err)
}

d.SetId(*resp.ETag)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm hesitant on using the ETag here, simply because the API mentions that if a user supplies their own key to encrypt the file(s), the ETag will not be the md5... it doesn't clearly say what it will be in that case though. I worry that down the road we expand on this and then get into a situation where we're losing objects :/

Can we simply use key here, instead?

@catsby
Copy link
Contributor

catsby commented Jul 29, 2015

Thanks again for the contribution. I had some more questions, but otherwise this works out.

It does need to be rebased on master and some changes made, notably

  • aws instead of awslabs
  • awsutil.StringValue is now longer around; aws structs now implement Stringer(), so you can just use log.Printf("[DEBUG] Result %s", resp) or similar
  • The test still has the depends_on which isn't necessary if you do the interpolation like I mentioned above (nitpick)

@catsby
Copy link
Contributor

catsby commented Jul 29, 2015

All those things said, this is probably good enough, so that if you don't get to these things in the next day or so I'll just push my own branch based on this and do them myself. Thanks!

@catsby
Copy link
Contributor

catsby commented Jul 30, 2015

Closing in favor of #2898, thanks for the contribution @m-s-austin !

@catsby catsby closed this Jul 30, 2015
catsby added a commit that referenced this pull request Aug 5, 2015
provider/aws: Add S3 Bucket Object (supercedes #2079)
@pawan19
Copy link

pawan19 commented Aug 12, 2019

I found the examples to upload objects by making ZIP but can we upload multiple files to S3 without Zip? If yes can you give me some example??
Here is my code:

resource "aws_s3_bucket" "testbucket" {
bucket = "test-terraform-1"
acl = "private"

tags = {
    Name  = "test-terraform"
    Environment = "test"
}

}

resource "aws_s3_bucket_object" "uploadfile" {
bucket = "test-terraform-1"
key = "index.html"
source = "/home/pawan/Documents/Projects/"

}

my files are inside project folders.

Thanks.

@ghost ghost removed the waiting-response An issue/pull request is waiting for a response from the community label Aug 12, 2019
@ghost
Copy link

ghost commented Aug 13, 2019

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Aug 13, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants