diff --git a/builder/bsu/builder.go b/builder/bsu/builder.go index 45c8d07e..878b4a66 100644 --- a/builder/bsu/builder.go +++ b/builder/bsu/builder.go @@ -102,6 +102,7 @@ func (b *Builder) Run( state.Put("ui", ui) steps := []multistep.Step{ + &osccommon.StepCheckAuth{}, &osccommon.StepPreValidate{ DestOmiName: b.config.OMIName, ForceDeregister: b.config.OMIForceDeregister, diff --git a/builder/bsusurrogate/builder.go b/builder/bsusurrogate/builder.go index f6625896..aac0c8f8 100644 --- a/builder/bsusurrogate/builder.go +++ b/builder/bsusurrogate/builder.go @@ -133,6 +133,7 @@ func (b *Builder) Run( launchOSCDevices := b.config.BuildOSCLaunchDevices() steps := []multistep.Step{ + &osccommon.StepCheckAuth{}, &osccommon.StepPreValidate{ DestOmiName: b.config.OMIName, ForceDeregister: b.config.OMIForceDeregister, diff --git a/builder/bsuvolume/builder.go b/builder/bsuvolume/builder.go index 1d616dae..a381f060 100644 --- a/builder/bsuvolume/builder.go +++ b/builder/bsuvolume/builder.go @@ -137,6 +137,7 @@ func (b *Builder) Run( // Build the steps steps := []multistep.Step{ + &osccommon.StepCheckAuth{}, &osccommon.StepSourceOMIInfo{ SourceOmi: b.config.SourceOmi, OmiFilters: b.config.SourceOmiFilter, diff --git a/builder/chroot/builder.go b/builder/chroot/builder.go index 89e67a0d..67ea475a 100644 --- a/builder/chroot/builder.go +++ b/builder/chroot/builder.go @@ -215,6 +215,7 @@ func (b *Builder) Run( // Build the steps steps := []multistep.Step{ + &osccommon.StepCheckAuth{}, &osccommon.StepPreValidate{ DestOmiName: b.config.OMIName, ForceDeregister: b.config.OMIForceDeregister, diff --git a/builder/common/step_check_auth.go b/builder/common/step_check_auth.go new file mode 100644 index 00000000..2a447802 --- /dev/null +++ b/builder/common/step_check_auth.go @@ -0,0 +1,33 @@ +package common + +import ( + "context" + "errors" + + "github.com/hashicorp/packer-plugin-sdk/multistep" + packersdk "github.com/hashicorp/packer-plugin-sdk/packer" + "github.com/outscale/goutils/sdk/auth" +) + +// StepCheckAuth validates that the authentication is valid +type StepCheckAuth struct{} + +var checkCredentials = auth.CheckCredentials + +func (s *StepCheckAuth) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction { + ui := state.Get("ui").(packersdk.Ui) + conn := state.Get("osc").(*OscClient) + + ui.Say("Validating configured credentials") + + err := checkCredentials(ctx, conn) + if err != nil { + state.Put("error", errors.New("OUTSCALE API authentication failed; verify your credentials and region configuration")) + ui.Error(err.Error()) + return multistep.ActionHalt + } + + return multistep.ActionContinue +} + +func (s *StepCheckAuth) Cleanup(multistep.StateBag) {} diff --git a/datasource/omi/data_acc_test.go b/datasource/omi/data_acc_test.go index a0ffe770..b754d355 100644 --- a/datasource/omi/data_acc_test.go +++ b/datasource/omi/data_acc_test.go @@ -20,7 +20,7 @@ func TestAccDatasource_OutscaleOmi(t *testing.T) { const testBuilderAccBasicDataSource = ` data "outscale-omi" "test" { filters = { - image-name = "RockyLinux-8-*" + image-name = "RockyLinux-10-*" root-device-type = "ebs" virtualization-type = "hvm" } diff --git a/go.mod b/go.mod index 2ac579f5..5daa0909 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/hashicorp/hcl/v2 v2.24.0 github.com/hashicorp/packer-plugin-sdk v0.6.8 github.com/mitchellh/mapstructure v1.5.0 - github.com/outscale/goutils/sdk v0.0.3 + github.com/outscale/goutils/sdk v0.0.5 github.com/outscale/osc-sdk-go/v3 v3.0.0-rc.2 github.com/zclconf/go-cty v1.18.1 golang.org/x/sys v0.45.0 diff --git a/go.sum b/go.sum index fb7ed918..75749cff 100644 --- a/go.sum +++ b/go.sum @@ -362,8 +362,8 @@ github.com/nywilken/go-cty v1.13.3 h1:03U99oXf3j3g9xgqAE3YGpixCjM8Mg09KZ0Ji9LzX0 github.com/nywilken/go-cty v1.13.3/go.mod h1:YKQzy/7pZ7iq2jNFzy5go57xdxdWoLLpaEp4u238AE0= github.com/oapi-codegen/runtime v1.3.1 h1:RgDY6J4OGQLbRXhG/Xpt3vSVqYpHQS7hN4m85+5xB9g= github.com/oapi-codegen/runtime v1.3.1/go.mod h1:kOdeacKy7t40Rclb1je37ZLFboFxh+YLy0zaPCMibPY= -github.com/outscale/goutils/sdk v0.0.3 h1:LnMuNUhQW8YgKDFH9vHTtstND3igHDbHDHPsaFsKFZ0= -github.com/outscale/goutils/sdk v0.0.3/go.mod h1:2Ae3lIQmdOC+n/VnOABrzS+kpjq/Hm0PJQhABpiFW8M= +github.com/outscale/goutils/sdk v0.0.5 h1:UVu7uC38VOSCPqeCORsw1rKWaoHrsv+TTp6TGUHenjo= +github.com/outscale/goutils/sdk v0.0.5/go.mod h1:LiXmAIA3CAXCdanEARKQ3Q/Lb8n8dKeGSbPRxIe43kc= github.com/outscale/osc-sdk-go/v3 v3.0.0-rc.2 h1:uj8s4jaqqzq2hFqQVAB6PTVwuPm43e5Ti/ZFQqvCAB0= github.com/outscale/osc-sdk-go/v3 v3.0.0-rc.2/go.mod h1:Yi0j2XAZ0/8g0ObVFofMSL5+IuNIDp/AiEI6gXc7txc= github.com/packer-community/winrmcp v0.0.0-20221126162354-6e900dd2c68f h1:sWm3fnjG6kxvDuGiQf46Io5xCTj3QJfNJIeICJ4g1kw= diff --git a/internal/testacc/check.go b/internal/testacc/check.go index ef0a361c..2e3ab3dd 100644 --- a/internal/testacc/check.go +++ b/internal/testacc/check.go @@ -2,7 +2,6 @@ package testacc import ( "fmt" - "os" "os/exec" ) @@ -11,10 +10,5 @@ func CheckWithLogs(buildCommand *exec.Cmd, logfile string) error { return nil } - logs, err := os.ReadFile(logfile) //nolint:gosec - if err != nil { - return fmt.Errorf("bad exit code. logfile: %s (failed to read logs: %w)", logfile, err) - } - - return fmt.Errorf("bad exit code. logfile: %s\n%s", logfile, string(logs)) + return fmt.Errorf("bad exit code. logfile: %s", logfile) }