Skip to content

Commit

Permalink
Merge pull request #1169 from Tomburgs/fix/ecs-task-port-mapping
Browse files Browse the repository at this point in the history
Fix getMappingInputs removing valid arguments
  • Loading branch information
mjeffryes authored Dec 5, 2023
2 parents 52e698d + 4537072 commit bf6f8cd
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
28 changes: 28 additions & 0 deletions awsx/ecs/container.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -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<T>(output: pulumi.Output<T>): Promise<T> {
Expand Down
3 changes: 2 additions & 1 deletion awsx/ecs/containers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit bf6f8cd

Please sign in to comment.