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

Interrupt remote-exec script on aws_instance creation #7190

Open
dcosson opened this issue Jun 15, 2016 · 2 comments
Open

Interrupt remote-exec script on aws_instance creation #7190

dcosson opened this issue Jun 15, 2016 · 2 comments

Comments

@dcosson
Copy link
Contributor

dcosson commented Jun 15, 2016

Terraform Version

0.6.15

Affected Resource(s)

  • aws_instance

Terraform Configuration Files

Any remote-exec script

When creating an instance with a remote-exec script, sometimes the script hangs and it's obvious that it's not going to work. For example, maybe I forgot -y on an apt-get install. When you hit 'ctrl-c' in terraform, it prints Interrupt received. Gracefully shutting down... but then it will never exit. So, I either have to kill the process by hitting ctrl-c again which means it never syncs to the tfstate file so I have to delete the orphaned ec2 instance(s) manually, or I have to just wait until the timeout.

I think it would be better if terraform would kill the remote-exec script immediately on ctrl-c, and then it could gracefully clean up by adding the tainted ec2 instances to the tfstate file and exit.

@eduardocerqueira
Copy link

I am seeing same behavior when using Openstack as provider. running terraform version: 0.7.2

to reproduce:
Prepare your instance.tf file for Openstack provider, you can use this below and feel free to change image to anything you want same for some others parameters:

resource "openstack_compute_instance_v2" "1_Windows2012R2" {
count = "1"
name = "Windows 2012 R2"
image_name = "win-2012-r2"
flavor_name = "m1.large"
network { name = "public" }
floating_ip = "${openstack_compute_floatingip_v2.1_Windows2012R2_ip.address}"
key_pair = "dev"
security_groups = ["default"]

connection {
user = "Admin"
host = "${openstack_compute_floatingip_v2.1_Windows2012R2_ip.address}"
private_key = "/home/ecerquei/.ssh/id_rsa"
timeout = "10m"
}

provisioner "remote-exec" {
inline = [
"dir"
]
}
}
resource "openstack_compute_floatingip_v2" "1_Windows2012R2_ip" {
region = ""
pool = "10.10.127.0/22"
}

Provision the system resource(s):
$terraform apply

then wait 5 seconds (just to get time enough to start provisioning) then click CTRL+C

you will see the rest of log as below with the message as mentioned at title of this issue

network.0.port: "" => ""
network.0.uuid: "" => ""
security_groups.#: "" => "1"
security_groups.3814588639: "" => "default"
stop_before_destroy: "" => "false"
^CInterrupt received. Gracefully shutting down...
openstack_compute_instance_v2.1_Windows2012R2: Still creating... (10s elapsed)

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

I hope it helps!

@thanasik
Copy link

Experiencing this with Azure VMs as well, it slows down our workflow since the timeouts are lengthy and having to manually destroy the resources on Azure is tedious.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants