diff --git a/pkg/cloud/services/ec2/instances.go b/pkg/cloud/services/ec2/instances.go index d5b510f438..5d5deafa56 100644 --- a/pkg/cloud/services/ec2/instances.go +++ b/pkg/cloud/services/ec2/instances.go @@ -132,11 +132,6 @@ func (s *Service) CreateInstance(scope *scope.MachineScope, userData []byte, use var err error - imageArchitecture, err := s.pickArchitectureForInstanceType(input.Type) - if err != nil { - return nil, err - } - // Pick image from the machine configuration, or use a default one. if scope.AWSMachine.Spec.AMI.ID != nil { //nolint:nestif input.ImageID = *scope.AWSMachine.Spec.AMI.ID @@ -163,6 +158,11 @@ func (s *Service) CreateInstance(scope *scope.MachineScope, userData []byte, use imageLookupBaseOS = scope.InfraCluster.ImageLookupBaseOS() } + imageArchitecture, err := s.pickArchitectureForInstanceType(input.Type) + if err != nil { + return nil, err + } + if scope.IsEKSManaged() && imageLookupFormat == "" && imageLookupOrg == "" && imageLookupBaseOS == "" { input.ImageID, err = s.eksAMILookup(*scope.Machine.Spec.Version, imageArchitecture, scope.AWSMachine.Spec.AMI.EKSOptimizedLookupType) if err != nil {