From 861f8df8bcb3183601bc59a841bb590d347e4201 Mon Sep 17 00:00:00 2001 From: watany <76135106+watany-dev@users.noreply.github.com> Date: Fri, 21 Jun 2024 08:41:10 +0900 Subject: [PATCH] feat(codebuild): adding `project.visibility` (#30103) ### Reason for this change missing property ### Description of changes https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_codebuild.CfnProjectProps.html#visibility ### Description of how you validated changes done test and integ-test ### 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* --- ...efaultTestDeployAssert1C40A7EB.assets.json | 19 + ...aultTestDeployAssert1C40A7EB.template.json | 36 ++ .../cdk.out | 1 + .../codebuild-visibility.assets.json | 19 + .../codebuild-visibility.template.json | 237 +++++++++++ .../integ.json | 13 + .../manifest.json | 131 ++++++ .../tree.json | 379 ++++++++++++++++++ .../test/integ.project-visibility.ts | 33 ++ packages/aws-cdk-lib/aws-codebuild/README.md | 15 + .../aws-cdk-lib/aws-codebuild/lib/project.ts | 23 ++ .../aws-codebuild/test/project.test.ts | 30 ++ 12 files changed, 936 insertions(+) create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-codebuild/test/integ.project-visibility.js.snapshot/VisibilityDefaultTestDeployAssert1C40A7EB.assets.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-codebuild/test/integ.project-visibility.js.snapshot/VisibilityDefaultTestDeployAssert1C40A7EB.template.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-codebuild/test/integ.project-visibility.js.snapshot/cdk.out create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-codebuild/test/integ.project-visibility.js.snapshot/codebuild-visibility.assets.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-codebuild/test/integ.project-visibility.js.snapshot/codebuild-visibility.template.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-codebuild/test/integ.project-visibility.js.snapshot/integ.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-codebuild/test/integ.project-visibility.js.snapshot/manifest.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-codebuild/test/integ.project-visibility.js.snapshot/tree.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-codebuild/test/integ.project-visibility.ts diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-codebuild/test/integ.project-visibility.js.snapshot/VisibilityDefaultTestDeployAssert1C40A7EB.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-codebuild/test/integ.project-visibility.js.snapshot/VisibilityDefaultTestDeployAssert1C40A7EB.assets.json new file mode 100644 index 0000000000000..b960595fc2bb4 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-codebuild/test/integ.project-visibility.js.snapshot/VisibilityDefaultTestDeployAssert1C40A7EB.assets.json @@ -0,0 +1,19 @@ +{ + "version": "36.0.0", + "files": { + "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22": { + "source": { + "path": "VisibilityDefaultTestDeployAssert1C40A7EB.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.project-visibility.js.snapshot/VisibilityDefaultTestDeployAssert1C40A7EB.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-codebuild/test/integ.project-visibility.js.snapshot/VisibilityDefaultTestDeployAssert1C40A7EB.template.json new file mode 100644 index 0000000000000..ad9d0fb73d1dd --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-codebuild/test/integ.project-visibility.js.snapshot/VisibilityDefaultTestDeployAssert1C40A7EB.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.project-visibility.js.snapshot/cdk.out b/packages/@aws-cdk-testing/framework-integ/test/aws-codebuild/test/integ.project-visibility.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.project-visibility.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.project-visibility.js.snapshot/codebuild-visibility.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-codebuild/test/integ.project-visibility.js.snapshot/codebuild-visibility.assets.json new file mode 100644 index 0000000000000..f383015252684 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-codebuild/test/integ.project-visibility.js.snapshot/codebuild-visibility.assets.json @@ -0,0 +1,19 @@ +{ + "version": "36.0.0", + "files": { + "9aed8fc879889a75e3a97bd32015b93227c5fc0eaf4a5597908bd6eea9d84e03": { + "source": { + "path": "codebuild-visibility.template.json", + "packaging": "file" + }, + "destinations": { + "current_account-current_region": { + "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", + "objectKey": "9aed8fc879889a75e3a97bd32015b93227c5fc0eaf4a5597908bd6eea9d84e03.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.project-visibility.js.snapshot/codebuild-visibility.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-codebuild/test/integ.project-visibility.js.snapshot/codebuild-visibility.template.json new file mode 100644 index 0000000000000..ad99d88e5c723 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-codebuild/test/integ.project-visibility.js.snapshot/codebuild-visibility.template.json @@ -0,0 +1,237 @@ +{ + "Resources": { + "MyBucketF68F3FF0": { + "Type": "AWS::S3::Bucket", + "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": [ + "s3:GetBucket*", + "s3:GetObject*", + "s3:List*" + ], + "Effect": "Allow", + "Resource": [ + { + "Fn::GetAtt": [ + "MyBucketF68F3FF0", + "Arn" + ] + }, + { + "Fn::Join": [ + "", + [ + { + "Fn::GetAtt": [ + "MyBucketF68F3FF0", + "Arn" + ] + }, + "/path/to/my/source.zip" + ] + ] + } + ] + }, + { + "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:BatchPutCodeCoverages", + "codebuild:BatchPutTestCases", + "codebuild:CreateReport", + "codebuild:CreateReportGroup", + "codebuild:UpdateReport" + ], + "Effect": "Allow", + "Resource": { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":codebuild:", + { + "Ref": "AWS::Region" + }, + ":", + { + "Ref": "AWS::AccountId" + }, + ":report-group/", + { + "Ref": "MyProject39F7B0AE" + }, + "-*" + ] + ] + } + } + ], + "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": { + "Location": { + "Fn::Join": [ + "", + [ + { + "Ref": "MyBucketF68F3FF0" + }, + "/path/to/my/source.zip" + ] + ] + }, + "Type": "S3" + }, + "Visibility": "PUBLIC_READ" + } + } + }, + "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.project-visibility.js.snapshot/integ.json b/packages/@aws-cdk-testing/framework-integ/test/aws-codebuild/test/integ.project-visibility.js.snapshot/integ.json new file mode 100644 index 0000000000000..6356edd3c2c3a --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-codebuild/test/integ.project-visibility.js.snapshot/integ.json @@ -0,0 +1,13 @@ +{ + "version": "36.0.0", + "testCases": { + "Visibility/DefaultTest": { + "stacks": [ + "codebuild-visibility" + ], + "stackUpdateWorkflow": true, + "assertionStack": "Visibility/DefaultTest/DeployAssert", + "assertionStackName": "VisibilityDefaultTestDeployAssert1C40A7EB" + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-codebuild/test/integ.project-visibility.js.snapshot/manifest.json b/packages/@aws-cdk-testing/framework-integ/test/aws-codebuild/test/integ.project-visibility.js.snapshot/manifest.json new file mode 100644 index 0000000000000..4a8c91ad33aac --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-codebuild/test/integ.project-visibility.js.snapshot/manifest.json @@ -0,0 +1,131 @@ +{ + "version": "36.0.0", + "artifacts": { + "codebuild-visibility.assets": { + "type": "cdk:asset-manifest", + "properties": { + "file": "codebuild-visibility.assets.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "codebuild-visibility": { + "type": "aws:cloudformation:stack", + "environment": "aws://unknown-account/unknown-region", + "properties": { + "templateFile": "codebuild-visibility.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}/9aed8fc879889a75e3a97bd32015b93227c5fc0eaf4a5597908bd6eea9d84e03.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", + "additionalDependencies": [ + "codebuild-visibility.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": [ + "codebuild-visibility.assets" + ], + "metadata": { + "/codebuild-visibility/MyBucket/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "MyBucketF68F3FF0" + } + ], + "/codebuild-visibility/MyProject/Role/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "MyProjectRole9BBE5233" + } + ], + "/codebuild-visibility/MyProject/Role/DefaultPolicy/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "MyProjectRoleDefaultPolicyB19B7C29" + } + ], + "/codebuild-visibility/MyProject/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "MyProject39F7B0AE" + } + ], + "/codebuild-visibility/BootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "BootstrapVersion" + } + ], + "/codebuild-visibility/CheckBootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "CheckBootstrapVersion" + } + ] + }, + "displayName": "codebuild-visibility" + }, + "VisibilityDefaultTestDeployAssert1C40A7EB.assets": { + "type": "cdk:asset-manifest", + "properties": { + "file": "VisibilityDefaultTestDeployAssert1C40A7EB.assets.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "VisibilityDefaultTestDeployAssert1C40A7EB": { + "type": "aws:cloudformation:stack", + "environment": "aws://unknown-account/unknown-region", + "properties": { + "templateFile": "VisibilityDefaultTestDeployAssert1C40A7EB.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": [ + "VisibilityDefaultTestDeployAssert1C40A7EB.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": [ + "VisibilityDefaultTestDeployAssert1C40A7EB.assets" + ], + "metadata": { + "/Visibility/DefaultTest/DeployAssert/BootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "BootstrapVersion" + } + ], + "/Visibility/DefaultTest/DeployAssert/CheckBootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "CheckBootstrapVersion" + } + ] + }, + "displayName": "Visibility/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.project-visibility.js.snapshot/tree.json b/packages/@aws-cdk-testing/framework-integ/test/aws-codebuild/test/integ.project-visibility.js.snapshot/tree.json new file mode 100644 index 0000000000000..96e6a2824e7f3 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-codebuild/test/integ.project-visibility.js.snapshot/tree.json @@ -0,0 +1,379 @@ +{ + "version": "tree-0.1", + "tree": { + "id": "App", + "path": "", + "children": { + "codebuild-visibility": { + "id": "codebuild-visibility", + "path": "codebuild-visibility", + "children": { + "MyBucket": { + "id": "MyBucket", + "path": "codebuild-visibility/MyBucket", + "children": { + "Resource": { + "id": "Resource", + "path": "codebuild-visibility/MyBucket/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::S3::Bucket", + "aws:cdk:cloudformation:props": {} + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_s3.CfnBucket", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_s3.Bucket", + "version": "0.0.0" + } + }, + "MyProject": { + "id": "MyProject", + "path": "codebuild-visibility/MyProject", + "children": { + "Role": { + "id": "Role", + "path": "codebuild-visibility/MyProject/Role", + "children": { + "ImportRole": { + "id": "ImportRole", + "path": "codebuild-visibility/MyProject/Role/ImportRole", + "constructInfo": { + "fqn": "aws-cdk-lib.Resource", + "version": "0.0.0" + } + }, + "Resource": { + "id": "Resource", + "path": "codebuild-visibility/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": "aws-cdk-lib.aws_iam.CfnRole", + "version": "0.0.0" + } + }, + "DefaultPolicy": { + "id": "DefaultPolicy", + "path": "codebuild-visibility/MyProject/Role/DefaultPolicy", + "children": { + "Resource": { + "id": "Resource", + "path": "codebuild-visibility/MyProject/Role/DefaultPolicy/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::IAM::Policy", + "aws:cdk:cloudformation:props": { + "policyDocument": { + "Statement": [ + { + "Action": [ + "s3:GetBucket*", + "s3:GetObject*", + "s3:List*" + ], + "Effect": "Allow", + "Resource": [ + { + "Fn::GetAtt": [ + "MyBucketF68F3FF0", + "Arn" + ] + }, + { + "Fn::Join": [ + "", + [ + { + "Fn::GetAtt": [ + "MyBucketF68F3FF0", + "Arn" + ] + }, + "/path/to/my/source.zip" + ] + ] + } + ] + }, + { + "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:BatchPutCodeCoverages", + "codebuild:BatchPutTestCases", + "codebuild:CreateReport", + "codebuild:CreateReportGroup", + "codebuild:UpdateReport" + ], + "Effect": "Allow", + "Resource": { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":codebuild:", + { + "Ref": "AWS::Region" + }, + ":", + { + "Ref": "AWS::AccountId" + }, + ":report-group/", + { + "Ref": "MyProject39F7B0AE" + }, + "-*" + ] + ] + } + } + ], + "Version": "2012-10-17" + }, + "policyName": "MyProjectRoleDefaultPolicyB19B7C29", + "roles": [ + { + "Ref": "MyProjectRole9BBE5233" + } + ] + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_iam.CfnPolicy", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_iam.Policy", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_iam.Role", + "version": "0.0.0" + } + }, + "Resource": { + "id": "Resource", + "path": "codebuild-visibility/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": "S3", + "location": { + "Fn::Join": [ + "", + [ + { + "Ref": "MyBucketF68F3FF0" + }, + "/path/to/my/source.zip" + ] + ] + } + }, + "visibility": "PUBLIC_READ" + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_codebuild.CfnProject", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_codebuild.Project", + "version": "0.0.0" + } + }, + "BootstrapVersion": { + "id": "BootstrapVersion", + "path": "codebuild-visibility/BootstrapVersion", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnParameter", + "version": "0.0.0" + } + }, + "CheckBootstrapVersion": { + "id": "CheckBootstrapVersion", + "path": "codebuild-visibility/CheckBootstrapVersion", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnRule", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.Stack", + "version": "0.0.0" + } + }, + "Visibility": { + "id": "Visibility", + "path": "Visibility", + "children": { + "DefaultTest": { + "id": "DefaultTest", + "path": "Visibility/DefaultTest", + "children": { + "Default": { + "id": "Default", + "path": "Visibility/DefaultTest/Default", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + }, + "DeployAssert": { + "id": "DeployAssert", + "path": "Visibility/DefaultTest/DeployAssert", + "children": { + "BootstrapVersion": { + "id": "BootstrapVersion", + "path": "Visibility/DefaultTest/DeployAssert/BootstrapVersion", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnParameter", + "version": "0.0.0" + } + }, + "CheckBootstrapVersion": { + "id": "CheckBootstrapVersion", + "path": "Visibility/DefaultTest/DeployAssert/CheckBootstrapVersion", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnRule", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.Stack", + "version": "0.0.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": "aws-cdk-lib.App", + "version": "0.0.0" + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-codebuild/test/integ.project-visibility.ts b/packages/@aws-cdk-testing/framework-integ/test/aws-codebuild/test/integ.project-visibility.ts new file mode 100644 index 0000000000000..120b748762b6e --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-codebuild/test/integ.project-visibility.ts @@ -0,0 +1,33 @@ +#!/usr/bin/env node +import { App, Stack, RemovalPolicy } from 'aws-cdk-lib'; +import { Construct } from 'constructs'; +import * as s3 from 'aws-cdk-lib/aws-s3'; +import * as codebuild from 'aws-cdk-lib/aws-codebuild'; +import { IntegTest } from '@aws-cdk/integ-tests-alpha'; + +const app = new App(); + +class VisibilityTestStack extends Stack { + constructor(scope: Construct, id: string) { + super(scope, id); + + const bucket = new s3.Bucket(this, 'MyBucket', { + removalPolicy: RemovalPolicy.DESTROY, + }); + new codebuild.Project(this, 'MyProject', { + source: codebuild.Source.s3({ + bucket, + path: 'path/to/my/source.zip', + }), + visibility: codebuild.ProjectVisibility.PUBLIC_READ, + }); + } +} + +const visibilityTest = new VisibilityTestStack(app, 'codebuild-visibility'); + +new IntegTest(app, 'Visibility', { + testCases: [visibilityTest], + stackUpdateWorkflow: true, +}); + diff --git a/packages/aws-cdk-lib/aws-codebuild/README.md b/packages/aws-cdk-lib/aws-codebuild/README.md index 3dde80fa45528..625103d0a7215 100644 --- a/packages/aws-cdk-lib/aws-codebuild/README.md +++ b/packages/aws-cdk-lib/aws-codebuild/README.md @@ -946,3 +946,18 @@ new codebuild.Project(this, 'MyProject', { concurrentBuildLimit: 1 }); ``` + +## Visibility +When you can specify the visibility of the project builds. This setting controls whether the builds are publicly readable or remain private. + +Visibility options: +- `PUBLIC_READ`: The project builds are visible to the public. +- `PRIVATE`: The project builds are not visible to the public. + +Examples: + +```ts +new codebuild.Project(this, 'MyProject', { + visibility: codebuild.ProjectVisibility.PUBLIC_READ, +}); +``` \ No newline at end of file diff --git a/packages/aws-cdk-lib/aws-codebuild/lib/project.ts b/packages/aws-cdk-lib/aws-codebuild/lib/project.ts index 573a20cbcd366..a6f04fca4504a 100644 --- a/packages/aws-cdk-lib/aws-codebuild/lib/project.ts +++ b/packages/aws-cdk-lib/aws-codebuild/lib/project.ts @@ -727,6 +727,13 @@ export interface CommonProjectProps { * @default false */ readonly ssmSessionPermissions?: boolean; + + /** + * Specifies the visibility of the project's builds. + * + * @default - no visibility is set + */ + readonly visibility?: ProjectVisibility; } export interface ProjectProps extends CommonProjectProps { @@ -1126,6 +1133,7 @@ export class Project extends ProjectBase { triggers: sourceConfig.buildTriggers, sourceVersion: sourceConfig.sourceVersion, vpcConfig: this.configureVpc(props), + visibility: props.visibility, logsConfig: this.renderLoggingConfiguration(props.logging), buildBatchConfig: Lazy.any({ produce: () => { @@ -2268,6 +2276,21 @@ export enum BuildEnvironmentVariableType { SECRETS_MANAGER = 'SECRETS_MANAGER', } +/** + * Specifies the visibility of the project's builds. + */ +export enum ProjectVisibility { + /** + * The project builds are visible to the public. + */ + PUBLIC_READ = 'PUBLIC_READ', + + /** + * The project builds are not visible to the public. + */ + PRIVATE = 'PRIVATE', +} + /** * The list of event types for AWS Codebuild * @see https://docs.aws.amazon.com/dtconsole/latest/userguide/concepts.html#events-ref-buildproject diff --git a/packages/aws-cdk-lib/aws-codebuild/test/project.test.ts b/packages/aws-cdk-lib/aws-codebuild/test/project.test.ts index 17621c0b949e6..5fd1e8b0b9881 100644 --- a/packages/aws-cdk-lib/aws-codebuild/test/project.test.ts +++ b/packages/aws-cdk-lib/aws-codebuild/test/project.test.ts @@ -2019,6 +2019,36 @@ test('can automatically add ssm permissions', () => { }); }); +test('can Setting Visibility', () => { + // GIVEN + const stackPublic = new cdk.Stack(); + const stackPrivate = new cdk.Stack(); + + // WHEN + new codebuild.Project(stackPublic, 'ProjectPublic', { + source: codebuild.Source.s3({ + bucket: new s3.Bucket(stackPublic, 'Bucket-ProjectPublic'), + path: 'path', + }), + visibility: codebuild.ProjectVisibility.PUBLIC_READ, + }); + new codebuild.Project(stackPrivate, 'ProjectPrivate', { + source: codebuild.Source.s3({ + bucket: new s3.Bucket(stackPrivate, 'Bucket-ProjectPrivate'), + path: 'path', + }), + visibility: codebuild.ProjectVisibility.PRIVATE, + }); + + // THEN + Template.fromStack(stackPublic).hasResourceProperties('AWS::CodeBuild::Project', { + Visibility: 'PUBLIC_READ', + }); + Template.fromStack(stackPrivate).hasResourceProperties('AWS::CodeBuild::Project', { + Visibility: 'PRIVATE', + }); +}); + describe('can be imported', () => { test('by ARN', () => { const stack = new cdk.Stack();