Skip to content

Fix multisource clienttoken #13

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

Merged
merged 2 commits into from
Apr 24, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions builder/tencentcloud/cvm/step_run_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"log"

"github.com/hashicorp/packer-plugin-sdk/multistep"
"github.com/hashicorp/packer-plugin-sdk/uuid"
cvm "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm/v20170312"
)

Expand Down Expand Up @@ -125,7 +126,11 @@ func (s *stepRunInstance) Run(ctx context.Context, state multistep.StateBag) mul
req.InternetAccessible.BandwidthPackageId = &s.BandwidthPackageId
}
}
req.InstanceName = &s.InstanceName

// Generate a unique ClientToken for each RunInstances request
clientToken := uuid.TimeOrderedUUID()
req.ClientToken = &clientToken

loginSettings := cvm.LoginSettings{}
if password != "" {
loginSettings.Password = &password
Expand All @@ -135,7 +140,7 @@ func (s *stepRunInstance) Run(ctx context.Context, state multistep.StateBag) mul
}
req.LoginSettings = &loginSettings
req.SecurityGroupIds = []*string{&security_group_id}
req.ClientToken = &s.InstanceName
req.InstanceName = &s.InstanceName
req.HostName = &s.HostName
req.UserData = &userData
req.CamRoleName = &s.CamRoleName
Expand Down Expand Up @@ -173,7 +178,7 @@ func (s *stepRunInstance) Run(ctx context.Context, state multistep.StateBag) mul
}

s.instanceId = *resp.Response.InstanceIdSet[0]
Message(state, "Waiting for instance ready", "")
Message(state, fmt.Sprintf("Instance %s created, waiting for instance ready", s.instanceId), "")

err = WaitForInstance(ctx, client, s.instanceId, "RUNNING", 1800)
if err != nil {
Expand Down
Loading