in pkg/aws/ec2/api/helper.go [277:315]
func (h *ec2APIHelper) AssociateBranchToTrunk(trunkInterfaceId *string, branchInterfaceId *string,
vlanId int,
) (*ec2.AssociateTrunkInterfaceOutput, error) {
// Get attach permission from User's Service Linked Role. Account ID will be added by the EC2 API Wrapper
input := &ec2.CreateNetworkInterfacePermissionInput{
NetworkInterfaceId: branchInterfaceId,
Permission: ec2types.InterfacePermissionType(ec2types.InterfacePermissionTypeInstanceAttach),
}
_, err := h.ec2Wrapper.CreateNetworkInterfacePermission(input)
if err != nil {
return nil, fmt.Errorf("failed to get attach network interface permissions for branch %v", err)
}
vlanId32, err := utils.IntToInt32(vlanId)
if err != nil {
return nil, fmt.Errorf("invalid vlandId: %v", err)
}
associateTrunkInterfaceIP := &ec2.AssociateTrunkInterfaceInput{
BranchInterfaceId: branchInterfaceId,
TrunkInterfaceId: trunkInterfaceId,
VlanId: aws.Int32(vlanId32),
}
associateTrunkInterfaceOutput, err := h.ec2Wrapper.AssociateTrunkInterface(associateTrunkInterfaceIP)
if err != nil {
return associateTrunkInterfaceOutput, err
}
if associateTrunkInterfaceOutput != nil &&
associateTrunkInterfaceOutput.InterfaceAssociation != nil &&
associateTrunkInterfaceOutput.InterfaceAssociation.AssociationId != nil {
return associateTrunkInterfaceOutput, nil
}
return associateTrunkInterfaceOutput, fmt.Errorf("no association id present in the output of request %v",
*associateTrunkInterfaceIP)
}