feat: fully functioning ALB
This commit is contained in:
@@ -94,6 +94,40 @@ describe('ec2Service.runInstance', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('ec2Service.describeInstance', () => {
|
||||
test('maps attached network interfaces and their addresses', async () => {
|
||||
const service = createEc2Service(fakeClient({
|
||||
DescribeInstancesCommand: {
|
||||
Reservations: [{Instances: [{
|
||||
InstanceId: 'i-networked',
|
||||
NetworkInterfaces: [{
|
||||
NetworkInterfaceId: 'eni-123',
|
||||
Attachment: {DeviceIndex: 0},
|
||||
Status: 'in-use',
|
||||
PrivateIpAddress: '10.0.1.10',
|
||||
Association: {PublicIp: '198.51.100.10'},
|
||||
Groups: [{GroupId: 'sg-123', GroupName: 'web'}],
|
||||
}],
|
||||
}]}],
|
||||
},
|
||||
}))
|
||||
|
||||
const instance = await service.describeInstance('i-networked')
|
||||
|
||||
expect(instance.networkInterfaces).toEqual([{
|
||||
networkInterfaceId: 'eni-123',
|
||||
deviceIndex: 0,
|
||||
status: 'in-use',
|
||||
privateIpAddress: '10.0.1.10',
|
||||
publicIpAddress: '198.51.100.10',
|
||||
privateDnsName: undefined,
|
||||
subnetId: undefined,
|
||||
vpcId: undefined,
|
||||
securityGroups: [{id: 'sg-123', name: 'web'}],
|
||||
}])
|
||||
})
|
||||
})
|
||||
|
||||
describe('ec2Service lifecycle', () => {
|
||||
test('startInstance sends StartInstancesCommand with correct id', async () => {
|
||||
const sentCmds: unknown[] = []
|
||||
|
||||
@@ -77,6 +77,18 @@ export type Ec2SecurityGroupRef = {
|
||||
name?: string
|
||||
}
|
||||
|
||||
export type Ec2NetworkInterface = {
|
||||
networkInterfaceId: string
|
||||
deviceIndex?: number
|
||||
status?: string
|
||||
privateIpAddress?: string
|
||||
publicIpAddress?: string
|
||||
privateDnsName?: string
|
||||
subnetId?: string
|
||||
vpcId?: string
|
||||
securityGroups: Ec2SecurityGroupRef[]
|
||||
}
|
||||
|
||||
export type Ec2IpPermission = {
|
||||
protocol: string
|
||||
fromPort: number | null
|
||||
@@ -126,6 +138,7 @@ export type Ec2Instance = {
|
||||
architecture?: string
|
||||
platform?: string
|
||||
securityGroups: Ec2SecurityGroupRef[]
|
||||
networkInterfaces: Ec2NetworkInterface[]
|
||||
tags: Ec2Tag[]
|
||||
}
|
||||
|
||||
@@ -306,6 +319,20 @@ function toEc2Instance(instance: Instance): Ec2Instance {
|
||||
id: sg.GroupId,
|
||||
name: sg.GroupName,
|
||||
})),
|
||||
networkInterfaces: (instance.NetworkInterfaces ?? []).map((networkInterface) => ({
|
||||
networkInterfaceId: networkInterface.NetworkInterfaceId ?? '',
|
||||
deviceIndex: networkInterface.Attachment?.DeviceIndex,
|
||||
status: networkInterface.Status,
|
||||
privateIpAddress: networkInterface.PrivateIpAddress,
|
||||
publicIpAddress: networkInterface.Association?.PublicIp,
|
||||
privateDnsName: networkInterface.PrivateDnsName,
|
||||
subnetId: networkInterface.SubnetId,
|
||||
vpcId: networkInterface.VpcId,
|
||||
securityGroups: (networkInterface.Groups ?? []).map((group) => ({
|
||||
id: group.GroupId,
|
||||
name: group.GroupName,
|
||||
})),
|
||||
})),
|
||||
tags,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user