I can't seem to find a documentation that will help me download a zip file from aws s3 to an instance using terraform, can someone help me find a solution to this ?
Thank you.
I can't seem to find a documentation that will help me download a zip file from aws s3 to an instance using terraform, can someone help me find a solution to this ?
Thank you.
There are various ways to download file from S3 depending on your needs.
remote-exec
provisioner. This one isMIME
agnostic.null_resource
with proper trigger.file
andaws_s3_bucket_object
data resource.It will work perfectly with text files.
http
provider as well.user_data_scripts
fromcloud-init
. There are set of problems and similar threads on the Internet. (AWS Developers Forum; an example of authenticated downloading with Cloudformation)Remember to give an instance an IAM role with proper permissions, if you execute command from the instance, or give proper permissions to role, that executes
Terraform
.Note: Said that, I doubt
Terraform
is best choice for instance provisioning. Take a look at SaltStack, Ansible or Chef. These are the tools designed to work with instance provisioning.Your question is not clear.
Assuming this you do not need the file in Terraform, then I would suggest to write a cloud-init script for the file download. Use Terraform to configure all IAM permissions, and to write the script into the instance's user-data. Then at boot time the server runs cloud-init and will download the file, either with
curl
/wget
(from public URLs) or withaws s3
(authenticated via instance profile).It's not clear but I think you're asking how to download a file to an instance you've created with terraform?
That should be done via a user_data script or by configuration management software on your instance's image. There is no resource in terraform that will do this