From 9bf85b22ab1ba7971375a3863410675684d4252a Mon Sep 17 00:00:00 2001 From: Julian Sommer <115516918+juliansommer@users.noreply.github.com> Date: Fri, 3 Jul 2026 09:55:11 +1000 Subject: [PATCH] chore: remove KeyName requirement --- spinifex/gateway/ec2/instance/RunInstances.go | 4 ---- .../gateway/ec2/instance/RunInstances_test.go | 20 ++++++------------- .../ec2/spotinstance/RequestSpotInstances.go | 4 ---- .../spotinstance/RequestSpotInstances_test.go | 16 +++++++-------- 4 files changed, 14 insertions(+), 30 deletions(-) diff --git a/spinifex/gateway/ec2/instance/RunInstances.go b/spinifex/gateway/ec2/instance/RunInstances.go index 0bd1fa06e..6714bd014 100644 --- a/spinifex/gateway/ec2/instance/RunInstances.go +++ b/spinifex/gateway/ec2/instance/RunInstances.go @@ -60,10 +60,6 @@ func ValidateRunInstancesInput(input *ec2.RunInstancesInput) (err error) { return errors.New(awserrors.ErrorMissingParameter) } - if input.KeyName == nil || *input.KeyName == "" { - return errors.New(awserrors.ErrorMissingParameter) - } - if !strings.HasPrefix(*input.ImageId, "ami-") { return errors.New(awserrors.ErrorInvalidAMIIDMalformed) } diff --git a/spinifex/gateway/ec2/instance/RunInstances_test.go b/spinifex/gateway/ec2/instance/RunInstances_test.go index 5379e058c..d9fd3a72b 100644 --- a/spinifex/gateway/ec2/instance/RunInstances_test.go +++ b/spinifex/gateway/ec2/instance/RunInstances_test.go @@ -191,22 +191,14 @@ func TestParseRunInstances(t *testing.T) { }, want: errors.New(awserrors.ErrorMissingParameter), }, - - { - name: "MissingKeyName", - input: &ec2.RunInstancesInput{ - ImageId: defaults.ImageId, - InstanceType: defaults.InstanceType, - MinCount: aws.Int64(1), - MaxCount: aws.Int64(1), - KeyName: nil, - SecurityGroupIds: defaults.SecurityGroupIds, - SubnetId: defaults.SubnetId, - }, - want: errors.New(awserrors.ErrorMissingParameter), - }, } + t.Run("MissingKeyNameIsValid", func(t *testing.T) { + input := defaults + input.KeyName = nil + assert.NoError(t, ValidateRunInstancesInput(&input)) + }) + for _, test := range tests { t.Run(test.name, func(t *testing.T) { // For validation tests, we can pass nil conn since validation happens before NATS call diff --git a/spinifex/gateway/ec2/spotinstance/RequestSpotInstances.go b/spinifex/gateway/ec2/spotinstance/RequestSpotInstances.go index 5087b5a6a..ff5f97ec0 100644 --- a/spinifex/gateway/ec2/spotinstance/RequestSpotInstances.go +++ b/spinifex/gateway/ec2/spotinstance/RequestSpotInstances.go @@ -44,10 +44,6 @@ func ValidateRequestSpotInstancesInput(input *ec2.RequestSpotInstancesInput) err if aws.StringValue(spec.InstanceType) == "" { return errors.New(awserrors.ErrorMissingParameter) } - if aws.StringValue(spec.KeyName) == "" { - return errors.New(awserrors.ErrorMissingParameter) - } - if input.InstanceCount != nil && *input.InstanceCount < 1 { return errors.New(awserrors.ErrorInvalidParameterValue) } diff --git a/spinifex/gateway/ec2/spotinstance/RequestSpotInstances_test.go b/spinifex/gateway/ec2/spotinstance/RequestSpotInstances_test.go index 8cab59e6c..afb0465fb 100644 --- a/spinifex/gateway/ec2/spotinstance/RequestSpotInstances_test.go +++ b/spinifex/gateway/ec2/spotinstance/RequestSpotInstances_test.go @@ -69,14 +69,6 @@ func TestValidateRequestSpotInstancesInput(t *testing.T) { }}, want: errors.New(awserrors.ErrorMissingParameter), }, - { - name: "MissingKeyName", - input: &ec2.RequestSpotInstancesInput{LaunchSpecification: &ec2.RequestSpotLaunchSpecification{ - ImageId: aws.String("ami-0abcdef1234567890"), - InstanceType: aws.String("t2.micro"), - }}, - want: errors.New(awserrors.ErrorMissingParameter), - }, { name: "InstanceCountZero", input: &ec2.RequestSpotInstancesInput{ @@ -101,6 +93,14 @@ func TestValidateRequestSpotInstancesInput(t *testing.T) { }, want: errors.New(awserrors.ErrorInvalidParameterValue), }, + { + name: "MissingKeyNameIsValid", + input: &ec2.RequestSpotInstancesInput{LaunchSpecification: &ec2.RequestSpotLaunchSpecification{ + ImageId: aws.String("ami-0abcdef1234567890"), + InstanceType: aws.String("t2.micro"), + }}, + want: nil, + }, { name: "PersistentTypeAccepted", input: &ec2.RequestSpotInstancesInput{