feat(aws-ecs): Ec2Service, FargateService, and ExternalService do not accept imported task definitions#37048
Open
letsgomeow wants to merge 11 commits intoaws:mainfrom
Open
feat(aws-ecs): Ec2Service, FargateService, and ExternalService do not accept imported task definitions#37048letsgomeow wants to merge 11 commits intoaws:mainfrom
letsgomeow wants to merge 11 commits intoaws:mainfrom
Conversation
…nd ExternalService
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue # (if applicable)
Closes #7863.
Reason for this change
Ec2Service,FargateService, andExternalServicedeclared theirtaskDefinitionprop as the concrete classTaskDefinition, which meant that task definitions imported viafromTaskDefinitionArn()or similar static import methods could not be passed to these constructs. This prevented valid cross-stack and cross-account patterns where a task definition is managed separately from the service.Description of changes
base/base-service.tstaskDefinitionparameter type fromTaskDefinitiontoITaskDefinitioninBaseService's constructor and thetaskDefinitionproperty declaration.TaskDefinition.isTaskDefinition()guards around all code paths that rely on properties only available on owned task definitions (e.g.,taskRole,family,defaultContainer,findPortMappingByName):taskRoledependency: skipped for imported task definitionsValidationErrorwhen an imported task definition is supplied, asfamilyis required for strip-revision logictaskDefinitionRevision: same restriction with a descriptive errorfindPortMappingByName)addInfoannotation instead of granting permissions, since the task role is unknownValidationErrorwith a clear messageValidationErrorec2/ec2-service.tstaskDefinitionprop type fromTaskDefinitiontoITaskDefinition.isEc2Compatiblecompatibility check in anisTaskDefinition()guard (imported task definitions cannot be verified at synth time).networkMode-based VPC networking setup in anisTaskDefinition()guard; for imported task definitions, VPC networking props are used as a hint if provided.defaultContainerexistence validation in anisTaskDefinition()guard; emits an annotation for imported task definitions.fargate/fargate-service.tstaskDefinitionprop type fromTaskDefinitiontoITaskDefinition.isFargateCompatiblecompatibility check in anisTaskDefinition()guard.external/external-service.tstaskDefinitionprop type fromTaskDefinitiontoITaskDefinition.Compatibility.EXTERNALcompatibility check in anisTaskDefinition()guard.defaultContainerexistence validation in anisTaskDefinition()guard.README.mdDescribe any new or updated permissions being added
None. When an imported task definition is used with execute-command enabled, permissions that would normally be granted to the task role are skipped (the task role is unknown). An
addInfoannotation is emitted to notify users to configure these permissions manually.Description of how you validated changes
Unit tests (
packages/aws-cdk-lib/aws-ecs/test/fargate/fargate-service.test.ts):FargateServiceaccepts an imported task definition.taskDefinitionRevision, Service Connect, load balancer target, Cloud Map) throw descriptiveValidationErrors.Integration tests (all passing against a real AWS account):
test/fargate/integ.fargate-service-imported-taskdef.tsproducerStack, service created inconsumerStackusing only the ARNtest/ec2/integ.ec2-service-imported-taskdef.tsEc2Servicewith an imported task definition, including a second service withplacementStrategiesto verify EC2-specific features worktest/external/integ.external-service-imported-taskdef.tsExternalServicewith an imported task definition, including a daemon-mode serviceChecklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license