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(codedeploy): DeploymentGroup's physical name not propagated to Application #13582

Merged
merged 4 commits into from
Mar 22, 2021

Conversation

BLasan
Copy link
Contributor

@BLasan BLasan commented Mar 14, 2021

fixes #13337


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 Mar 14, 2021

@github-actions github-actions bot added the @aws-cdk/aws-codedeploy Related to AWS CodeDeploy label Mar 14, 2021
@BLasan BLasan force-pushed the issue-13337 branch 2 times, most recently from 198c2e5 to fdb8af8 Compare March 14, 2021 08:07
@BLasan
Copy link
Contributor Author

BLasan commented Mar 14, 2021

@skinny85 Please review

@@ -269,7 +269,7 @@ export class ServerDeploymentGroup extends ServerDeploymentGroupBase {
physicalName: props.deploymentGroupName,
});

this.application = props.application || new ServerApplication(this, 'Application');
this.application = props.application || new ServerApplication(this, this.physicalName);
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not the right fix for this issue. The fix is that if the parent DeploymentGroup has a PhysicalName.GENERATE_IF_NEEDED, so should the ServerApplication.

The poster suggested as much under Expected Result.

Also the title of this PR doesn't cover the change it's making. The title as written makes it sound as if no Application was created before, whereas now there is. This is not true though, an Application was already being created before.

We generally also write the PR title in terms of things the user would care about, and specifically for fixes it describes the bug that is now fixed (users will see these titles in the CHANGELOG, so think about what would make sense to them when viewed there).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rix0rrr Thanks for the review. I made the changes. Please have a look

@skinny85 skinny85 assigned rix0rrr and unassigned skinny85 Mar 15, 2021
@mergify mergify bot dismissed rix0rrr’s stale review March 16, 2021 07:47

Pull request has been modified.

@@ -4,6 +4,7 @@ import * as ec2 from '@aws-cdk/aws-ec2';
import * as iam from '@aws-cdk/aws-iam';
import * as s3 from '@aws-cdk/aws-s3';
import * as cdk from '@aws-cdk/core';
import { isGeneratedWhenNeededMarker } from '@aws-cdk/core/lib/private/physical-name-generator';
Copy link
Contributor

Choose a reason for hiding this comment

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

You can't import this in this way. This looks like it's a private function. Either import from @aws-cdk/core directory, or if it's not exported there, you can't import this at all.

I'm guessing name == PhysicalName.GENERATE_IF_NEEDED should just work, did you try that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I initially tried cdk.PhysicalName.GENERATE_IF_NEEDED . But after going through the logic resides inside the resources.ts file, I came up with this logic :) I hope name == PhysicalName.GENERATE_IF_NEEDED would work fine. will changes that

@@ -269,7 +270,11 @@ export class ServerDeploymentGroup extends ServerDeploymentGroupBase {
physicalName: props.deploymentGroupName,
});

this.application = props.application || new ServerApplication(this, 'Application');
if (props.deploymentGroupName && isGeneratedWhenNeededMarker(props.deploymentGroupName)) {
this.application = new ServerApplication(this, this.physicalName);
Copy link
Contributor

Choose a reason for hiding this comment

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

You are changing the construct ID, not the resource name. The construct ID needs to stay consistent (and cannot be a token). The resource name is a property and CAN be a token.

The pattern always looks like this:

new Resource(this, 'ResourceId', {   // <--- id
  resourceName: 'resourceName'  // <--- name
});

deploymentGroupName: physical_name,
});

test.notEqual(deploymentGroup, undefined);
Copy link
Contributor

Choose a reason for hiding this comment

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

The test you want to write here is that there is an AWS::CodeDeploy::Application with a specific ApplicationName property.

Look into using haveResource assertions.

@mergify mergify bot dismissed rix0rrr’s stale review March 16, 2021 09:22

Pull request has been modified.

@BLasan
Copy link
Contributor Author

BLasan commented Mar 16, 2021

@rix0rrr Please review

@BLasan BLasan changed the title fix(aws-codedeploy): implicitly create application in ServerDeploymentGroup fix(aws-codedeploy): deploymentgroup creation with physicalname_generate_if_needed Mar 16, 2021
deploymentGroupName: cdk.PhysicalName.GENERATE_IF_NEEDED,
});

expect(stack).to(haveResource('AWS::CodeDeploy::DeploymentGroup', {
Copy link
Contributor

Choose a reason for hiding this comment

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

You need to be asserting something about the AWS::CodeDeploy::Application, not the DeploymentGroup.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yuh, but there won't be a field called ApplicationName in the output. That fails the build.

Copy link
Contributor

@rix0rrr rix0rrr Mar 16, 2021

Choose a reason for hiding this comment

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

Then the issue is not fixed. That is what the desired output needs to be.

If it's not that, then we need to change code until it is.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

- Field ApplicationName missing in:
    {
      "Type": "AWS::CodeDeploy::Application",
      "Properties": {
        "ComputePlatform": "Server"
      }
    }

output for the test case with the resource type AWS::CodeDeploy:;DeploymentGroup. Same output will be received when the resource type of can be created by explicitly passing an Application test changed

@mergify mergify bot dismissed rix0rrr’s stale review March 16, 2021 20:10

Pull request has been modified.

@BLasan BLasan force-pushed the issue-13337 branch 2 times, most recently from 6f5622a to 36020c4 Compare March 16, 2021 20:24
});

expect(stack).to(haveResource('AWS::CodeDeploy::Application', {
'ComputePlatform': 'Server',
Copy link
Contributor

Choose a reason for hiding this comment

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

We do need an ApplicationName provided here.

If it doesn't appear, then the fix is not sufficient. It may be the that the ServerApplication does not respect PhysicalNames, for example.

Try and step through the code to see where the discrepancy between what we expect and what actually happens comes from.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can we give a custom name and check whether we'll be receiving the out as expected instead of a PhysicaName?

@mergify mergify bot dismissed rix0rrr’s stale review March 19, 2021 06:12

Pull request has been modified.

@skinny85 skinny85 removed their assignment Mar 19, 2021
@rix0rrr rix0rrr changed the title fix(aws-codedeploy): deploymentgroup creation with physicalname_generate_if_needed fix(codedeploy): DeploymentGroup's physical name not propagated to Application Mar 22, 2021
@mergify
Copy link
Contributor

mergify bot commented Mar 22, 2021

Thank you for contributing! Your pull request will be updated from master 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: AutoBuildProject89A8053A-LhjRyN9kxr8o
  • Commit ID: 8f6ad60
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

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

@mergify
Copy link
Contributor

mergify bot commented Mar 22, 2021

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

@mergify mergify bot merged commit 9d228e4 into aws:master Mar 22, 2021
eladb pushed a commit that referenced this pull request Mar 24, 2021
…pplication (#13582)

fixes #13337


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
hollanddd pushed a commit to hollanddd/aws-cdk that referenced this pull request Aug 26, 2021
…pplication (aws#13582)

fixes aws#13337


----

*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
@aws-cdk/aws-codedeploy Related to AWS CodeDeploy
Projects
None yet
Development

Successfully merging this pull request may close these issues.

(codedeploy.ServerDeploymentGroup): Creating ServerDeploymentGroup does not create Application implicitly
4 participants