This message was deleted.
# aws
s
This message was deleted.
m
Hi, What I recently did was to create a command resource and wait cloud-init to be finished:
Copy code
installDocker, err := remote.NewCommand(ctx, "install-docker", &remote.CommandArgs{
			Connection: &remote.ConnectionArgs{
				Host:       instance.Ipv4Address,
				PrivateKey: readFileOrPanic("~/.ssh/id_rsa"),
				User:       pulumi.String("root"),
			},
			Create: pulumi.String("cloud-init status --wait && sleep 30s"),
		})
		if err != nil {
			return err
		}
And then I have a
pulumi.DependsOn([]pulumi.Resource{installDocker})
in the next resource.
p
That sounds really interesting, will give it a try. Thanks!
f
I'd tackle this problem using https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cfn-signal.html Not really a fan of Cloudformation 🙂 But you could create a mini-Cloudformation template that waits until the script on ec2 signals to proceed. Pros: no ssh key, works with instances that don't have public IPs.
m
@fierce-ability-58936, thats nice! My snippet is not from AWS (actually DO) and I had to come up with an "vanilla" solution.
👍 1
p
@fierce-ability-58936 hmm the thing with public IP is something I didn't consider. I plan to spin up the instance in a private subnet... Good tip 👍
👍 1
In the end, I achieved it a bit differently. I used a local command calling the AWS CLI to wait for the status checks:
Copy code
wait_for_instance_command = command.local.Command(
        "wait-for-instance-command",
        create=pulumi.Output.format(
            "aws ec2 wait instance-status-ok --instance-ids {instance_id}",
            instance_id=run_instance_command.stdout,
        ),
        triggers=[run_instance_command.stdout],
        opts=pulumi.ResourceOptions(depends_on=[run_instance_command]),
    )
For a bit more context. I realized that I don't even want the EC2 instance managed by Pulumi because the only resource I care about is the created AMI. So I start the EC2 instance also with local command (the
run_instance_command
) and get the instance ID from the command output. Then I wait to the instance to come up and report successful status check. The
ec2.AmiFromInstance
specifies the wait command as an explicit dependency. The final local command in the chain is the
terminate_instance_command
which terminates the ephemeral instance.
👍 1