5

How does one instruct Pulumi to execute one or more commands on a remote host?

The equivalent Terraform command is remote-exec.

Gili
  • 86,244
  • 97
  • 390
  • 689

2 Answers2

5

Pulumi currently doesn't support remote-exec-like provisioners but they are on the roadmap (see https://github.com/pulumi/pulumi/issues/1691).

For now, I'd recommend using the cloud-init userdata functionality of the various providers as in this AWS EC2 example.

Cameron
  • 431
  • 3
  • 3
  • Is it possible to execute a script after the instance is already up? The `userdata` script cannot reference properties of the `server` variable because the latter depends on the former. – Gili Aug 28 '19 at 19:08
  • 1
    Not currently, no. That would require the roadmap item I mentioned (provisioners). Though depending on what you're trying to do, this may still be done using userdata. Amazon's metadata service exposes instance properties to scripts/apps running on the instance - so you could potentially use values from that in your scripts. See https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-metadata.html for more info. – Cameron Aug 28 '19 at 20:48
  • It's now possible with https://www.pulumi.com/registry/packages/command – Can Rau Jun 02 '22 at 06:45
3

Pulumi supports this with the Command package as of 2021-12-31: https://github.com/pulumi/pulumi/issues/99#issuecomment-1003445058

Reilly Wood
  • 1,753
  • 2
  • 12
  • 17