Skip to content

Commit d728c78

Browse files
committed
Adding tags to AWS Network Interfaces
1 parent 9488cb5 commit d728c78

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

pkg/cloud/services/ec2/instances.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ func (s *Service) InstanceIfExists(id *string) (*infrav1.Instance, error) {
110110
}
111111

112112
// CreateInstance runs an ec2 instance.
113+
//
114+
//nolint:gocyclo // this function has multiple processes to perform
113115
func (s *Service) CreateInstance(scope *scope.MachineScope, userData []byte, userDataFormat string) (*infrav1.Instance, error) {
114116
s.scope.Debug("Creating an instance for a machine")
115117

@@ -249,6 +251,27 @@ func (s *Service) CreateInstance(scope *scope.MachineScope, userData []byte, use
249251
}
250252
}
251253

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+
252275
record.Eventf(scope.AWSMachine, "SuccessfulCreate", "Created new %s instance with id %q", scope.Role(), out.ID)
253276
return out, nil
254277
}

0 commit comments

Comments
 (0)