-
Notifications
You must be signed in to change notification settings - Fork 9.2k
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
Terraform provisioner #1836
Comments
Hi @tvd2017 I would like to know more about this use-case please :) What is working and what is not, e.g. is the dir creation working? the copy? This will help to provide a better answer :) Thanks! |
Thanks Gauthier for quick response!
(1) We need to create a Windows instance, then (2) once it’s created we need to upload the Powershell script file (MyScript.ps1) from my local computer to this new instance, then (3) run that PS script remotely on the new instance.
Here’s my .tf file –
The instance is created successfully but the provisioner “file” and provisioner “remote-exec” are not working (seems to be hanging during apply). I think the syntax is not correct or I’m missing something here. Since the new folder “MyFolder” doesn’t exist on the new instance, I thought we have to create it first using remote-exec, then use provisioner "file" to upload the file, then use provisioner "remote-exec" to execute the script. I also wonder if the new directory is created automatically by the provisioner "file" if it doesn't exist so we don't have to create it first:
```hcl
resource "aws_instance" "web" {
ami = "ami-06b19063"
instance_type = "t2.micro"
#1. Create new directory:
provisioner "remote-exec" {
connection = {
type = "winrm"
}
inline = [
"cmd mdir C:\\MyFolder"
]
}
#2. Copy Powershell script:
provisioner "file" {
source = "myscript.ps1"
destination = "C:\\MyFolder\\MyScript.ps1"
}
#3. Execute the Powershell script:
provisioner "remote-exec" {
inline = [
"powershell.exe Set-ExecutionPolicy RemoteSigned -force",
"powershell.exe -version 4 -ExecutionPolicy Bypass -File C:\\MyFolder\\MyScript.ps1"
]
}
}
```
|
Under the connection, along with type="winrm" I may need the username and admin pw for it, but the question may be how to get the credentials for the new instance. |
@tvd2017 Thanks for your feedback. It seems to me that this is a wrong use of The user-data is a script that is executed when the machine is created (so not executed when the machine boots / reboots). This would probably be better to handle it there, what do you think? In a more complicated use-case I would have suggested to prepare the AMI using Packer, and then create the instance based on it, but that's our plan B here ;) Tell me how it goes! |
Thanks for your advise, Ninir. I'll try that. |
Closing as the GitHub account was deleted. |
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. |
Hi Experts,
We want to create a .tf file to do the following while creating a new EC2 Windows instance:
Below is what I have but not working and I'm sure I'm missing something or not correct:
Would you please help advise me what's wrong/missing from this code? Thanks so much!!!
The text was updated successfully, but these errors were encountered: