Skip to content
Open
Show file tree
Hide file tree
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
5 changes: 3 additions & 2 deletions builder/tencentcloud/cvm/run_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,9 @@ func (cf *TencentCloudRunConfig) Prepare(ctx *interpolate.Context) []error {
packerId := fmt.Sprintf("packer_%s", uuid.TimeOrderedUUID()[:8])
if cf.Comm.SSHKeyPairName == "" && cf.Comm.SSHTemporaryKeyPairName == "" &&
cf.Comm.SSHPrivateKeyFile == "" && cf.Comm.SSHPassword == "" && cf.Comm.WinRMPassword == "" {
//tencentcloud support key pair name length max to 25
cf.Comm.SSHTemporaryKeyPairName = packerId
// Key pair names must be unique so we can't use packerId here, instead we set a
// dummy value now and a unique name later
cf.Comm.SSHTemporaryKeyPairName = "dummy value"
}

errs := cf.Comm.Prepare(ctx)
Expand Down
9 changes: 9 additions & 0 deletions builder/tencentcloud/cvm/step_config_key_pair.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

"github.com/hashicorp/packer-plugin-sdk/communicator"
"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 All @@ -22,6 +23,12 @@ type stepConfigKeyPair struct {
keyID string
}

func CreateKeyPairName() string {
uuid := uuid.TimeOrderedUUID()

return fmt.Sprintf("packer_%s_%s", uuid[:8], uuid[9:13])
}

func (s *stepConfigKeyPair) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
client := state.Get("cvm_client").(*cvm.Client)

Expand Down Expand Up @@ -51,6 +58,8 @@ func (s *stepConfigKeyPair) Run(ctx context.Context, state multistep.StateBag) m
return multistep.ActionContinue
}

// Set a unique value for each key pair name
s.Comm.SSHTemporaryKeyPairName = CreateKeyPairName()
Say(state, s.Comm.SSHTemporaryKeyPairName, "Trying to create a new keypair")

req := cvm.NewCreateKeyPairRequest()
Expand Down