From 5e7df88a97a5c523eb55ac8c180eb39e64cc9afc Mon Sep 17 00:00:00 2001 From: mazyu36 Date: Fri, 24 May 2024 03:28:46 +0900 Subject: [PATCH] feat(codebuild): add deleteReports property to the ReportGroup Construct (#30141) ### Issue # (if applicable) N/A ### Reason for this change Missing property in the L2 Construct. ### Description of changes Add deleteReports property. https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_codebuild.CfnReportGroup.html#deletereports ### Description of how you validated changes Add unit tests and integ tests. ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* --- ...efaultTestDeployAssertFBD2FDC0.assets.json | 19 + ...aultTestDeployAssertFBD2FDC0.template.json | 36 ++ ...dk-report-group-delete-reports.assets.json | 19 + ...-report-group-delete-reports.template.json | 197 ++++++++++ .../cdk.out | 1 + .../integ.json | 12 + .../manifest.json | 131 +++++++ .../tree.json | 338 ++++++++++++++++++ .../test/integ.report-group-delete-reports.ts | 42 +++ packages/aws-cdk-lib/aws-codebuild/README.md | 23 +- .../aws-codebuild/lib/report-group.ts | 12 + .../aws-codebuild/test/report-group.test.ts | 25 ++ 12 files changed, 854 insertions(+), 1 deletion(-) create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-codebuild/test/integ.report-group-delete-reports.js.snapshot/ReportGroupDeleteReportsIntegTestDefaultTestDeployAssertFBD2FDC0.assets.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-codebuild/test/integ.report-group-delete-reports.js.snapshot/ReportGroupDeleteReportsIntegTestDefaultTestDeployAssertFBD2FDC0.template.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-codebuild/test/integ.report-group-delete-reports.js.snapshot/aws-cdk-report-group-delete-reports.assets.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-codebuild/test/integ.report-group-delete-reports.js.snapshot/aws-cdk-report-group-delete-reports.template.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-codebuild/test/integ.report-group-delete-reports.js.snapshot/cdk.out create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-codebuild/test/integ.report-group-delete-reports.js.snapshot/integ.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-codebuild/test/integ.report-group-delete-reports.js.snapshot/manifest.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-codebuild/test/integ.report-group-delete-reports.js.snapshot/tree.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-codebuild/test/integ.report-group-delete-reports.ts diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-codebuild/test/integ.report-group-delete-reports.js.snapshot/ReportGroupDeleteReportsIntegTestDefaultTestDeployAssertFBD2FDC0.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-codebuild/test/integ.report-group-delete-reports.js.snapshot/ReportGroupDeleteReportsIntegTestDefaultTestDeployAssertFBD2FDC0.assets.json new file mode 100644 index 0000000000000..8bb8a422c32c7 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-codebuild/test/integ.report-group-delete-reports.js.snapshot/ReportGroupDeleteReportsIntegTestDefaultTestDeployAssertFBD2FDC0.assets.json @@ -0,0 +1,19 @@ +{ + "version": "36.0.0", + "files": { + "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22": { + "source": { + "path": "ReportGroupDeleteReportsIntegTestDefaultTestDeployAssertFBD2FDC0.template.json", + "packaging": "file" + }, + "destinations": { + "current_account-current_region": { + "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", + "objectKey": "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json", + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" + } + } + } + }, + "dockerImages": {} +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-codebuild/test/integ.report-group-delete-reports.js.snapshot/ReportGroupDeleteReportsIntegTestDefaultTestDeployAssertFBD2FDC0.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-codebuild/test/integ.report-group-delete-reports.js.snapshot/ReportGroupDeleteReportsIntegTestDefaultTestDeployAssertFBD2FDC0.template.json new file mode 100644 index 0000000000000..ad9d0fb73d1dd --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-codebuild/test/integ.report-group-delete-reports.js.snapshot/ReportGroupDeleteReportsIntegTestDefaultTestDeployAssertFBD2FDC0.template.json @@ -0,0 +1,36 @@ +{ + "Parameters": { + "BootstrapVersion": { + "Type": "AWS::SSM::Parameter::Value", + "Default": "/cdk-bootstrap/hnb659fds/version", + "Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]" + } + }, + "Rules": { + "CheckBootstrapVersion": { + "Assertions": [ + { + "Assert": { + "Fn::Not": [ + { + "Fn::Contains": [ + [ + "1", + "2", + "3", + "4", + "5" + ], + { + "Ref": "BootstrapVersion" + } + ] + } + ] + }, + "AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI." + } + ] + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-codebuild/test/integ.report-group-delete-reports.js.snapshot/aws-cdk-report-group-delete-reports.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-codebuild/test/integ.report-group-delete-reports.js.snapshot/aws-cdk-report-group-delete-reports.assets.json new file mode 100644 index 0000000000000..46bf11d056426 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-codebuild/test/integ.report-group-delete-reports.js.snapshot/aws-cdk-report-group-delete-reports.assets.json @@ -0,0 +1,19 @@ +{ + "version": "36.0.0", + "files": { + "c6a2f102b98eb6b8b078b8c708c5ec49ac9fb7e611cd4a8bccfd504b93ab555c": { + "source": { + "path": "aws-cdk-report-group-delete-reports.template.json", + "packaging": "file" + }, + "destinations": { + "current_account-current_region": { + "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", + "objectKey": "c6a2f102b98eb6b8b078b8c708c5ec49ac9fb7e611cd4a8bccfd504b93ab555c.json", + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" + } + } + } + }, + "dockerImages": {} +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-codebuild/test/integ.report-group-delete-reports.js.snapshot/aws-cdk-report-group-delete-reports.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-codebuild/test/integ.report-group-delete-reports.js.snapshot/aws-cdk-report-group-delete-reports.template.json new file mode 100644 index 0000000000000..f23ea7df4e3bf --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-codebuild/test/integ.report-group-delete-reports.js.snapshot/aws-cdk-report-group-delete-reports.template.json @@ -0,0 +1,197 @@ +{ + "Resources": { + "TestReportGroupDeleteReportsE2EEFA13": { + "Type": "AWS::CodeBuild::ReportGroup", + "Properties": { + "DeleteReports": true, + "ExportConfig": { + "ExportConfigType": "NO_EXPORT" + }, + "Type": "TEST" + }, + "UpdateReplacePolicy": "Delete", + "DeletionPolicy": "Delete" + }, + "MyProjectRole9BBE5233": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "codebuild.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + } + } + }, + "MyProjectRoleDefaultPolicyB19B7C29": { + "Type": "AWS::IAM::Policy", + "Properties": { + "PolicyDocument": { + "Statement": [ + { + "Action": [ + "logs:CreateLogGroup", + "logs:CreateLogStream", + "logs:PutLogEvents" + ], + "Effect": "Allow", + "Resource": [ + { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":logs:", + { + "Ref": "AWS::Region" + }, + ":", + { + "Ref": "AWS::AccountId" + }, + ":log-group:/aws/codebuild/", + { + "Ref": "MyProject39F7B0AE" + }, + ":*" + ] + ] + }, + { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":logs:", + { + "Ref": "AWS::Region" + }, + ":", + { + "Ref": "AWS::AccountId" + }, + ":log-group:/aws/codebuild/", + { + "Ref": "MyProject39F7B0AE" + } + ] + ] + } + ] + }, + { + "Action": [ + "codebuild:BatchPutTestCases", + "codebuild:CreateReport", + "codebuild:UpdateReport" + ], + "Effect": "Allow", + "Resource": { + "Fn::GetAtt": [ + "TestReportGroupDeleteReportsE2EEFA13", + "Arn" + ] + } + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "MyProjectRoleDefaultPolicyB19B7C29", + "Roles": [ + { + "Ref": "MyProjectRole9BBE5233" + } + ] + } + }, + "MyProject39F7B0AE": { + "Type": "AWS::CodeBuild::Project", + "Properties": { + "Artifacts": { + "Type": "NO_ARTIFACTS" + }, + "Cache": { + "Type": "NO_CACHE" + }, + "EncryptionKey": "alias/aws/s3", + "Environment": { + "ComputeType": "BUILD_GENERAL1_SMALL", + "Image": "aws/codebuild/standard:1.0", + "ImagePullCredentialsType": "CODEBUILD", + "PrivilegedMode": false, + "Type": "LINUX_CONTAINER" + }, + "ServiceRole": { + "Fn::GetAtt": [ + "MyProjectRole9BBE5233", + "Arn" + ] + }, + "Source": { + "BuildSpec": { + "Fn::Join": [ + "", + [ + "{\n \"version\": \"0.2\",\n \"phases\": {\n \"build\": {\n \"commands\": [\n \"echo \\\"Nothing to do!\\\"\"\n ]\n }\n },\n \"reports\": {\n \"", + { + "Fn::GetAtt": [ + "TestReportGroupDeleteReportsE2EEFA13", + "Arn" + ] + }, + "\": {\n \"base-directory\": \"test-reports\",\n \"file-format\": \"JUNITXML\",\n \"files\": [\n \"**/*\"\n ]\n }\n }\n}" + ] + ] + }, + "Type": "NO_SOURCE" + } + } + } + }, + "Parameters": { + "BootstrapVersion": { + "Type": "AWS::SSM::Parameter::Value", + "Default": "/cdk-bootstrap/hnb659fds/version", + "Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]" + } + }, + "Rules": { + "CheckBootstrapVersion": { + "Assertions": [ + { + "Assert": { + "Fn::Not": [ + { + "Fn::Contains": [ + [ + "1", + "2", + "3", + "4", + "5" + ], + { + "Ref": "BootstrapVersion" + } + ] + } + ] + }, + "AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI." + } + ] + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-codebuild/test/integ.report-group-delete-reports.js.snapshot/cdk.out b/packages/@aws-cdk-testing/framework-integ/test/aws-codebuild/test/integ.report-group-delete-reports.js.snapshot/cdk.out new file mode 100644 index 0000000000000..1f0068d32659a --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-codebuild/test/integ.report-group-delete-reports.js.snapshot/cdk.out @@ -0,0 +1 @@ +{"version":"36.0.0"} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-codebuild/test/integ.report-group-delete-reports.js.snapshot/integ.json b/packages/@aws-cdk-testing/framework-integ/test/aws-codebuild/test/integ.report-group-delete-reports.js.snapshot/integ.json new file mode 100644 index 0000000000000..458b47a187673 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-codebuild/test/integ.report-group-delete-reports.js.snapshot/integ.json @@ -0,0 +1,12 @@ +{ + "version": "36.0.0", + "testCases": { + "ReportGroupDeleteReportsIntegTest/DefaultTest": { + "stacks": [ + "aws-cdk-report-group-delete-reports" + ], + "assertionStack": "ReportGroupDeleteReportsIntegTest/DefaultTest/DeployAssert", + "assertionStackName": "ReportGroupDeleteReportsIntegTestDefaultTestDeployAssertFBD2FDC0" + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-codebuild/test/integ.report-group-delete-reports.js.snapshot/manifest.json b/packages/@aws-cdk-testing/framework-integ/test/aws-codebuild/test/integ.report-group-delete-reports.js.snapshot/manifest.json new file mode 100644 index 0000000000000..a7a7ef53b8ef3 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-codebuild/test/integ.report-group-delete-reports.js.snapshot/manifest.json @@ -0,0 +1,131 @@ +{ + "version": "36.0.0", + "artifacts": { + "aws-cdk-report-group-delete-reports.assets": { + "type": "cdk:asset-manifest", + "properties": { + "file": "aws-cdk-report-group-delete-reports.assets.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "aws-cdk-report-group-delete-reports": { + "type": "aws:cloudformation:stack", + "environment": "aws://unknown-account/unknown-region", + "properties": { + "templateFile": "aws-cdk-report-group-delete-reports.template.json", + "terminationProtection": false, + "validateOnSynth": false, + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", + "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/c6a2f102b98eb6b8b078b8c708c5ec49ac9fb7e611cd4a8bccfd504b93ab555c.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", + "additionalDependencies": [ + "aws-cdk-report-group-delete-reports.assets" + ], + "lookupRole": { + "arn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-lookup-role-${AWS::AccountId}-${AWS::Region}", + "requiresBootstrapStackVersion": 8, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "dependencies": [ + "aws-cdk-report-group-delete-reports.assets" + ], + "metadata": { + "/aws-cdk-report-group-delete-reports/TestReportGroupDeleteReports/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "TestReportGroupDeleteReportsE2EEFA13" + } + ], + "/aws-cdk-report-group-delete-reports/MyProject/Role/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "MyProjectRole9BBE5233" + } + ], + "/aws-cdk-report-group-delete-reports/MyProject/Role/DefaultPolicy/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "MyProjectRoleDefaultPolicyB19B7C29" + } + ], + "/aws-cdk-report-group-delete-reports/MyProject/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "MyProject39F7B0AE" + } + ], + "/aws-cdk-report-group-delete-reports/BootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "BootstrapVersion" + } + ], + "/aws-cdk-report-group-delete-reports/CheckBootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "CheckBootstrapVersion" + } + ] + }, + "displayName": "aws-cdk-report-group-delete-reports" + }, + "ReportGroupDeleteReportsIntegTestDefaultTestDeployAssertFBD2FDC0.assets": { + "type": "cdk:asset-manifest", + "properties": { + "file": "ReportGroupDeleteReportsIntegTestDefaultTestDeployAssertFBD2FDC0.assets.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "ReportGroupDeleteReportsIntegTestDefaultTestDeployAssertFBD2FDC0": { + "type": "aws:cloudformation:stack", + "environment": "aws://unknown-account/unknown-region", + "properties": { + "templateFile": "ReportGroupDeleteReportsIntegTestDefaultTestDeployAssertFBD2FDC0.template.json", + "terminationProtection": false, + "validateOnSynth": false, + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", + "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", + "additionalDependencies": [ + "ReportGroupDeleteReportsIntegTestDefaultTestDeployAssertFBD2FDC0.assets" + ], + "lookupRole": { + "arn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-lookup-role-${AWS::AccountId}-${AWS::Region}", + "requiresBootstrapStackVersion": 8, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "dependencies": [ + "ReportGroupDeleteReportsIntegTestDefaultTestDeployAssertFBD2FDC0.assets" + ], + "metadata": { + "/ReportGroupDeleteReportsIntegTest/DefaultTest/DeployAssert/BootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "BootstrapVersion" + } + ], + "/ReportGroupDeleteReportsIntegTest/DefaultTest/DeployAssert/CheckBootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "CheckBootstrapVersion" + } + ] + }, + "displayName": "ReportGroupDeleteReportsIntegTest/DefaultTest/DeployAssert" + }, + "Tree": { + "type": "cdk:tree", + "properties": { + "file": "tree.json" + } + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-codebuild/test/integ.report-group-delete-reports.js.snapshot/tree.json b/packages/@aws-cdk-testing/framework-integ/test/aws-codebuild/test/integ.report-group-delete-reports.js.snapshot/tree.json new file mode 100644 index 0000000000000..ca8a17cf0dfc5 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-codebuild/test/integ.report-group-delete-reports.js.snapshot/tree.json @@ -0,0 +1,338 @@ +{ + "version": "tree-0.1", + "tree": { + "id": "App", + "path": "", + "children": { + "aws-cdk-report-group-delete-reports": { + "id": "aws-cdk-report-group-delete-reports", + "path": "aws-cdk-report-group-delete-reports", + "children": { + "TestReportGroupDeleteReports": { + "id": "TestReportGroupDeleteReports", + "path": "aws-cdk-report-group-delete-reports/TestReportGroupDeleteReports", + "children": { + "Resource": { + "id": "Resource", + "path": "aws-cdk-report-group-delete-reports/TestReportGroupDeleteReports/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::CodeBuild::ReportGroup", + "aws:cdk:cloudformation:props": { + "deleteReports": true, + "exportConfig": { + "exportConfigType": "NO_EXPORT" + }, + "type": "TEST" + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + }, + "MyProject": { + "id": "MyProject", + "path": "aws-cdk-report-group-delete-reports/MyProject", + "children": { + "Role": { + "id": "Role", + "path": "aws-cdk-report-group-delete-reports/MyProject/Role", + "children": { + "ImportRole": { + "id": "ImportRole", + "path": "aws-cdk-report-group-delete-reports/MyProject/Role/ImportRole", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + }, + "Resource": { + "id": "Resource", + "path": "aws-cdk-report-group-delete-reports/MyProject/Role/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::IAM::Role", + "aws:cdk:cloudformation:props": { + "assumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "codebuild.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + }, + "DefaultPolicy": { + "id": "DefaultPolicy", + "path": "aws-cdk-report-group-delete-reports/MyProject/Role/DefaultPolicy", + "children": { + "Resource": { + "id": "Resource", + "path": "aws-cdk-report-group-delete-reports/MyProject/Role/DefaultPolicy/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::IAM::Policy", + "aws:cdk:cloudformation:props": { + "policyDocument": { + "Statement": [ + { + "Action": [ + "logs:CreateLogGroup", + "logs:CreateLogStream", + "logs:PutLogEvents" + ], + "Effect": "Allow", + "Resource": [ + { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":logs:", + { + "Ref": "AWS::Region" + }, + ":", + { + "Ref": "AWS::AccountId" + }, + ":log-group:/aws/codebuild/", + { + "Ref": "MyProject39F7B0AE" + }, + ":*" + ] + ] + }, + { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":logs:", + { + "Ref": "AWS::Region" + }, + ":", + { + "Ref": "AWS::AccountId" + }, + ":log-group:/aws/codebuild/", + { + "Ref": "MyProject39F7B0AE" + } + ] + ] + } + ] + }, + { + "Action": [ + "codebuild:BatchPutTestCases", + "codebuild:CreateReport", + "codebuild:UpdateReport" + ], + "Effect": "Allow", + "Resource": { + "Fn::GetAtt": [ + "TestReportGroupDeleteReportsE2EEFA13", + "Arn" + ] + } + } + ], + "Version": "2012-10-17" + }, + "policyName": "MyProjectRoleDefaultPolicyB19B7C29", + "roles": [ + { + "Ref": "MyProjectRole9BBE5233" + } + ] + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + }, + "Resource": { + "id": "Resource", + "path": "aws-cdk-report-group-delete-reports/MyProject/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::CodeBuild::Project", + "aws:cdk:cloudformation:props": { + "artifacts": { + "type": "NO_ARTIFACTS" + }, + "cache": { + "type": "NO_CACHE" + }, + "encryptionKey": "alias/aws/s3", + "environment": { + "type": "LINUX_CONTAINER", + "image": "aws/codebuild/standard:1.0", + "imagePullCredentialsType": "CODEBUILD", + "privilegedMode": false, + "computeType": "BUILD_GENERAL1_SMALL" + }, + "serviceRole": { + "Fn::GetAtt": [ + "MyProjectRole9BBE5233", + "Arn" + ] + }, + "source": { + "type": "NO_SOURCE", + "buildSpec": { + "Fn::Join": [ + "", + [ + "{\n \"version\": \"0.2\",\n \"phases\": {\n \"build\": {\n \"commands\": [\n \"echo \\\"Nothing to do!\\\"\"\n ]\n }\n },\n \"reports\": {\n \"", + { + "Fn::GetAtt": [ + "TestReportGroupDeleteReportsE2EEFA13", + "Arn" + ] + }, + "\": {\n \"base-directory\": \"test-reports\",\n \"file-format\": \"JUNITXML\",\n \"files\": [\n \"**/*\"\n ]\n }\n }\n}" + ] + ] + } + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + }, + "BootstrapVersion": { + "id": "BootstrapVersion", + "path": "aws-cdk-report-group-delete-reports/BootstrapVersion", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + }, + "CheckBootstrapVersion": { + "id": "CheckBootstrapVersion", + "path": "aws-cdk-report-group-delete-reports/CheckBootstrapVersion", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + }, + "ReportGroupDeleteReportsIntegTest": { + "id": "ReportGroupDeleteReportsIntegTest", + "path": "ReportGroupDeleteReportsIntegTest", + "children": { + "DefaultTest": { + "id": "DefaultTest", + "path": "ReportGroupDeleteReportsIntegTest/DefaultTest", + "children": { + "Default": { + "id": "Default", + "path": "ReportGroupDeleteReportsIntegTest/DefaultTest/Default", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + }, + "DeployAssert": { + "id": "DeployAssert", + "path": "ReportGroupDeleteReportsIntegTest/DefaultTest/DeployAssert", + "children": { + "BootstrapVersion": { + "id": "BootstrapVersion", + "path": "ReportGroupDeleteReportsIntegTest/DefaultTest/DeployAssert/BootstrapVersion", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + }, + "CheckBootstrapVersion": { + "id": "CheckBootstrapVersion", + "path": "ReportGroupDeleteReportsIntegTest/DefaultTest/DeployAssert/CheckBootstrapVersion", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/integ-tests-alpha.IntegTestCase", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/integ-tests-alpha.IntegTest", + "version": "0.0.0" + } + }, + "Tree": { + "id": "Tree", + "path": "Tree", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-codebuild/test/integ.report-group-delete-reports.ts b/packages/@aws-cdk-testing/framework-integ/test/aws-codebuild/test/integ.report-group-delete-reports.ts new file mode 100644 index 0000000000000..bb767bb5eb209 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-codebuild/test/integ.report-group-delete-reports.ts @@ -0,0 +1,42 @@ +import * as cdk from 'aws-cdk-lib'; +import * as integ from '@aws-cdk/integ-tests-alpha'; +import * as codebuild from 'aws-cdk-lib/aws-codebuild'; + +const app = new cdk.App(); + +const stack = new cdk.Stack(app, 'aws-cdk-report-group-delete-reports'); + +const reportGroupTest = new codebuild.ReportGroup(stack, 'TestReportGroupDeleteReports', { + type: codebuild.ReportGroupType.TEST, + deleteReports: true, + removalPolicy: cdk.RemovalPolicy.DESTROY, +}); + +const project = new codebuild.Project(stack, 'MyProject', { + buildSpec: codebuild.BuildSpec.fromObject({ + version: '0.2', + phases: { + build: { + commands: ['echo "Nothing to do!"'], + }, + }, + reports: { + [reportGroupTest.reportGroupArn]: { + 'base-directory': 'test-reports', + 'file-format': 'JUNITXML', + 'files': [ + '**/*', + ], + }, + }, + }), + grantReportGroupPermissions: false, +}); + +reportGroupTest.grantWrite(project); + +new integ.IntegTest(app, 'ReportGroupDeleteReportsIntegTest', { + testCases: [stack], +}); + +app.synth(); diff --git a/packages/aws-cdk-lib/aws-codebuild/README.md b/packages/aws-cdk-lib/aws-codebuild/README.md index 9f96d90097cd0..5d683459cd736 100644 --- a/packages/aws-cdk-lib/aws-codebuild/README.md +++ b/packages/aws-cdk-lib/aws-codebuild/README.md @@ -302,7 +302,7 @@ can use the `environment` property to customize the build environment: The CodeBuild library supports both Linux and Windows images via the `LinuxBuildImage` (or `LinuxArmBuildImage`), and `WindowsBuildImage` classes, respectively. -With the introduction of Lambda compute support, the `LinuxLambdaBuildImage ` (or `LinuxArmLambdaBuildImage`) class +With the introduction of Lambda compute support, the `LinuxLambdaBuildImage ` (or `LinuxArmLambdaBuildImage`) class is available for specifying Lambda-compatible images. You can specify one of the predefined Windows/Linux images by using one @@ -619,6 +619,27 @@ The created policy will adjust to the report group type. If no type is specified For more information on the test reports feature, see the [AWS CodeBuild documentation](https://docs.aws.amazon.com/codebuild/latest/userguide/test-reporting.html). +### Report group deletion + +When a report group is removed from a stack (or the stack is deleted), the report +group will be removed according to its removal policy (which by default will +simply orphan the report group and leave it in your AWS account). If the removal +policy is set to `RemovalPolicy.DESTROY`, the report group will be deleted as long +as it does not contain any reports. + +To override this and force all reports to get deleted during report group deletion, +enable the `deleteReports` option as well as setting the removal policy to +`RemovalPolicy.DESTROY`. + +```ts +import * as cdk from 'aws-cdk-lib'; + +const reportGroup = new codebuild.ReportGroup(this, 'ReportGroup', { + removalPolicy: cdk.RemovalPolicy.DESTROY, + deleteReports: true, +}); +``` + ## Events CodeBuild projects can be used either as a source for events or be triggered diff --git a/packages/aws-cdk-lib/aws-codebuild/lib/report-group.ts b/packages/aws-cdk-lib/aws-codebuild/lib/report-group.ts index aa577cd79952d..234cf8e5d6c22 100644 --- a/packages/aws-cdk-lib/aws-codebuild/lib/report-group.ts +++ b/packages/aws-cdk-lib/aws-codebuild/lib/report-group.ts @@ -119,6 +119,13 @@ export interface ReportGroupProps { * @default TEST */ readonly type?: ReportGroupType; + + /** + * If true, deleting the report group force deletes the contents of the report group. If false, the report group must be empty before attempting to delete it. + * + * @default false + */ + readonly deleteReports?: boolean; } /** @@ -165,6 +172,7 @@ export class ReportGroup extends ReportGroupBase { : undefined, }, name: props.reportGroupName, + deleteReports: props.deleteReports, }); resource.applyRemovalPolicy(props.removalPolicy, { default: cdk.RemovalPolicy.RETAIN, @@ -177,5 +185,9 @@ export class ReportGroup extends ReportGroupBase { cdk.Fn.select(1, cdk.Fn.split('/', resource.ref)), ); this.exportBucket = props.exportBucket; + + if (props.deleteReports && props.removalPolicy !== cdk.RemovalPolicy.DESTROY) { + throw new Error('Cannot use \'deleteReports\' property on a report group without setting removal policy to \'DESTROY\'.'); + } } } diff --git a/packages/aws-cdk-lib/aws-codebuild/test/report-group.test.ts b/packages/aws-cdk-lib/aws-codebuild/test/report-group.test.ts index fefa664e9ba6a..fa58c3cc73554 100644 --- a/packages/aws-cdk-lib/aws-codebuild/test/report-group.test.ts +++ b/packages/aws-cdk-lib/aws-codebuild/test/report-group.test.ts @@ -242,4 +242,29 @@ describe('Test Reports Groups', () => { }, }); }); + + test('report group with deleteReports enabled', () => { + const stack = new cdk.Stack(); + + new codebuild.ReportGroup(stack, 'ReportGroup', { + deleteReports: true, + removalPolicy: cdk.RemovalPolicy.DESTROY, + }); + + Template.fromStack(stack).hasResourceProperties('AWS::CodeBuild::ReportGroup', { + "DeleteReports": true, + }); + }); + + test('deleteReports requires \'RemovalPolicy.DESTROY\'', () => { + const stack = new cdk.Stack(); + + expect(() => { + new codebuild.ReportGroup(stack, 'ReportGroup', { + deleteReports: true, + }); + }, + ).toThrow('Cannot use \'deleteReports\' property on a report group without setting removal policy to \'DESTROY\'.'); + }); + });