From 84063d2132b5c87caae767d7584255da26906d78 Mon Sep 17 00:00:00 2001 From: Megan Marsh Date: Fri, 13 Dec 2019 11:57:01 -0800 Subject: [PATCH] implement ID and Type values in the provisioner template info sharing --- builder/alicloud/ecs/step_create_instance.go | 3 +++ .../amazon/common/step_run_source_instance.go | 3 +++ .../amazon/common/step_run_spot_instance.go | 3 +++ builder/digitalocean/step_create_droplet.go | 3 +++ builder/docker/step_run.go | 3 +++ builder/googlecompute/step_create_instance.go | 3 +++ builder/hcloud/step_create_server.go | 3 +++ builder/hyperone/step_create_vm.go | 3 +++ builder/hyperv/common/step_clone_vm.go | 3 +++ builder/hyperv/common/step_create_vm.go | 3 +++ builder/jdcloud/step_create_instance.go | 3 +++ builder/linode/step_create_linode.go | 3 +++ .../ncloud/step_create_public_ip_instance.go | 3 +++ builder/ncloud/step_create_server_instance.go | 3 +++ builder/oneandone/step_create_server.go | 3 +++ builder/openstack/step_run_source_server.go | 3 +++ builder/osc/common/step_run_source_vm.go | 3 +++ builder/parallels/common/step_run.go | 3 +++ builder/profitbricks/step_create_server.go | 3 +++ builder/proxmox/step_start_vm.go | 3 +++ builder/scaleway/step_create_server.go | 3 +++ builder/tencentcloud/cvm/step_run_instance.go | 3 +++ builder/triton/step_create_source_machine.go | 3 +++ builder/ucloud/uhost/step_create_instance.go | 3 +++ builder/vagrant/step_up.go | 6 +++++- builder/virtualbox/common/step_run.go | 3 +++ builder/vmware/common/step_run.go | 4 ++++ builder/yandex/step_create_instance.go | 3 +++ common/step_provision.go | 19 ++++++++++++++++--- 29 files changed, 103 insertions(+), 4 deletions(-) diff --git a/builder/alicloud/ecs/step_create_instance.go b/builder/alicloud/ecs/step_create_instance.go index 909720e2d..24d3acf27 100644 --- a/builder/alicloud/ecs/step_create_instance.go +++ b/builder/alicloud/ecs/step_create_instance.go @@ -77,6 +77,9 @@ func (s *stepCreateAlicloudInstance) Run(ctx context.Context, state multistep.St ui.Message(fmt.Sprintf("Created instance: %s", instanceId)) s.instance = &instances.Instances.Instance[0] state.Put("instance", s.instance) + // instance_id is the generic term used so that users can have access to the + // instance id inside of the provisioners, used in step_provision. + state.Put("instance_id", instanceId) return multistep.ActionContinue } diff --git a/builder/amazon/common/step_run_source_instance.go b/builder/amazon/common/step_run_source_instance.go index 0f1941b85..b83db0383 100644 --- a/builder/amazon/common/step_run_source_instance.go +++ b/builder/amazon/common/step_run_source_instance.go @@ -280,6 +280,9 @@ func (s *StepRunSourceInstance) Run(ctx context.Context, state multistep.StateBa } state.Put("instance", instance) + // instance_id is the generic term used so that users can have access to the + // instance id inside of the provisioners, used in step_provision. + state.Put("instance_id", instance.InstanceId) // If we're in a region that doesn't support tagging on instance creation, // do that now. diff --git a/builder/amazon/common/step_run_spot_instance.go b/builder/amazon/common/step_run_spot_instance.go index 06cb28912..d6db5be62 100644 --- a/builder/amazon/common/step_run_spot_instance.go +++ b/builder/amazon/common/step_run_spot_instance.go @@ -441,6 +441,9 @@ func (s *StepRunSpotInstance) Run(ctx context.Context, state multistep.StateBag) } state.Put("instance", instance) + // instance_id is the generic term used so that users can have access to the + // instance id inside of the provisioners, used in step_provision. + state.Put("instance_id", instance.InstanceId) return multistep.ActionContinue } diff --git a/builder/digitalocean/step_create_droplet.go b/builder/digitalocean/step_create_droplet.go index a64325d35..d3a54c955 100644 --- a/builder/digitalocean/step_create_droplet.go +++ b/builder/digitalocean/step_create_droplet.go @@ -63,6 +63,9 @@ func (s *stepCreateDroplet) Run(ctx context.Context, state multistep.StateBag) m // Store the droplet id for later state.Put("droplet_id", droplet.ID) + // instance_id is the generic term used so that users can have access to the + // instance id inside of the provisioners, used in step_provision. + state.Put("instance_id", droplet.ID) return multistep.ActionContinue } diff --git a/builder/docker/step_run.go b/builder/docker/step_run.go index 281505104..bdd8e7dcd 100644 --- a/builder/docker/step_run.go +++ b/builder/docker/step_run.go @@ -42,6 +42,9 @@ func (s *StepRun) Run(ctx context.Context, state multistep.StateBag) multistep.S // Save the container ID s.containerId = containerId state.Put("container_id", s.containerId) + // instance_id is the generic term used so that users can have access to the + // instance id inside of the provisioners, used in step_provision. + state.Put("instance_id", s.containerId) ui.Message(fmt.Sprintf("Container ID: %s", s.containerId)) return multistep.ActionContinue } diff --git a/builder/googlecompute/step_create_instance.go b/builder/googlecompute/step_create_instance.go index ca15eeccb..088c88925 100644 --- a/builder/googlecompute/step_create_instance.go +++ b/builder/googlecompute/step_create_instance.go @@ -176,6 +176,9 @@ func (s *StepCreateInstance) Run(ctx context.Context, state multistep.StateBag) // Things succeeded, store the name so we can remove it later state.Put("instance_name", name) + // instance_id is the generic term used so that users can have access to the + // instance id inside of the provisioners, used in step_provision. + state.Put("instance_id", name) return multistep.ActionContinue } diff --git a/builder/hcloud/step_create_server.go b/builder/hcloud/step_create_server.go index c5c38b9ad..f0d2f863a 100644 --- a/builder/hcloud/step_create_server.go +++ b/builder/hcloud/step_create_server.go @@ -85,6 +85,9 @@ func (s *stepCreateServer) Run(ctx context.Context, state multistep.StateBag) mu // Store the server id for later state.Put("server_id", serverCreateResult.Server.ID) + // instance_id is the generic term used so that users can have access to the + // instance id inside of the provisioners, used in step_provision. + state.Put("instance_id", serverCreateResult.Server.ID) if err := waitForAction(ctx, client, serverCreateResult.Action); err != nil { err := fmt.Errorf("Error creating server: %s", err) diff --git a/builder/hyperone/step_create_vm.go b/builder/hyperone/step_create_vm.go index 155f383a0..58c1dfbc0 100644 --- a/builder/hyperone/step_create_vm.go +++ b/builder/hyperone/step_create_vm.go @@ -67,6 +67,9 @@ func (s *stepCreateVM) Run(ctx context.Context, state multistep.StateBag) multis s.vmID = vm.Id state.Put("vm_id", vm.Id) + // instance_id is the generic term used so that users can have access to the + // instance id inside of the provisioners, used in step_provision. + state.Put("instance_id", vm.Id) hdds, _, err := client.VmApi.VmListHdd(ctx, vm.Id) if err != nil { diff --git a/builder/hyperv/common/step_clone_vm.go b/builder/hyperv/common/step_clone_vm.go index 20d40abfe..5213574e1 100644 --- a/builder/hyperv/common/step_clone_vm.go +++ b/builder/hyperv/common/step_clone_vm.go @@ -154,6 +154,9 @@ func (s *StepCloneVM) Run(ctx context.Context, state multistep.StateBag) multist // Set the final name in the state bag so others can use it state.Put("vmName", s.VMName) + // instance_id is the generic term used so that users can have access to the + // instance id inside of the provisioners, used in step_provision. + state.Put("instance_id", s.VMName) return multistep.ActionContinue } diff --git a/builder/hyperv/common/step_create_vm.go b/builder/hyperv/common/step_create_vm.go index f9a05f797..920edfa45 100644 --- a/builder/hyperv/common/step_create_vm.go +++ b/builder/hyperv/common/step_create_vm.go @@ -166,6 +166,9 @@ func (s *StepCreateVM) Run(ctx context.Context, state multistep.StateBag) multis // Set the final name in the state bag so others can use it state.Put("vmName", s.VMName) + // instance_id is the generic term used so that users can have access to the + // instance id inside of the provisioners, used in step_provision. + state.Put("instance_id", s.VMName) return multistep.ActionContinue } diff --git a/builder/jdcloud/step_create_instance.go b/builder/jdcloud/step_create_instance.go index fe66f464d..930910544 100644 --- a/builder/jdcloud/step_create_instance.go +++ b/builder/jdcloud/step_create_instance.go @@ -96,6 +96,9 @@ func (s *stepCreateJDCloudInstance) Run(_ context.Context, state multistep.State "Hi, we have created the instance, its name=%v , "+ "its id=%v, "+ "and its eip=%v :) ", instance.InstanceName, s.InstanceSpecConfig.InstanceId, eip.Result.ElasticIp.ElasticIpAddress)) + // instance_id is the generic term used so that users can have access to the + // instance id inside of the provisioners, used in step_provision. + state.Put("instance_id", s.InstanceSpecConfig.InstanceId) return multistep.ActionContinue } diff --git a/builder/linode/step_create_linode.go b/builder/linode/step_create_linode.go index ca15facfd..90dc6342a 100644 --- a/builder/linode/step_create_linode.go +++ b/builder/linode/step_create_linode.go @@ -49,6 +49,9 @@ func (s *stepCreateLinode) Run(ctx context.Context, state multistep.StateBag) mu return multistep.ActionHalt } state.Put("instance", instance) + // instance_id is the generic term used so that users can have access to the + // instance id inside of the provisioners, used in step_provision. + state.Put("instance_id", instance.ID) } disk, err := s.findDisk(ctx, instance.ID) diff --git a/builder/ncloud/step_create_public_ip_instance.go b/builder/ncloud/step_create_public_ip_instance.go index 39c31966c..e4550e6ef 100644 --- a/builder/ncloud/step_create_public_ip_instance.go +++ b/builder/ncloud/step_create_public_ip_instance.go @@ -97,6 +97,9 @@ func (s *StepCreatePublicIPInstance) Run(ctx context.Context, state multistep.St if err == nil { state.Put("PublicIP", publicIPInstance.PublicIP) state.Put("PublicIPInstance", publicIPInstance) + // instance_id is the generic term used so that users can have access to the + // instance id inside of the provisioners, used in step_provision. + state.Put("instance_id", publicIPInstance) } return processStepResult(err, s.Error, state) diff --git a/builder/ncloud/step_create_server_instance.go b/builder/ncloud/step_create_server_instance.go index 2a72789f6..49648cbb0 100644 --- a/builder/ncloud/step_create_server_instance.go +++ b/builder/ncloud/step_create_server_instance.go @@ -96,6 +96,9 @@ func (s *StepCreateServerInstance) Run(ctx context.Context, state multistep.Stat serverInstanceNo, err := s.CreateServerInstance(loginKey.KeyName, zoneNo, feeSystemTypeCode) if err == nil { state.Put("InstanceNo", serverInstanceNo) + // instance_id is the generic term used so that users can have access to the + // instance id inside of the provisioners, used in step_provision. + state.Put("instance_id", serverInstanceNo) } return processStepResult(err, s.Error, state) diff --git a/builder/oneandone/step_create_server.go b/builder/oneandone/step_create_server.go index 1fc9863aa..6d70db862 100644 --- a/builder/oneandone/step_create_server.go +++ b/builder/oneandone/step_create_server.go @@ -94,6 +94,9 @@ func (s *stepCreateServer) Run(ctx context.Context, state multistep.StateBag) mu } state.Put("server_id", server_id) + // instance_id is the generic term used so that users can have access to the + // instance id inside of the provisioners, used in step_provision. + state.Put("instance_id", server_id) state.Put("server_ip", server.Ips[0].Ip) diff --git a/builder/openstack/step_run_source_server.go b/builder/openstack/step_run_source_server.go index 3c3bdff1b..59cf63afe 100644 --- a/builder/openstack/step_run_source_server.go +++ b/builder/openstack/step_run_source_server.go @@ -128,6 +128,9 @@ func (s *StepRunSourceServer) Run(ctx context.Context, state multistep.StateBag) s.server = latestServer.(*servers.Server) state.Put("server", s.server) + // instance_id is the generic term used so that users can have access to the + // instance id inside of the provisioners, used in step_provision. + state.Put("instance_id", s.server.ID) return multistep.ActionContinue } diff --git a/builder/osc/common/step_run_source_vm.go b/builder/osc/common/step_run_source_vm.go index 04fe1d5b3..a0f92a6a5 100644 --- a/builder/osc/common/step_run_source_vm.go +++ b/builder/osc/common/step_run_source_vm.go @@ -253,6 +253,9 @@ func (s *StepRunSourceVm) Run(ctx context.Context, state multistep.StateBag) mul } state.Put("vm", vm) + // instance_id is the generic term used so that users can have access to the + // instance id inside of the provisioners, used in step_provision. + state.Put("instance_id", vmId) // If we're in a region that doesn't support tagging on vm creation, // do that now. diff --git a/builder/parallels/common/step_run.go b/builder/parallels/common/step_run.go index d3d60fd1a..062312069 100644 --- a/builder/parallels/common/step_run.go +++ b/builder/parallels/common/step_run.go @@ -36,6 +36,9 @@ func (s *StepRun) Run(ctx context.Context, state multistep.StateBag) multistep.S } s.vmName = vmName + // instance_id is the generic term used so that users can have access to the + // instance id inside of the provisioners, used in step_provision. + state.Put("instance_id", vmName) return multistep.ActionContinue } diff --git a/builder/profitbricks/step_create_server.go b/builder/profitbricks/step_create_server.go index 3d2e44d70..b7320d6d0 100644 --- a/builder/profitbricks/step_create_server.go +++ b/builder/profitbricks/step_create_server.go @@ -147,6 +147,9 @@ func (s *stepCreateServer) Run(ctx context.Context, state multistep.StateBag) mu state.Put("volume_id", server.Entities.Volumes.Items[0].Id) server = profitbricks.GetServer(datacenter.Id, server.Id) + // instance_id is the generic term used so that users can have access to the + // instance id inside of the provisioners, used in step_provision. + state.Put("instance_id", server.Id) state.Put("server_ip", server.Entities.Nics.Items[0].Properties.Ips[0]) diff --git a/builder/proxmox/step_start_vm.go b/builder/proxmox/step_start_vm.go index 8020cf9db..378b689ea 100644 --- a/builder/proxmox/step_start_vm.go +++ b/builder/proxmox/step_start_vm.go @@ -76,6 +76,9 @@ func (s *stepStartVM) Run(ctx context.Context, state multistep.StateBag) multist // Store the vm id for later state.Put("vmRef", vmRef) + // instance_id is the generic term used so that users can have access to the + // instance id inside of the provisioners, used in step_provision. + state.Put("instance_id", vmRef) ui.Say("Starting VM") _, err = client.StartVm(vmRef) diff --git a/builder/scaleway/step_create_server.go b/builder/scaleway/step_create_server.go index 9cfee4207..06a72d95a 100644 --- a/builder/scaleway/step_create_server.go +++ b/builder/scaleway/step_create_server.go @@ -60,6 +60,9 @@ func (s *stepCreateServer) Run(ctx context.Context, state multistep.StateBag) mu s.serverID = server state.Put("server_id", server) + // instance_id is the generic term used so that users can have access to the + // instance id inside of the provisioners, used in step_provision. + state.Put("instance_id", s.serverID) return multistep.ActionContinue } diff --git a/builder/tencentcloud/cvm/step_run_instance.go b/builder/tencentcloud/cvm/step_run_instance.go index b43e1fbf6..72f3f7b90 100644 --- a/builder/tencentcloud/cvm/step_run_instance.go +++ b/builder/tencentcloud/cvm/step_run_instance.go @@ -175,6 +175,9 @@ func (s *stepRunInstance) Run(ctx context.Context, state multistep.StateBag) mul } state.Put("instance", describeResp.Response.InstanceSet[0]) + // instance_id is the generic term used so that users can have access to the + // instance id inside of the provisioners, used in step_provision. + state.Put("instance_id", s.instanceId) Message(state, s.instanceId, "Instance created") return multistep.ActionContinue diff --git a/builder/triton/step_create_source_machine.go b/builder/triton/step_create_source_machine.go index 1aad77508..24080ba23 100644 --- a/builder/triton/step_create_source_machine.go +++ b/builder/triton/step_create_source_machine.go @@ -43,6 +43,9 @@ func (s *StepCreateSourceMachine) Run(ctx context.Context, state multistep.State } state.Put("machine", machineId) + // instance_id is the generic term used so that users can have access to the + // instance id inside of the provisioners, used in step_provision. + state.Put("instance_id", machineId) return multistep.ActionContinue } diff --git a/builder/ucloud/uhost/step_create_instance.go b/builder/ucloud/uhost/step_create_instance.go index 3c60daef8..8ce0836a2 100644 --- a/builder/ucloud/uhost/step_create_instance.go +++ b/builder/ucloud/uhost/step_create_instance.go @@ -77,6 +77,9 @@ func (s *stepCreateInstance) Run(ctx context.Context, state multistep.StateBag) s.instanceId = instanceId state.Put("instance", instance) + // instance_id is the generic term used so that users can have access to the + // instance id inside of the provisioners, used in step_provision. + state.Put("instance_id", instance) if instance.BootDiskState != ucloudcommon.BootDiskStateNormal { ui.Say("Waiting for boot disk of instance initialized") diff --git a/builder/vagrant/step_up.go b/builder/vagrant/step_up.go index 6ca931f3a..e78834f36 100644 --- a/builder/vagrant/step_up.go +++ b/builder/vagrant/step_up.go @@ -35,7 +35,11 @@ func (s *StepUp) Run(ctx context.Context, state multistep.StateBag) multistep.St ui.Say("Calling Vagrant Up (this can take some time)...") - _, _, err := driver.Up(s.generateArgs()) + args := s.generateArgs() + // instance_id is the generic term used so that users can have access to the + // instance id inside of the provisioners, used in step_provision. + state.Put("instance_id", args[0]) + _, _, err := driver.Up(args) if err != nil { state.Put("error", err) diff --git a/builder/virtualbox/common/step_run.go b/builder/virtualbox/common/step_run.go index 46a45d001..8144087b2 100644 --- a/builder/virtualbox/common/step_run.go +++ b/builder/virtualbox/common/step_run.go @@ -57,6 +57,9 @@ func (s *StepRun) Run(ctx context.Context, state multistep.StateBag) multistep.S } s.vmName = vmName + // instance_id is the generic term used so that users can have access to the + // instance id inside of the provisioners, used in step_provision. + state.Put("instance_id", s.vmName) return multistep.ActionContinue } diff --git a/builder/vmware/common/step_run.go b/builder/vmware/common/step_run.go index 5f03ebca5..e9ac27331 100644 --- a/builder/vmware/common/step_run.go +++ b/builder/vmware/common/step_run.go @@ -64,6 +64,10 @@ func (s *StepRun) Run(ctx context.Context, state multistep.StateBag) multistep.S return multistep.ActionHalt } + // instance_id is the generic term used so that users can have access to the + // instance id inside of the provisioners, used in step_provision. + state.Put("instance_id", vmxPath) + return multistep.ActionContinue } diff --git a/builder/yandex/step_create_instance.go b/builder/yandex/step_create_instance.go index 5d7b28f10..b13cbca1e 100644 --- a/builder/yandex/step_create_instance.go +++ b/builder/yandex/step_create_instance.go @@ -249,6 +249,9 @@ runcmd: } state.Put("disk_id", instance.BootDisk.DiskId) + // instance_id is the generic term used so that users can have access to the + // instance id inside of the provisioners, used in step_provision. + state.Put("instance_id", instance.Id) if s.Debug { ui.Message(fmt.Sprintf("Instance ID %s started. Current instance status %s", instance.Id, instance.Status)) diff --git a/common/step_provision.go b/common/step_provision.go index 548150b9e..4c1df2659 100644 --- a/common/step_provision.go +++ b/common/step_provision.go @@ -26,7 +26,7 @@ import ( // accidentally being interpolated into empty strings at prepare time. func PlaceholderData() map[string]string { placeholderData := map[string]string{} - + placeholderData["ID"] = "{{.ID}}" // The following correspond to communicator-agnostic functions that are // part of the SSH and WinRM communicator implementations. These functions // are not part of the communicator interface, but are stored on the @@ -38,6 +38,7 @@ func PlaceholderData() map[string]string { placeholderData["Port"] = "{{.Port}}" placeholderData["User"] = "{{.User}}" placeholderData["Password"] = "{{.Password}}" + placeholderData["ConnType"] = "{{.Type}}" // Backwards-compatability: placeholderData["WinRMPassword"] = "{{.WinRMPassword}}" @@ -60,12 +61,24 @@ func PopulateProvisionHookData(state multistep.StateBag) map[string]interface{} hookData["Port"] = commConf.Port() hookData["User"] = commConf.User() hookData["Password"] = commConf.Password() + hookData["ConnType"] = commConf.Type + // Backwards compatibility; in practice, WinRMPassword is fulfilled by // Password. hookData["WinRMPassword"] = commConf.WinRMPassword - // TODO - // state.GetOK("id") + // instance_id is placed in state by the builders. + // Not yet implemented in Chroot, lxc/lxd, Azure, Qemu. + // Implemented in most others including digitalOcean (droplet id), + // docker (container_id), and clouds which use "server" internally instead + // of instance. + id, ok := state.GetOk("instance_id") + if ok { + hookData["ID"] = id + } else { + // Warn user that the id isn't implemented + hookData["ID"] = "ERR_ID_NOT_IMPLEMENTED_BY_BUILDER" + } return hookData }