From 1007d91ed7cc83c69b74ed34c67753d23719f2c7 Mon Sep 17 00:00:00 2001 From: Michael Shen Date: Thu, 30 Nov 2023 09:21:18 -0500 Subject: [PATCH] UPSTREAM: 4670: Update awsmachine providerID and instanceID immediately after ec2:RunInstances is called This mitigates issues caused by falling back to tag-based searching for EC2 instances in case future AWS calls fail, such as attaching ENIs to security groups or tagging ENIs. Signed-off-by: Michael Shen --- pkg/cloud/services/ec2/instances.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkg/cloud/services/ec2/instances.go b/pkg/cloud/services/ec2/instances.go index 8a656c521c..d40111df3e 100644 --- a/pkg/cloud/services/ec2/instances.go +++ b/pkg/cloud/services/ec2/instances.go @@ -240,6 +240,10 @@ func (s *Service) CreateInstance(scope *scope.MachineScope, userData []byte, use return nil, err } + // Set the providerID and instanceID as soon as we create an instance so that we keep it in case of errors afterward + scope.SetProviderID(out.ID, out.AvailabilityZone) + scope.SetInstanceID(out.ID) + if len(input.NetworkInterfaces) > 0 { for _, id := range input.NetworkInterfaces { s.scope.Debug("Attaching security groups to provided network interface", "groups", input.SecurityGroupIDs, "interface", id)