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

Terraform provisioner #1836

Closed
ghost opened this issue Oct 6, 2017 · 7 comments
Closed

Terraform provisioner #1836

ghost opened this issue Oct 6, 2017 · 7 comments
Labels
question A question about existing functionality; most questions are re-routed to discuss.hashicorp.com. service/ec2 Issues and PRs that pertain to the ec2 service. windows Issues and PRs that relate to using the provider on the Windows operating system.

Comments

@ghost
Copy link

ghost commented Oct 6, 2017

Hi Experts,
We want to create a .tf file to do the following while creating a new EC2 Windows instance:

  1. Create a new directory "C:\MyFolder"
  2. Copy a Powershell script file (myscript.ps1) from local (current local terraform directory) to the new directory ("C:\MyFolder") on the new EC2 instance.
  3. Execute the Powershell script remotely on the new EC2 instance.

Below is what I have but not working and I'm sure I'm missing something or not correct:

resource "aws_instance" "web" {
   #......

   #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"
          ]
    }
}

Would you please help advise me what's wrong/missing from this code? Thanks so much!!!

@Ninir
Copy link
Contributor

Ninir commented Oct 10, 2017

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?
Is it something you want to do each time or only once?

This will help to provide a better answer :)

Thanks!

@Ninir Ninir added question A question about existing functionality; most questions are re-routed to discuss.hashicorp.com. waiting-response Maintainers are waiting on response from community or contributor. labels Oct 10, 2017
@ghost
Copy link
Author

ghost commented Oct 10, 2017 via email

@ghost
Copy link
Author

ghost commented Oct 10, 2017

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.

@Ninir
Copy link
Contributor

Ninir commented Oct 11, 2017

@tvd2017 Thanks for your feedback.

It seems to me that this is a wrong use of remote-exe and file provisionners`: the user-data stuff would be even more efficient and I would even say that this is what it has been designed for 😄

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!

@Ninir Ninir removed the waiting-response Maintainers are waiting on response from community or contributor. label Oct 11, 2017
@ghost
Copy link
Author

ghost commented Oct 11, 2017

Thanks for your advise, Ninir. I'll try that.

@radeksimko radeksimko added windows Issues and PRs that relate to using the provider on the Windows operating system. service/ec2 Issues and PRs that pertain to the ec2 service. labels Jan 28, 2018
@bflad
Copy link
Contributor

bflad commented Jun 28, 2018

Closing as the GitHub account was deleted.

@bflad bflad closed this as completed Jun 28, 2018
@github-actions
Copy link

github-actions bot commented Jun 2, 2021

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 2, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
question A question about existing functionality; most questions are re-routed to discuss.hashicorp.com. service/ec2 Issues and PRs that pertain to the ec2 service. windows Issues and PRs that relate to using the provider on the Windows operating system.
Projects
None yet
Development

No branches or pull requests

3 participants