diff --git a/awsx/ecs/container.test.ts b/awsx/ecs/container.test.ts index 74767e765..e044d1d43 100644 --- a/awsx/ecs/container.test.ts +++ b/awsx/ecs/container.test.ts @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. import * as pulumi from "@pulumi/pulumi"; +import * as aws from "@pulumi/aws"; import { normalizeTaskDefinitionContainers, getMappingInputs } from "./containers"; @@ -32,6 +33,33 @@ describe("port mappings", () => { expect(inputs).toMatchObject({ containerPort: containerOut, hostPort: hostOut }); }, ); + + it("returns all valid arguments", () => { + const targetGroup = new aws.lb.TargetGroup("test-tg"); + + const inputs = getMappingInputs( + { + appProtocol: "grpc", + containerPort: 1, + containerPortRange: "1-65535", + hostPort: 2, + name: "test-mapping-1-2", + protocol: "tcp", + targetGroup, + }, + undefined, + ); + + expect(inputs).toMatchObject({ + appProtocol: "grpc", + containerPort: 1, + containerPortRange: "1-65535", + hostPort: 2, + name: "test-mapping-1-2", + protocol: "tcp", + targetGroup, + }); + }); }); function promiseOf(output: pulumi.Output): Promise { diff --git a/awsx/ecs/containers.ts b/awsx/ecs/containers.ts index 7cdb3680e..e4ac350a1 100644 --- a/awsx/ecs/containers.ts +++ b/awsx/ecs/containers.ts @@ -97,10 +97,11 @@ function computeContainerDefinition( } export function getMappingInputs( - mappingInput: { containerPort?: number; hostPort?: number; protocol?: string }, + mappingInput: schema.TaskDefinitionPortMappingInputs, tgPort: number | undefined, ): schema.TaskDefinitionPortMappingInputs { return { + ...mappingInput, containerPort: mappingInput.containerPort ?? mappingInput.hostPort ?? tgPort, hostPort: mappingInput.hostPort ?? tgPort ?? mappingInput.containerPort, protocol: mappingInput.protocol,