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

aws-codebuild: Project secondaryArtifacts not removed from resource when property is removed #33300

Open
1 task
rahuldeverani opened this issue Feb 5, 2025 · 2 comments
Labels
@aws-cdk/aws-codebuild Related to AWS CodeBuild bug This issue is a bug. closing-soon This issue will automatically close in 4 days unless further comments are made. effort/medium Medium work item – several days of effort p3 response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.

Comments

@rahuldeverani
Copy link

rahuldeverani commented Feb 5, 2025

Describe the bug

In CodeBuild Project , if secondary artifacts are removed from CDK code, secondary artifacts are not removed from the resource. This issue is occurring because CDK removes the secondary artifact from the CFN template from the template when this is commented in cdk code.

There seems to be limitation with CFN resource 'AWS::CodeBuild::Project' where to unset or remove a project value via CFN, explicitly provide the attribute with value as empty input : https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-codebuild-project.html

So CDK should synthsize the template such that, if the secondary artifact is removed from code during update, then the synthesised template should have SecondaryArtifacts as []. This would unset the property.

Regression Issue

  • Select this option if this issue appears to be a regression.

Last Known Working CDK Version

No response

Expected Behavior

Secondary artifacts must be removed from the project.

Current Behavior

Secondary artifacts are not getting removed.

Reproduction Steps

Code to replicate:

import * as cdk from 'aws-cdk-lib';
import { Construct } from 'constructs';
import * as s3 from 'aws-cdk-lib/aws-s3';
import * as codecommit from 'aws-cdk-lib/aws-codecommit';
import * as codebuild from 'aws-cdk-lib/aws-codebuild';


export class CdknewStack extends cdk.Stack {
  constructor(scope: Construct, id: string, props?: cdk.StackProps) {
    super(scope, id, props);

    const primaryArtifactBucket = new s3.Bucket(this, 'PrimaryArtifactBucket', {
      removalPolicy: cdk.RemovalPolicy.DESTROY,
      autoDeleteObjects: true,
      versioned: true,
    });

    const secondaryArtifactBucket = new s3.Bucket(this, 'SecondaryArtifactBucket', {
      removalPolicy: cdk.RemovalPolicy.DESTROY,
      autoDeleteObjects: true,
      versioned: true,
    });
    const buildProject = new codebuild.Project(this, 'BuildProject', {
      projectName: 'multi-artifact-project',
      buildSpec: codebuild.BuildSpec.fromObjectToYaml({
        version: '0.2',
        phases: {
          build: {
            commands: [
              'echo "Building primary and secondary artifacts"',
              'mkdir -p primary-output/',
              'mkdir -p secondary-output/',
              'echo "Primary content" > primary-output/primary.txt',
              'echo "Secondary content" > secondary-output/secondary.txt',
            ],
          },
        },
        artifacts: {
          files: ['**/*'],
          'base-directory': 'primary-output',
        },
        secondaryArtifacts: [
          {
            artifactIdentifier: 'SecondaryArtifact',
            files: ['**/*'],
            'base-directory': 'secondary-output',
          },
        ],
      }),
      artifacts: codebuild.Artifacts.s3({
        bucket: primaryArtifactBucket,
        includeBuildId: true,
        packageZip: true,
        path: 'primary',
      }),
     secondaryArtifacts: [
        codebuild.Artifacts.s3({
          bucket: secondaryArtifactBucket,
          identifier: 'SecondaryArtifact',
          includeBuildId: true,
          packageZip: true,
          path: 'secondary',
        }),
     ],
      environment: {
        buildImage: codebuild.LinuxBuildImage.AMAZON_LINUX_2_4,
      },
    });

    primaryArtifactBucket.grantReadWrite(buildProject);
   // secondaryArtifactBucket.grantReadWrite(buildProject);

  }}

After the stack is created from above code. Comment or remove secondaryArtifacts from the code and update the stack.

Possible Solution

CDK should synthsize the template such that, if the secondary artifact is removed from code during update, then the synthesised template should have SecondaryArtifacts as []. This would unset the property.

Additional Information/Context

No response

CDK CLI Version

2.175.1

Framework Version

No response

Node.js Version

v23.1.0

OS

MacOs

Language

TypeScript

Language Version

No response

Other information

No response

@rahuldeverani rahuldeverani added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Feb 5, 2025
@github-actions github-actions bot added the @aws-cdk/aws-codebuild Related to AWS CodeBuild label Feb 5, 2025
@pahud pahud self-assigned this Feb 5, 2025
@pahud
Copy link
Contributor

pahud commented Feb 5, 2025

Did you mean after initial deploy, now if you comment off this

  secondaryArtifacts: [
        codebuild.Artifacts.s3({
          bucket: secondaryArtifactBucket,
          identifier: 'SecondaryArtifact',
          includeBuildId: true,
          packageZip: true,
          path: 'secondary',
        }),
     ],

cdk synth would not remove the SecondaryArtifacts prop?

Can you share what you are seeing with cdk diff ?

@pahud pahud added p2 effort/medium Medium work item – several days of effort labels Feb 5, 2025
@pahud pahud removed their assignment Feb 5, 2025
@pahud pahud added p3 response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. and removed p2 needs-triage This issue or PR still needs to be triaged. labels Feb 5, 2025
Copy link

github-actions bot commented Feb 7, 2025

This issue has not received a response in a while. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.

@github-actions github-actions bot added the closing-soon This issue will automatically close in 4 days unless further comments are made. label Feb 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-codebuild Related to AWS CodeBuild bug This issue is a bug. closing-soon This issue will automatically close in 4 days unless further comments are made. effort/medium Medium work item – several days of effort p3 response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.
Projects
None yet
Development

No branches or pull requests

2 participants