Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ecs): ability to access tag parameter value of TagParameterContainerImage #13340

Merged
merged 6 commits into from
Mar 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/@aws-cdk/aws-ecs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,8 @@ obtained from either DockerHub or from ECR repositories, or built directly from
image directly from a `Dockerfile` in your source directory.
- `ecs.ContainerImage.fromDockerImageAsset(asset)`: uses an existing
`@aws-cdk/aws-ecr-assets.DockerImageAsset` as a container image.
- `new ecs.TagParameterContainerImage(repository)`: use the given ECR repository as the image
but a CloudFormation parameter as the tag.

### Environment variables

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,20 @@ export class TagParameterContainerImage extends ContainerImage {
},
});
}

/**
* Returns the value of the CloudFormation Parameter that represents the tag of the image
* in the ECR repository.
*/
public get tagParameterValue(): string {
return cdk.Lazy.string({
produce: () => {
if (this.imageTagParameter) {
return this.imageTagParameter.valueAsString;
} else {
throw new Error('TagParameterContainerImage must be used in a container definition when using tagParameterValue');
}
},
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,21 @@ nodeunitShim({

test.done();
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add an empty line after this line?

Suggested change
},
},


'throws an error when tagParameterValue() is used without binding the image'(test: Test) {
// GIVEN
const stack = new cdk.Stack();
const repository = new ecr.Repository(stack, 'Repository');
const tagParameterContainerImage = new ecs.TagParameterContainerImage(repository);
new cdk.CfnOutput(stack, 'Output', {
value: tagParameterContainerImage.tagParameterValue,
});

test.throws(() => {
SynthUtils.synthesize(stack);
}, /TagParameterContainerImage must be used in a container definition when using tagParameterValue/);

test.done();
},
},
});