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(apprunner-alpha): env vars and secrets can't solely be added via .add*() methods #24346

Merged
merged 9 commits into from
Mar 3, 2023

Conversation

rogerchi
Copy link
Contributor

This fixes the logic for rendering environment variables and environment secrets for the apprunner-alpha module. Previously, .addEnvironmentVariable() and .addSecret() were being ignored if there were not already "seed" values in the input props.

Closes #24345.


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

@github-actions github-actions bot added repeat-contributor [Pilot] contributed between 3-5 PRs to the CDK bug This issue is a bug. p2 labels Feb 27, 2023
@aws-cdk-automation aws-cdk-automation requested a review from a team February 27, 2023 05:21
Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

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

The pull request linter has failed. See the aws-cdk-automation comment below for failure reasons. If you believe this pull request should receive an exemption, please comment and provide a justification.

A comment requesting an exemption should contain the text Exemption Request. Additionally, if clarification is needed add Clarification Request to a comment.

@TheRealAmazonKendra
Copy link
Contributor

Please make sure that your PR title confirms to the conventional commit standard (fix, feat, chore) and that it is written in a style that will reflect correctly in the change log (See Contributing Guide, Pull Requests)

@aws-cdk-automation aws-cdk-automation dismissed their stale review March 1, 2023 03:23

✅ Updated pull request passes all PRLinter validations. Dissmissing previous PRLinter review.

@rogerchi
Copy link
Contributor Author

rogerchi commented Mar 1, 2023

Please make sure that your PR title confirms to the conventional commit standard (fix, feat, chore) and that it is written in a style that will reflect correctly in the change log (See Contributing Guide, Pull Requests)

I've updated the code, tests, and added a new integration test and snapshot.

@TheRealAmazonKendra
Copy link
Contributor

Please make sure that your PR title confirms to the conventional commit standard (fix, feat, chore) and that it is written in a style that will reflect correctly in the change log (See Contributing Guide, Pull Requests)

I've updated the code, tests, and added a new integration test and snapshot.

I'll take a look but please also address the message above.

@rogerchi rogerchi changed the title fix(apprunner-alpha): adding environment logic fix fix(apprunner-alpha): env vars and secrets can't solely be added via .add*() methods Mar 1, 2023
@github-actions github-actions bot added the effort/medium Medium work item – several days of effort label Mar 1, 2023
@rogerchi
Copy link
Contributor Author

rogerchi commented Mar 1, 2023

I'll take a look but please also address the message above.

Let me know if the new title works.

packages/@aws-cdk/aws-apprunner/test/service.test.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-apprunner/test/service.test.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-apprunner/test/service.test.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-apprunner/test/service.test.ts Outdated Show resolved Hide resolved
Comment on lines -1154 to -1162
if (Object.keys(this.environmentSecrets).length > 0 && this.instanceRole) {
for (const [key, value] of Object.entries(this.environmentSecrets)) {
if (key.startsWith('AWSAPPRUNNER')) {
throw new Error(`Environment secret key ${key} with a prefix of AWSAPPRUNNER is not allowed`);
}

value.grantRead(this.instanceRole);
this.secrets.push({ name: key, value: value.arn });
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why was this removed?

Copy link
Contributor Author

@rogerchi rogerchi Mar 2, 2023

Choose a reason for hiding this comment

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

The logic for throwing the error now happens in the .addSecret() method. And the prop secrets are added using the same .addSecret() method now, see lines 977:985. I followed the pattern that the lambda.Function construct established by using the .add* methods for both prop environment variables/secrets and ones added later using the .add* methods.

Comment on lines -1140 to -1146
if (Object.keys(this.environmentVariables).length > 0) {
for (const [key, value] of Object.entries(this.environmentVariables)) {
if (key.startsWith('AWSAPPRUNNER')) {
throw new Error(`Environment variable key ${key} with a prefix of AWSAPPRUNNER is not allowed`);
}
this.variables.push({ name: key, value: value });
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why was this removed?

Copy link
Contributor Author

@rogerchi rogerchi Mar 2, 2023

Choose a reason for hiding this comment

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

The logic for throwing the error now happens in the .addEnvironmentVariable() method (it was not catching variables that started with AWSAPPRUNNER if added through the .add*() methods.

Comment on lines -991 to -994
// generalte an IAM role only when environmentSecrets has values and props.instanceRole is undefined
this.instanceRole = (Object.keys(this.environmentSecrets).length > 0 && !this.props.instanceRole) ?
this.createInstanceRole() : this.props.instanceRole;

Copy link
Contributor

Choose a reason for hiding this comment

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

This same logic now needs to be performed lazily, no? Not entirely removed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is handled in lines 975, 1049, and then lazily produced in line 1000.

Copy link
Contributor

Choose a reason for hiding this comment

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

ah, I missed that. I see, nicely done.

Co-authored-by: Calvin Combs <66279577+comcalvi@users.noreply.github.com>
@mergify mergify bot dismissed comcalvi’s stale review March 2, 2023 01:16

Pull request has been modified.

@rogerchi
Copy link
Contributor Author

rogerchi commented Mar 2, 2023

@comcalvi I've tried to address/answer all of your comments. Let me know if there's any further suggestions or clarifications required!

@rogerchi rogerchi requested a review from comcalvi March 3, 2023 01:50
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.

nice work!

Comment on lines -991 to -994
// generalte an IAM role only when environmentSecrets has values and props.instanceRole is undefined
this.instanceRole = (Object.keys(this.environmentSecrets).length > 0 && !this.props.instanceRole) ?
this.createInstanceRole() : this.props.instanceRole;

Copy link
Contributor

Choose a reason for hiding this comment

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

ah, I missed that. I see, nicely done.

@mergify
Copy link
Contributor

mergify bot commented Mar 3, 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: dd23bb4
  • 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 45195b6 into aws:main Mar 3, 2023
@mergify
Copy link
Contributor

mergify bot commented Mar 3, 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).

@rogerchi rogerchi deleted the fix/apprunner-env-vars branch March 6, 2023 00:26
homakk pushed a commit to homakk/aws-cdk that referenced this pull request Mar 28, 2023
….add*() methods (aws#24346)

This fixes the logic for rendering environment variables and environment secrets for the `apprunner-alpha` module.  Previously, `.addEnvironmentVariable()` and `.addSecret()` were being ignored if there were not already "seed" values in the input props.

Closes aws#24345.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. effort/medium Medium work item – several days of effort p2 repeat-contributor [Pilot] contributed between 3-5 PRs to the CDK
Projects
None yet
Development

Successfully merging this pull request may close these issues.

(apprunner-alpha): only using .addEnvrionmentVariable() and .addSecret() fails to work
4 participants