Skip to content
This repository has been archived by the owner on Jul 30, 2020. It is now read-only.

remote-exec ssh host not populated #98

Closed
hadleyrich opened this issue Aug 7, 2019 · 6 comments
Closed

remote-exec ssh host not populated #98

hadleyrich opened this issue Aug 7, 2019 · 6 comments
Assignees
Labels
question Further information is requested

Comments

@hadleyrich
Copy link

When adding a remote-exec to a config it's acutally executed on the localhost as the host field is not populated:

resource "vultr_server" "this" {
  label       = var.server_name
  plan_id     = "${data.vultr_plan.starter.id}"
  os_id       = "${data.vultr_os.ubuntu-1904.id}"
  region_id   = "${data.vultr_region.sydney.id}"
  ssh_key_ids = var.ssh_key_ids
  provisioner "remote-exec" {
    inline     = [
      "apt update",
      "apt -y dist-upgrade",
    ]
  }
}

Some output:

module.vultr_server_testypants2.vultr_server.this: Still creating... [1m30s elapsed]
module.vultr_server_testypants1.vultr_server.this: Still creating... [1m30s elapsed]
module.vultr_server_testypants2.vultr_server.this: Provisioning with 'remote-exec'...
module.vultr_server_testypants2.vultr_server.this (remote-exec): Connecting to remote host via SSH...
module.vultr_server_testypants2.vultr_server.this (remote-exec):   Host:
module.vultr_server_testypants2.vultr_server.this (remote-exec):   User: root
module.vultr_server_testypants2.vultr_server.this (remote-exec):   Password: false
module.vultr_server_testypants2.vultr_server.this (remote-exec):   Private key: false
module.vultr_server_testypants2.vultr_server.this (remote-exec):   Certificate: false
module.vultr_server_testypants2.vultr_server.this (remote-exec):   SSH Agent: true
module.vultr_server_testypants2.vultr_server.this (remote-exec):   Checking Host Key: false
module.vultr_server_testypants2.vultr_server.this (remote-exec): Connected!
module.vultr_server_testypants2.vultr_server.this (remote-exec): 
module.vultr_server_testypants2.vultr_server.this (remote-exec): 0% [Working]

The reason it shows connected there is because I can SSH to my localhost.

@hadleyrich hadleyrich added the bug Something isn't working label Aug 7, 2019
@OJFord
Copy link

OJFord commented Aug 7, 2019

I agree that it would be better if default connection.host = self.main_ip (since Terraform docs say 'This is usually specified by the provider.'), but you can specify this yourself:

resource "vultr_server" "this" {
  # ...
  connection {
    host = self.main_ip
    agent = true
  }
}

That an empty host connects to localhost if sshd running there is 'interesting' terraform core behaviour, IMO.

@ddymko
Copy link
Contributor

ddymko commented Aug 7, 2019

@hadleyrich

You will need to define a connection block within your provisioner

  provisioner "remote-exec" {
    inline     = [
      "apt update",
      "apt -y dist-upgrade",
    ]

    connection {
        type     = "ssh"
        host     = "${vultr_server.this.main_ip}"
        user     = "root"
        password = "${vultr_server.this.default_password}"

   }
  }

@hadleyrich
Copy link
Author

Thanks for the replies guys. I guess not a bug then, I had assumed that the provider would specify it.

@OJFord
Copy link

OJFord commented Aug 7, 2019

@hadleyrich It should do/usually does, per core docs. I suppose it's not a bug, but IMO would be good to add to the provider @ddymko.

@hadleyrich
Copy link
Author

@OJFord Agreed, I've not come across it before and it would be a nice to have. Perhaps a feature request or included in documentation, rather than a bug.

@ddymko
Copy link
Contributor

ddymko commented Aug 8, 2019

@OJFord This isn't a bug since this is not a mandatory feature required by Terraform and there is a way to define your connection information. Also not all providers do this there are some cloud providers who do and some who don't.

@OJFord @hadleyrich I created a new enhancement ticket #100 that addresses this topic. It will set the connection information for regular instances and baremetal. This will remove the headache of having to set the connection blocks.

@ddymko ddymko added question Further information is requested and removed bug Something isn't working labels Aug 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants