forked from hashicorp/packer-plugin-tencentcloud
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstep_pre_validate.go
More file actions
43 lines (31 loc) · 1.04 KB
/
step_pre_validate.go
File metadata and controls
43 lines (31 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package cvm
import (
"context"
"fmt"
"github.com/hashicorp/packer-plugin-sdk/multistep"
cvm "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm/v20170312"
)
type stepPreValidate struct {
SkipCreateImage bool
}
func (s *stepPreValidate) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
// No need to validate the image name if we're not creating an image
if s.SkipCreateImage {
return multistep.ActionContinue
}
config := state.Get("config").(*Config)
client := state.Get("cvm_client").(*cvm.Client)
Say(state, config.ImageName, "Trying to check image name")
image, err := GetImageByName(ctx, client, config.ImageName)
if err != nil {
return Halt(state, err, "Failed to get images info")
}
if image != nil {
return Halt(state, fmt.Errorf("Image name %s has exists", config.ImageName), "")
}
Message(state, "useable", "Image name")
return multistep.ActionContinue
}
func (s *stepPreValidate) Cleanup(multistep.StateBag) {}