(codebuild): removing vpc from codebuild project will not actually remove the vpc configuration
- Dominant language
- TypeScript
- Stars
- 12.9k
- Forks
- 4.6k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 83
Description
### Describe the bug
If you build a CodeBuild Project first with a vpc and deploy, then remove the vpc and perform the second deploy, the related IAM permission would be removed but the vpc remains in the CodeBuild Project's configuration.
Below is a simple example that I can use to reproduce the problem
```
export class MyStack extends Stack {
constructor(scope: Construct, id: string, props: StackProps = {}) {
super(scope, id, props);
const vpc = ec2.Vpc.fromLookup(this, "Vpc", {
vpcId: "vpc-12345678", // any valid vpc id in the target account
});
new codebuild.Project(this, "Project", {
// vpc,
buildSpec: codebuild.BuildSpec.fromObject({
version: "0.2",
env: {},
phases: {
build: {
commands: 'echo "Hello World!"',
},
},
}),
});
}
}
```
This is problematic especially with pipeline, because the pipeline would fail because it can't perform `ec2:DescribeNetworkInterfaces` on the vpc and the project fails during Queue time.
### Expected Behavior
The VPC configuration be cleared from the CodeBuild Project.
### Current Behavior
The VPC configuration remains in the CodeBuild Project according to console and cli.
### Reproduction Steps
First deploy this
```
export class MyStack extends Stack {
constructor(scope: Construct, id: string, props: StackProps = {}) {
super(scope, id, props);
const vpc = ec2.Vpc.fromLookup(this, "Vpc", {
vpcId: "vpc-12345678", // any valid vpc id in the target account
});
new codebuild.Project(this, "Project", {
vpc,
buildSpec: codebuild.BuildSpec.fromObject({
version: "0.2",
env: {},
phases: {
build: {
commands: 'echo "Hello World!"',
},
},
}),
});
}
}
```
then deploy this
```
export class MyStack extends Stack {
constructor(scope: Construct, id: string, props: StackProps = {}) {
super(scope, id, props);
ec2.Vpc.fromLookup(this, "Vpc", {
vpcId: "vpc-12345678", // any valid vpc id in the target account
});
new codebuild.Project(this, "Project", {
// vpc,
buildSpec: codebuild.BuildSpec.fromObject({
version: "0.2",
env: {},
phases: {
build: {
commands: 'echo "Hello World!"',
},
},
}),
});
}
}
```
The second deploy would remove the Project role's ability to perform various ec2 actions, including `ec2:DescribeNetworkInterfaces`. But the vpc configuration remains in the Project (according to console as well as aws cli)
### Possible Solution
_No response_
### Additional Information/Context
_No response_
### CDK CLI Version
2.50.0
### Framework Version
_No response_
### Node.js Version
v18.6.0
### OS
MacOS
### Language
Typescript
### Language Version
_No response_
### Other information
_No response_
Contributor guide
Research direction
Reproduce the issue by deploying the CodeBuild project first with a VPC and then without one, using the TypeScript examples in the report. Inspect the generated project update and verify the AWS console or CLI; done means the VPC configuration and related permissions are both cleared after the second deployment.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, typescript
- Domain
- cloud, devops, infrastructure
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100