CircleCI-Public / aws-code-deploy-orb

Easily deploy applications to AWS CodeDeploy on CircleCI with the aws-code-deploy orb
https://circleci.com/orbs/registry/orb/circleci/aws-code-deploy
MIT License
9 stars 13 forks source link

Fix issue from 185: aws-code-deploy fails to check the existence of deployment group with extra arguments passed #2

Closed KyleTryon closed 4 years ago

KyleTryon commented 4 years ago

Original issue from old repo: https://github.com/CircleCI-Public/circleci-orbs/issues/185 Original PR: https://github.com/CircleCI-Public/circleci-orbs/pull/235 Original reporter: @pcwiek Original PR author: @Kobin


What happened

Any arguments passed to aws-code-deploy/create-deployment-group which are intended for group creation are also passed to AWS CLI when calling aws deploy get-deployment-group, which makes the check for group existence fail each and every time because those options are not recognized by get-deployment-group. Then the step tries to create the group again and fails every time because the deployment group with specified name already exists.

CIRCLE_WORKFLOW_ID=cf22d16d-2421-4a55-9ae0-2327f7b11fd6

Example below is adapted from one of the steps from workflow above

ensure-deployment-created

set +e
aws deploy get-deployment-group \
  --application-name my-app \
  --deployment-group-name test --ec2-tag-filters Key=environment,Value=test,Type=KEY_AND_VALUE --auto-rollback-configuration enabled=true,events=DEPLOYMENT_FAILURE
if [ $? -ne 0 ]; then
  set -e
  echo "No deployment group named test found. Trying to create a new one"
  aws deploy create-deployment-group \
    --application-name my-app \
    --deployment-group-name test \
    --deployment-config-name CodeDeployDefault.OneAtATime \
    --service-role-arn $CODEDEPLOY_ROLE_ARN --ec2-tag-filters Key=environment,Value=test,Type=KEY_AND_VALUE --auto-rollback-configuration enabled=true,events=DEPLOYMENT_FAILURE
else
  set -e
  echo "Deployment group named test already exists. Skipping creation."
fi

Output:

usage: aws [options] <command> <subcommand> [<subcommand> ...] [parameters]
To see help text, you can run:

  aws help
  aws <command> help
  aws <command> <subcommand> help

Unknown options: --ec2-tag-filters, Key=environment,Value=test,Type=KEY_AND_VALUE, --auto-rollback-configuration, enabled=true,events=DEPLOYMENT_FAILURE, 
No deployment group named test found. Trying to create a new one

An error occurred (DeploymentGroupAlreadyExistsException) when calling the CreateDeploymentGroup operation: An Deployment Group with the name test already exists for this application.
Exited with code 255

Expected behavior

Either the arguments should be split in two (arguments to get-deployment-group and create-deployment-group separately), or they should be only used for create-deployment-group and omitted for get-deployment-group call.


Fixes #185

Checklist

Motivation, issues

Issue #185 showed that the arguments are passed both to the get-deployment-group and create-deployment-group subcommands. As the former has less arguments, it will likely fail when some arguments provided.

Description

Separate get-deployment-group arguments into their own parameter, to ensure the command won't yield a non-zero exit code and trigger the deployment group creation just because the parameters were invalid.


@KyleTryon: I have taken your PR one step further to ensure the parameter is included within the deploy job, not just the command.

A concern I have is the arguments parameter is still passed to each command. Might that mean that similar issues to yours will still exist? @lokst I am wondering your thoughts, perhaps we need to break up arguments for each individual CLI command?

zetxek commented 4 years ago

Any ETA for this PR to be merged to the orb?

lokst commented 4 years ago

@KyleTryon Do you have any further considerations about this PR?

KyleTryon commented 4 years ago

I still have concerns about

I am wondering your thoughts, perhaps we need to break up arguments for each individual CLI command?

But, that can also be another PR. Going to attempt to merge now, thanks all.

zetxek commented 4 years ago

Is there some way to integrate/test the alpha version of the orb @KyleTryon @lokst ? Is it published somewhere that can be referenced in a pipeline?

lokst commented 4 years ago

@zetxek The changes from this PR are available in circleci/aws-code-deploy@1.0.1