Copy file or file content to EC2 without using remote-exec or file provisioner

I am provisioning AWS EC2 instances with terraform scripts and have to copy some files to it. Unfortunately, SSH login is not allowed in EC2’s in that VPC.

So is there any way to copy files from my local to remote EC2?

I found remote-exec and file provisioners, but both required SSH connections to copy files.

so what is the solution?

if you can’t access the instance remotely, you can try to have the instance download the files. A cheap way of doing that is to use a bootstrap script via EC2 user data which would download files from S3. You could also have terraform to create the S3 objects or a zip of them and check the hashes before doing anything with them.

be aware of this caveat tho: https://github.com/hashicorp/terraform-provider-aws/issues/23