I need to upload the file (.zip and .exe) and execute PowerShell commands on the ec2 instances while building it using terraform.
I have a base image (server 2012) where I am making all the changes using terraform. All instances are connected to the internal AWS network.
I tried " data “template_file” "userdata " it is only working with sysprep AMI and not working with the normal AMI which is not built using sysprep.
Also, all the instances are not exposed to the internet hence, I cannot use terraform remote_exec or other solutions which require internet. I can’t expose them.
I tried many solutions but nothing working. Currently i am running commands on sysprep instance as shown below:
data "template_file" "userdata" {
template = "<powershell>${file("setup.ps1")}</powershell><persist>false</persist>"
}
In the script, I am running PSSession commands to make changes to the instances.
Problem:
-
How to upload files using terraform?
-
How to run commands on the non-sysprep images.