Skip to content

Commit

Permalink
fix(ecs): remove unnecessary error when adding volume to external tas…
Browse files Browse the repository at this point in the history
…k definition (#19774)

fixes #19259

----

### All Submissions:

* [ ] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md)

### Adding new Unconventional Dependencies:

* [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md/#adding-new-unconventional-dependencies)

### New Features

* [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/master/INTEGRATION_TESTS.md)?
	* [ ] Did you use `cdk-integ` to deploy the infrastructure and generate the snapshot (i.e. `cdk-integ` without `--dry-run`)?

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
peterwoodworth committed Apr 5, 2022
1 parent 2550589 commit 5446ded
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
ITaskDefinition,
NetworkMode,
TaskDefinition,
Volume,
} from '../base/task-definition';

/**
Expand Down Expand Up @@ -75,13 +74,6 @@ export class ExternalTaskDefinition extends TaskDefinition implements IExternalT
});
}

/**
* Overridden method to throw error, as volumes are not supported for external task definitions
*/
public addVolume(_volume: Volume) {
throw new Error('External task definitions doesnt support volumes');
}

/**
* Overriden method to throw error as interface accelerators are not supported for external tasks
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -601,17 +601,30 @@ describe('external task definition', () => {
Annotations.fromStack(stack).hasWarning('/Default/ExternalTaskDef/web', "Proper policies need to be attached before pulling from ECR repository, or use 'fromEcrRepository'.");
});

test('correctly sets volumes from', () => {
test('correctly sets volumes', () => {
// GIVEN
const stack = new cdk.Stack();
const taskDefinition = new ecs.ExternalTaskDefinition(stack, 'ExternalTaskDef', {});

// THEN
expect(() => taskDefinition.addVolume({
// WHEN
taskDefinition.addVolume({
host: {
sourcePath: '/tmp/cache',
},
name: 'scratch',
})).toThrow('External task definitions doesnt support volumes' );
});

// THEN
Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', {
Volumes: [
{
Host: {
SourcePath: '/tmp/cache',
},
Name: 'scratch',
},
],
});
});

test('error when interferenceAccelerators set', () => {
Expand Down

0 comments on commit 5446ded

Please sign in to comment.