{"action":"created","issue":{"url":"https://api.github.com/repos/squat/terraform-provider-vultr/issues/4","repository_url":"https://api.github.com/repos/squat/terraform-provider-vultr","labels_url":"https://api.github.com/repos/squat/terraform-provider-vultr/issues/4/labels{/name}","comments_url":"https://api.github.com/repos/squat/terraform-provider-vultr/issues/4/comments","events_url":"https://api.github.com/repos/squat/terraform-provider-vultr/issues/4/events","html_url":"https://github.com/squat/terraform-provider-vultr/issues/4","id":251492126,"number":4,"title":"Initialize Connection Info in Resource Instance","user":{"login":"tk8817","id":849320,"avatar_url":"https://avatars2.githubusercontent.com/u/849320?v=4","gravatar_id":"","url":"https://api.github.com/users/tk8817","html_url":"https://github.com/tk8817","followers_url":"https://api.github.com/users/tk8817/followers","following_url":"https://api.github.com/users/tk8817/following{/other_user}","gists_url":"https://api.github.com/users/tk8817/gists{/gist_id}","starred_url":"https://api.github.com/users/tk8817/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tk8817/subscriptions","organizations_url":"https://api.github.com/users/tk8817/orgs","repos_url":"https://api.github.com/users/tk8817/repos","events_url":"https://api.github.com/users/tk8817/events{/privacy}","received_events_url":"https://api.github.com/users/tk8817/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2017-08-20T14:31:57Z","updated_at":"2017-08-23T00:59:07Z","closed_at":null,"body":"Hey @squat, \r\n\r\nFor other cloud providers I noticed that when you perform `provisioner` blocks on a `resource` , you can get away with very little info in the `connection` block. This is due to the `provider` initializing / defaulting certain fields as part of the `resource_instance.go` code.\r\n\r\nCurrent Example Usage for Vultr:\r\n```\r\n  provisioner \"remote-exec\" {\r\n    inline = [\"cd /tmp\",\"ls -la\"]\r\n    connection {\r\n      host        = \"${self.ipv4_address}\"\r\n      type        = \"ssh\"\r\n      user        = \"root\"\r\n      password    = \"${self.default_password}\"\r\n      private_key = \"${file(\"~/.ssh/jcommu.pem\")}\"\r\n      timeout     = \"2m\"\r\n    }\r\n  }\r\n```\r\n\r\nTo get the above working I needed to specify the `host`, `type`, `user`, `password`, and `private_key`. Based on how Vultr provisions, we should be able to let users of this provider call a `provisioner` block without passing any `connection` info. \r\n\r\nRequested Usage for Vultr:\r\n```\r\n  provisioner \"remote-exec\" {\r\n    inline = [\"cd /tmp\",\"ls -la\"]\r\n  }\r\n```\r\n\r\nHow to make this work?\r\nIn `resource_instance.go` as part of the `resourceInstanceRead ` function, add the following\r\n\r\n```\r\n\t// Initialize the connection info\r\n\td.SetConnInfo(map[string]string{\r\n\t\t\"type\": \"ssh\",\r\n\t\t\"host\": --get IPv4 from read--,\r\n                \"user\": \"root\",\r\n                \"password\": --getDefaultPassword from read--,\r\n\t})\r\n```\r\n\r\nIn this case, a user could provide a `private_key` or `user` as an over-ride if the like, but it will not be required. \r\n"},"comment":{"url":"https://api.github.com/repos/squat/terraform-provider-vultr/issues/comments/324191417","html_url":"https://github.com/squat/terraform-provider-vultr/issues/4#issuecomment-324191417","issue_url":"https://api.github.com/repos/squat/terraform-provider-vultr/issues/4","id":324191417,"user":{"login":"squat","id":20484159,"avatar_url":"https://avatars1.githubusercontent.com/u/20484159?v=4","gravatar_id":"","url":"https://api.github.com/users/squat","html_url":"https://github.com/squat","followers_url":"https://api.github.com/users/squat/followers","following_url":"https://api.github.com/users/squat/following{/other_user}","gists_url":"https://api.github.com/users/squat/gists{/gist_id}","starred_url":"https://api.github.com/users/squat/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/squat/subscriptions","organizations_url":"https://api.github.com/users/squat/orgs","repos_url":"https://api.github.com/users/squat/repos","events_url":"https://api.github.com/users/squat/events{/privacy}","received_events_url":"https://api.github.com/users/squat/received_events","type":"User","site_admin":false},"created_at":"2017-08-23T00:59:07Z","updated_at":"2017-08-23T00:59:07Z","body":"@tk8817, thanks for filing this issue. Provisioning without specifying connection information is indeed broken. We actually already had most of those connection details specified in the instance resource [0], however, I just tested provisioning again with the following config:\r\n```terraform\r\n  provisioner \"remote-exec\" {\r\n    inline = [\"pwd\"]\r\n  }\r\n```\r\nand saw that unless you specify a host, you will get the following error over and over:\r\n```\r\nvultr_instance.example (remote-exec): Connecting to remote host via SSH...\r\nvultr_instance.example (remote-exec):   Host: <nil>\r\nvultr_instance.example (remote-exec):   User: root\r\nvultr_instance.example (remote-exec):   Password: true\r\nvultr_instance.example (remote-exec):   Private key: false\r\nvultr_instance.example (remote-exec):   SSH Agent: true\r\nvultr_instance.example: Still creating... (1m50s elapsed)\r\n```\r\nThis is because the connection details are specified before the instance is ready and the public IP is actually known. The fix is trivial and I'll post it shortly.\r\n[0] https://github.com/squat/terraform-provider-vultr/blob/master/vultr/resource_instance.go#L177"}}
{"actor":{"display_login":"squat"}}