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

provider/aws: unable to bootstrap a spot instance (connection data is not set) #3762

Closed
jwmarshall opened this issue Nov 4, 2015 · 10 comments · Fixed by #3940
Closed

provider/aws: unable to bootstrap a spot instance (connection data is not set) #3762

jwmarshall opened this issue Nov 4, 2015 · 10 comments · Fixed by #3940

Comments

@jwmarshall
Copy link

Maybe I'm missing something silly here, but I cannot seem to bootstrap a spot instance with terraform.

My terraform file:

provider "aws" {
    region = "us-east-1"
}

resource "aws_spot_instance_request" "staging" {
    availability_zone = "us-east-1c"
    instance_type = "m4.xlarge"
    spot_price = "0.25"
    ami = "ami-9eaa1cf6"
    key_name = "chef-client"
    subnet_id = "subnet-*****"
    security_groups = ["sg-*****","sg-*****","sg-*****"]
    wait_for_fulfillment = true
    associate_public_ip_address = true
    ebs_optimized = true
    root_block_device = {
        volume_size = 64
        volume_type = "gp2"
        delete_on_termination = false
    }
    tags {
        Name = "staging"
    }
    provisioner "chef" {
      version = "11.18.6"
      validation_client_name = "chef-validator"
      validation_key_path = "~/.chef/chef-validator.pem"
      secret_key_path = "~/.chef/encrypted_data_bag_secret"
      server_url = "http://chef.*****.com"
      environment = "staging"
      node_name = "*****"
      run_list = ["role[bootstrap_ec2]"]
    }
    connection {
        type = "ssh"
        user = "ubuntu"
        key_file = "~/.ssh/chef-client.pem"
    }
}

The spot instance is requested, fulfilled, but never bootstrapped. Once the instance exists terraform simply displays the following lines over and over until it a timeout is reached.

aws_spot_instance_request.staging (chef): Connecting to remote host via SSH...
aws_spot_instance_request.staging (chef):   Host:
aws_spot_instance_request.staging (chef):   User: ubuntu
aws_spot_instance_request.staging (chef):   Password: false
aws_spot_instance_request.staging (chef):   Private key: true
aws_spot_instance_request.staging (chef):   SSH Agent: true
@svanharmelen
Copy link
Contributor

I don't see a value for the host attribute in the connection logging, so maybe add a reference to the associated public IP in the connection block (probably by using an interpolated value)?

@jwmarshall
Copy link
Author

No luck. The resulting attribute should exist as aws_spot_instance_request bases itself on the aws_instance schema.

Resource 'aws_spot_instance_request.staging' does not have attribute 'private_ip' for variable 'aws_spot_instance_request.staging.private_ip'

According to the docs this should be provided automatically. (https://terraform.io/docs/provisioners/connection.html)

host - The address of the resource to connect to. This is provided by the provider.

@svanharmelen svanharmelen changed the title Chef bootstrap a spot instance provider/aws: unable to bootstrap a spot instance (connection data is not set) Nov 5, 2015
@svanharmelen
Copy link
Contributor

@jwmarshall I just had a look at the code and noticed that the connection data is not set in the spot resource. So I guess (based on the docs) this should be labeled as a bug and needs to be fixed...

@jwmarshall
Copy link
Author

Makes sense. Thanks for your help! If I have some time this weekend and the local development setup isnt too difficult I can look at bringing the relevant lines out of aws_instance.

@jmreicha
Copy link

+1 I just ran in to this as well.

@jwmarshall
Copy link
Author

Yea haven't had anytime to try and tackle this one myself. Maybe I can find a few hours on the weekend.

@catsby
Copy link
Contributor

catsby commented Nov 16, 2015

I have a patch for this, once I get a test confirming I'll open a PR

@jwmarshall
Copy link
Author

👍

@catsby
Copy link
Contributor

catsby commented Nov 16, 2015

Fix is in #3940 , if you can, take it for a spin, otherwise it is under review. I was able to get this to work:

resource "aws_spot_instance_request" "cheap_worker" {
  ami                         = "ami-6f6d635f"
  spot_price                  = "0.04"
  instance_type               = "t1.micro"
  wait_for_fulfillment        = true
  subnet_id                   = "${aws_subnet.tf_test_subnet.id}"
  vpc_security_group_ids      = ["${aws_security_group.tf_test_sg_ssh.id}"]
  key_name                    = "${aws_key_pair.ssh_thing.key_name}"
  associate_public_ip_address = true

  provisioner "remote-exec" {
    connection {
      user     = "ubuntu"
      key_file = "/Users/clint/.ssh/id_rsa2"
      agent    = "false"
    }

    inline = [
      "echo 'hello world'",
    ]
  }
}

Where the subnet and Sg are configured to all SSH

@ghost
Copy link

ghost commented Apr 29, 2020

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.

@ghost ghost locked and limited conversation to collaborators Apr 29, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants