@@ -110,6 +110,8 @@ func (s *Service) InstanceIfExists(id *string) (*infrav1.Instance, error) {
110
110
}
111
111
112
112
// CreateInstance runs an ec2 instance.
113
+ //
114
+ //nolint:gocyclo // this function has multiple processes to perform
113
115
func (s * Service ) CreateInstance (scope * scope.MachineScope , userData []byte , userDataFormat string ) (* infrav1.Instance , error ) {
114
116
s .scope .Debug ("Creating an instance for a machine" )
115
117
@@ -249,6 +251,27 @@ func (s *Service) CreateInstance(scope *scope.MachineScope, userData []byte, use
249
251
}
250
252
}
251
253
254
+ s .scope .Debug ("Adding tags on each network interface from resource" , "resource-id" , out .ID )
255
+
256
+ // Fetching the network interfaces attached to the specific instanace
257
+ networkInterfaces , err := s .getInstanceENIs (out .ID )
258
+ if err != nil {
259
+ return nil , err
260
+ }
261
+
262
+ s .scope .Debug ("Fetched the network interfaces" )
263
+
264
+ // Once all the network interfaces attached to the specific instanace are found, the similar tags of instance are created for network interfaces too
265
+ if len (networkInterfaces ) > 0 {
266
+ s .scope .Debug ("Attempting to create tags from resource" , "resource-id" , out .ID )
267
+ for _ , networkInterface := range networkInterfaces {
268
+ // Create/Update tags in AWS.
269
+ if err := s .UpdateResourceTags (networkInterface .NetworkInterfaceId , out .Tags , nil ); err != nil {
270
+ return nil , errors .Wrapf (err , "failed to create tags for resource %q: " , * networkInterface .NetworkInterfaceId )
271
+ }
272
+ }
273
+ }
274
+
252
275
record .Eventf (scope .AWSMachine , "SuccessfulCreate" , "Created new %s instance with id %q" , scope .Role (), out .ID )
253
276
return out , nil
254
277
}
0 commit comments