Adding tags to AWS Network Interfaces
@@ -110,6 +110,8 @@ func (s *Service) InstanceIfExists(id *string) (*infrav1.Instance, error) {
}
// CreateInstance runs an ec2 instance.
+//
+//nolint:gocyclo // this function has multiple processes to perform
func (s *Service) CreateInstance(scope *scope.MachineScope, userData []byte, userDataFormat string) (*infrav1.Instance, error) {
s.scope.Debug("Creating an instance for a machine")
@@ -249,6 +251,27 @@ func (s *Service) CreateInstance(scope *scope.MachineScope, userData []byte, use
}
}
+ s.scope.Debug("Adding tags on each network interface from resource", "resource-id", out.ID)
+
+ // Fetching the network interfaces attached to the specific instanace
+ networkInterfaces, err := s.getInstanceENIs(out.ID)
+ if err != nil {
+ return nil, err
+ }
+
+ s.scope.Debug("Fetched the network interfaces")
+
+ // Once all the network interfaces attached to the specific instanace are found, the similar tags of instance are created for network interfaces too
+ if len(networkInterfaces) > 0 {
+ s.scope.Debug("Attempting to create tags from resource", "resource-id", out.ID)
+ for _, networkInterface := range networkInterfaces {
+ // Create/Update tags in AWS.
+ if err := s.UpdateResourceTags(networkInterface.NetworkInterfaceId, out.Tags, nil); err != nil {
+ return nil, errors.Wrapf(err, "failed to create tags for resource %q: ", *networkInterface.NetworkInterfaceId)
+ }
+ }
+ }
+
record.Eventf(scope.AWSMachine, "SuccessfulCreate", "Created new %s instance with id %q", scope.Role(), out.ID)
return out, nil
}
