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

fix(ec2): Cannot deploy VPC flow log with other resources that requires bucket policies #23889

Merged
merged 3 commits into from
Jan 31, 2023

Conversation

tmokmss
Copy link
Contributor

@tmokmss tmokmss commented Jan 28, 2023

Closes #18985.

The problem is described on the issue. In short, when we enable VPC Flow log, it tries to create a bucket policy for the target S3 bucket. That's why a deployment fails if there is a bucket policy defined in a CFn template and the policy is created AFTER a flow log is enabled, which cannot replace the existing policy created by the flow log.

To avoid the error, this PR adds explicit dependencies for a VPC flow log resource:

  • dependency 1: Flow log must be created after a corresponding bucket policy is created by CFn
  • dependency 2: Flow log must be deleted before a corresponding autoDeleteObjects custom resource removed (i.e. deleting all the objects in the bucket).

Dependency 2 is actually not related to the original issue, but I'd like to add this because I saw the error relating this on the integration tests.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@gitpod-io
Copy link

gitpod-io bot commented Jan 28, 2023

@github-actions github-actions bot added bug This issue is a bug. p2 admired-contributor [Pilot] contributed between 13-24 PRs to the CDK labels Jan 28, 2023
@aws-cdk-automation aws-cdk-automation requested a review from a team January 28, 2023 04:14
@comcalvi comcalvi self-assigned this Jan 30, 2023
Copy link
Contributor

@comcalvi comcalvi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR, this is great!

Could you add the stack you included as reproduction steps as a new stack in packages/@aws-cdk/aws-ec2/test/integ.vpc-flow-logs.ts?

It's this code:

import * as cdk from 'aws-cdk-lib';
import { RemovalPolicy, Stack } from 'aws-cdk-lib';
import { FlowLogDestination, Vpc } from 'aws-cdk-lib/aws-ec2';
import { Bucket } from 'aws-cdk-lib/aws-s3';

const stack = new Stack(new cdk.App(), "Stack");

const vpc = new Vpc(stack, 'Vpc', {
  natGateways: 1,
});

const logBucket = new Bucket(stack, 'LogBucket', {
  autoDeleteObjects: true,
  removalPolicy: RemovalPolicy.DESTROY,
});

vpc.addFlowLog('FlowLogS3', {
  destination: FlowLogDestination.toS3(logBucket, 'vpcFlowLog'),
});

@mergify mergify bot dismissed comcalvi’s stale review January 31, 2023 00:32

Pull request has been modified.

@tmokmss
Copy link
Contributor Author

tmokmss commented Jan 31, 2023

Hi @comcalvi, thanks for the review! I added the integ test.

I also added { natGateways: 1 } for each VPCs because otherwise 6 EIPs are required to run the test, which exceeds he default quota for #of EIPs (5), and thus cannot be deployed easily.

@mergify
Copy link
Contributor

mergify bot commented Jan 31, 2023

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: 7dfac61
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify mergify bot merged commit e646ad5 into aws:main Jan 31, 2023
@mergify
Copy link
Contributor

mergify bot commented Jan 31, 2023

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
admired-contributor [Pilot] contributed between 13-24 PRs to the CDK bug This issue is a bug. p2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

(ec2): Cannot deploy VPC flow log with other resources that requires bucket policies
3 participants