Skip to content

Commit

Permalink
feat(ecr): Add emptyOnDelete CloudFormation property to L2 construct
Browse files Browse the repository at this point in the history
  • Loading branch information
markmansur committed Dec 2, 2023
1 parent 116b933 commit bed2d07
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 10 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@
}
]
}
},
"RepoWithEmptyOnDeleteCA5C67FA": {
"Type": "AWS::ECR::Repository",
"Properties": {
"EmptyOnDelete": true
},
"UpdateReplacePolicy": "Retain",
"DeletionPolicy": "Retain"
}
},
"Outputs": {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ const user = new iam.User(stack, 'MyUser');
repo.grantRead(user);
repo.grantPullPush(user);

new ecr.Repository(stack, 'RepoWithEmptyOnDelete', {
emptyOnDelete: true,
});

new cdk.CfnOutput(stack, 'RepositoryURI', {
value: repo.repositoryUri,
});
Expand Down
8 changes: 8 additions & 0 deletions packages/aws-cdk-lib/aws-ecr/lib/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,13 @@ export interface RepositoryProps {
* @default false
*/
readonly autoDeleteImages?: boolean;

/**
* If true, deleting the repository force deletes the contents of the repository. If false, the repository must be empty before attempting to delete it.
*
* @default false
*/
readonly emptyOnDelete?: boolean;
}

export interface RepositoryAttributes {
Expand Down Expand Up @@ -706,6 +713,7 @@ export class Repository extends RepositoryBase {
imageScanningConfiguration: props.imageScanOnPush !== undefined ? { scanOnPush: props.imageScanOnPush } : undefined,
imageTagMutability: props.imageTagMutability || undefined,
encryptionConfiguration: this.parseEncryption(props),
emptyOnDelete: props.emptyOnDelete,
});
this._resource = resource;

Expand Down
11 changes: 11 additions & 0 deletions packages/aws-cdk-lib/aws-ecr/test/repository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,17 @@ describe('repository', () => {
});
});

test('emptyOnDelete can be set', () => {
// GIVEN
const stack = new cdk.Stack();
new ecr.Repository(stack, 'Repo', { emptyOnDelete: true });

// THEN
Template.fromStack(stack).hasResourceProperties('AWS::ECR::Repository', {
EmptyOnDelete: true,
});
});

test('add day-based lifecycle policy', () => {
// GIVEN
const stack = new cdk.Stack();
Expand Down

0 comments on commit bed2d07

Please sign in to comment.