Skip to content

Commit

Permalink
fix: targetGroup errors appear in containerDefinition diff
Browse files Browse the repository at this point in the history
The [container
definition](https://www.pulumi.com/registry/packages/aws/api-docs/ecs/taskdefinition/#containerdefinitions_nodejs)
property of a Task Definition is a JSON string. We do not provide types
for the container definition which means it is possible to include
things in that JSON string that shouldn't be there. In the case of
this bug, we are including an additional `targetGroup` object in the
container definition string.

To fix this, I am removing the `targetGroup` field at the time that we
render the container definition JSON string. Ideally we may want to
created an interface type for a container definition in the AWS provider
which would make these errors easier to catch.

fix #1248
  • Loading branch information
corymhall committed Apr 9, 2024
1 parent 0390f0d commit 3cbf9d6
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion awsx/ecs/fargateTaskDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,34 @@ function buildTaskDefinitionArgs(
if (mutableArgs.memory === undefined) {
mutableArgs.memory = requiredMemoryAndCPU.memory;
}
const containerString = containerDefinitions.apply((d) => JSON.stringify(d));

// containerDefinitions is of type TaskDefinitionContainerDefinitionInputs[],
// but this type does not match 1:1 with what the actual container definition
// JSON string expects. Specifically the portMappings field contains an extra
// `targetGroup` field which is a reference to the target group resource. We
// need to remove this field from the container definition JSON string,
// otherwise the diff will contain a lot of noise.
const containerString = containerDefinitions.apply((d) =>
JSON.stringify(
d.map((c) => {
return {
...c,
portMappings: pulumi.output(c.portMappings).apply((mappings) => {
return mappings?.map((mappingInput) => {
return {
appProtocol: mappingInput.appProtocol,
containerPort: mappingInput.containerPort,
containerPortRange: mappingInput.containerPortRange,
hostPort: mappingInput.hostPort,
name: mappingInput.name,
protocol: mappingInput.protocol,
};
});
}),
};
}),
),
);
const defaultFamily = containerString.apply(
(s) => name + "-" + utils.sha1hash(pulumi.getStack() + s),
);
Expand Down

0 comments on commit 3cbf9d6

Please sign in to comment.