rebase && some fixes
This commit is contained in:
parent
1c08463204
commit
9fabad6f1d
|
@ -7,6 +7,7 @@ import (
|
|||
"fmt"
|
||||
"os"
|
||||
"regexp"
|
||||
"time"
|
||||
|
||||
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
|
||||
"github.com/hashicorp/packer/packer-plugin-sdk/template/interpolate"
|
||||
|
@ -25,6 +26,9 @@ type CommonConfig struct {
|
|||
|
||||
// File path to save serial port output of the launched instance.
|
||||
SerialLogFile string `mapstructure:"serial_log_file" required:"false"`
|
||||
// The time to wait for instance state changes.
|
||||
// Defaults to `5m`.
|
||||
StateTimeout time.Duration `mapstructure:"state_timeout" required:"false"`
|
||||
|
||||
InstanceConfig `mapstructure:",squash"`
|
||||
DiskConfig `mapstructure:",squash"`
|
||||
|
@ -41,6 +45,10 @@ func (c *CommonConfig) Prepare(errs *packersdk.MultiError) *packersdk.MultiError
|
|||
}
|
||||
}
|
||||
|
||||
if c.StateTimeout == 0 {
|
||||
c.StateTimeout = 5 * time.Minute
|
||||
}
|
||||
|
||||
errs = c.CloudConfig.Prepare(errs)
|
||||
errs = c.InstanceConfig.Prepare(errs)
|
||||
errs = c.DiskConfig.Prepare(errs)
|
||||
|
|
|
@ -6,7 +6,6 @@ package yandex
|
|||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/packer/packer-plugin-sdk/common"
|
||||
"github.com/hashicorp/packer/packer-plugin-sdk/communicator"
|
||||
|
@ -42,9 +41,6 @@ type Config struct {
|
|||
TargetImageFolderID string `mapstructure:"target_image_folder_id" required:"false"`
|
||||
|
||||
ctx interpolate.Context
|
||||
// The time to wait for instance state changes.
|
||||
// Defaults to `5m`.
|
||||
StateTimeout time.Duration `mapstructure:"state_timeout" required:"false"`
|
||||
}
|
||||
|
||||
func (c *Config) Prepare(raws ...interface{}) ([]string, error) {
|
||||
|
@ -99,10 +95,6 @@ func (c *Config) Prepare(raws ...interface{}) ([]string, error) {
|
|||
c.TargetImageFolderID = c.FolderID
|
||||
}
|
||||
|
||||
if c.StateTimeout == 0 {
|
||||
c.StateTimeout = 5 * time.Minute
|
||||
}
|
||||
|
||||
// Check for any errors.
|
||||
if errs != nil && len(errs.Errors) > 0 {
|
||||
return nil, errs
|
||||
|
|
|
@ -71,6 +71,7 @@ type FlatConfig struct {
|
|||
Token *string `mapstructure:"token" required:"true" cty:"token" hcl:"token"`
|
||||
MaxRetries *int `mapstructure:"max_retries" cty:"max_retries" hcl:"max_retries"`
|
||||
SerialLogFile *string `mapstructure:"serial_log_file" required:"false" cty:"serial_log_file" hcl:"serial_log_file"`
|
||||
StateTimeout *string `mapstructure:"state_timeout" required:"false" cty:"state_timeout" hcl:"state_timeout"`
|
||||
InstanceCores *int `mapstructure:"instance_cores" required:"false" cty:"instance_cores" hcl:"instance_cores"`
|
||||
InstanceGpus *int `mapstructure:"instance_gpus" required:"false" cty:"instance_gpus" hcl:"instance_gpus"`
|
||||
InstanceMemory *int `mapstructure:"instance_mem_gb" required:"false" cty:"instance_mem_gb" hcl:"instance_mem_gb"`
|
||||
|
@ -102,7 +103,6 @@ type FlatConfig struct {
|
|||
SourceImageID *string `mapstructure:"source_image_id" required:"false" cty:"source_image_id" hcl:"source_image_id"`
|
||||
SourceImageName *string `mapstructure:"source_image_name" cty:"source_image_name" hcl:"source_image_name"`
|
||||
TargetImageFolderID *string `mapstructure:"target_image_folder_id" required:"false" cty:"target_image_folder_id" hcl:"target_image_folder_id"`
|
||||
StateTimeout *string `mapstructure:"state_timeout" required:"false" cty:"state_timeout" hcl:"state_timeout"`
|
||||
}
|
||||
|
||||
// FlatMapstructure returns a new FlatConfig.
|
||||
|
@ -179,6 +179,7 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec {
|
|||
"token": &hcldec.AttrSpec{Name: "token", Type: cty.String, Required: false},
|
||||
"max_retries": &hcldec.AttrSpec{Name: "max_retries", Type: cty.Number, Required: false},
|
||||
"serial_log_file": &hcldec.AttrSpec{Name: "serial_log_file", Type: cty.String, Required: false},
|
||||
"state_timeout": &hcldec.AttrSpec{Name: "state_timeout", Type: cty.String, Required: false},
|
||||
"instance_cores": &hcldec.AttrSpec{Name: "instance_cores", Type: cty.Number, Required: false},
|
||||
"instance_gpus": &hcldec.AttrSpec{Name: "instance_gpus", Type: cty.Number, Required: false},
|
||||
"instance_mem_gb": &hcldec.AttrSpec{Name: "instance_mem_gb", Type: cty.Number, Required: false},
|
||||
|
@ -210,7 +211,6 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec {
|
|||
"source_image_id": &hcldec.AttrSpec{Name: "source_image_id", Type: cty.String, Required: false},
|
||||
"source_image_name": &hcldec.AttrSpec{Name: "source_image_name", Type: cty.String, Required: false},
|
||||
"target_image_folder_id": &hcldec.AttrSpec{Name: "target_image_folder_id", Type: cty.String, Required: false},
|
||||
"state_timeout": &hcldec.AttrSpec{Name: "state_timeout", Type: cty.String, Required: false},
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
|
|
@ -9,11 +9,11 @@ import (
|
|||
"fmt"
|
||||
"log"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/hcl/v2/hcldec"
|
||||
"github.com/hashicorp/packer/builder/yandex"
|
||||
"github.com/hashicorp/packer/packer-plugin-sdk/common"
|
||||
"github.com/hashicorp/packer/packer-plugin-sdk/communicator"
|
||||
"github.com/hashicorp/packer/packer-plugin-sdk/multistep"
|
||||
"github.com/hashicorp/packer/packer-plugin-sdk/multistep/commonsteps"
|
||||
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
|
||||
|
@ -105,7 +105,7 @@ func (p *PostProcessor) Configure(raws ...interface{}) error {
|
|||
// through the internal network - we need access
|
||||
// to the global Internet: either through ipv4 or ipv6
|
||||
// TODO: delete this when access appears
|
||||
if p.config.UseIPv4Nat && p.config.UseIPv6 == false {
|
||||
if p.config.UseIPv4Nat == false && p.config.UseIPv6 == false {
|
||||
p.config.UseIPv4Nat = true
|
||||
}
|
||||
p.config.Preemptible = true //? safety
|
||||
|
@ -198,9 +198,18 @@ func (p *PostProcessor) PostProcess(ctx context.Context, ui packersdk.Ui, artifa
|
|||
"zone": p.config.Zone,
|
||||
},
|
||||
)
|
||||
if yandexConfig.InstanceConfig.InstanceName == "" {
|
||||
yandexConfig.InstanceConfig.InstanceName = exporterName
|
||||
}
|
||||
if yandexConfig.DiskName == "" {
|
||||
yandexConfig.DiskName = exporterName
|
||||
}
|
||||
|
||||
errs := yandexConfig.Communicator.Prepare(interpolate.NewContext())
|
||||
if len(errs) > 0 {
|
||||
err := &packersdk.MultiError{Errors: errs}
|
||||
return nil, false, false, err
|
||||
}
|
||||
ui.Say(fmt.Sprintf("Validating service_account_id: '%s'...", yandexConfig.ServiceAccountID))
|
||||
if err := validateServiceAccount(ctx, driver.SDK(), yandexConfig.ServiceAccountID); err != nil {
|
||||
return nil, false, false, err
|
||||
|
@ -250,10 +259,15 @@ func ycSaneDefaults(c *Config, md map[string]string) yandex.Config {
|
|||
yandexConfig := yandex.Config{
|
||||
CommonConfig: c.CommonConfig,
|
||||
AccessConfig: c.AccessConfig,
|
||||
Communicator: communicator.Config{
|
||||
Type: "ssh",
|
||||
SSH: communicator.SSH{
|
||||
SSHUsername: "ubuntu",
|
||||
},
|
||||
},
|
||||
}
|
||||
if c.SSHPrivateKeyFile != "" {
|
||||
yandexConfig.Communicator.SSH.SSHPrivateKeyFile = c.SSHPrivateKeyFile
|
||||
yandexConfig.Communicator.SSH.SSHUsername = "ubuntu"
|
||||
}
|
||||
if yandexConfig.Metadata == nil {
|
||||
yandexConfig.Metadata = md
|
||||
|
@ -265,7 +279,6 @@ func ycSaneDefaults(c *Config, md map[string]string) yandex.Config {
|
|||
|
||||
yandexConfig.SourceImageFamily = "ubuntu-1604-lts"
|
||||
yandexConfig.SourceImageFolderID = yandex.StandardImagesFolderID
|
||||
yandexConfig.StateTimeout = 3 * time.Minute
|
||||
|
||||
yandexConfig.ServiceAccountID = c.ServiceAccountID
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@ type FlatConfig struct {
|
|||
Token *string `mapstructure:"token" required:"true" cty:"token" hcl:"token"`
|
||||
MaxRetries *int `mapstructure:"max_retries" cty:"max_retries" hcl:"max_retries"`
|
||||
SerialLogFile *string `mapstructure:"serial_log_file" required:"false" cty:"serial_log_file" hcl:"serial_log_file"`
|
||||
StateTimeout *string `mapstructure:"state_timeout" required:"false" cty:"state_timeout" hcl:"state_timeout"`
|
||||
InstanceCores *int `mapstructure:"instance_cores" required:"false" cty:"instance_cores" hcl:"instance_cores"`
|
||||
InstanceGpus *int `mapstructure:"instance_gpus" required:"false" cty:"instance_gpus" hcl:"instance_gpus"`
|
||||
InstanceMemory *int `mapstructure:"instance_mem_gb" required:"false" cty:"instance_mem_gb" hcl:"instance_mem_gb"`
|
||||
|
@ -71,6 +72,7 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec {
|
|||
"token": &hcldec.AttrSpec{Name: "token", Type: cty.String, Required: false},
|
||||
"max_retries": &hcldec.AttrSpec{Name: "max_retries", Type: cty.Number, Required: false},
|
||||
"serial_log_file": &hcldec.AttrSpec{Name: "serial_log_file", Type: cty.String, Required: false},
|
||||
"state_timeout": &hcldec.AttrSpec{Name: "state_timeout", Type: cty.String, Required: false},
|
||||
"instance_cores": &hcldec.AttrSpec{Name: "instance_cores", Type: cty.Number, Required: false},
|
||||
"instance_gpus": &hcldec.AttrSpec{Name: "instance_gpus", Type: cty.Number, Required: false},
|
||||
"instance_mem_gb": &hcldec.AttrSpec{Name: "instance_mem_gb", Type: cty.Number, Required: false},
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
<!-- Code generated from the comments of the CommonConfig struct in builder/yandex/common_config.go; DO NOT EDIT MANUALLY -->
|
||||
|
||||
- `serial_log_file` (string) - File path to save serial port output of the launched instance.
|
||||
|
||||
- `state_timeout` (duration string | ex: "1h5m2s") - The time to wait for instance state changes.
|
||||
Defaults to `5m`.
|
||||
|
|
|
@ -11,6 +11,3 @@
|
|||
|
||||
- `target_image_folder_id` (string) - The ID of the folder to save built image in.
|
||||
This defaults to value of 'folder_id'.
|
||||
|
||||
- `state_timeout` (duration string | ex: "1h5m2s") - The time to wait for instance state changes.
|
||||
Defaults to `5m`.
|
||||
|
|
Loading…
Reference in New Issue