コード例 #1
0
        public async Task DescribeChangeset(StackArn stack, ChangeSetArn changeSet, IVariables variables)
        {
            Guard.NotNull(stack, "The provided stack identifer or name may not be null");
            Guard.NotNull(changeSet, "The provided change set identifier or name may not be null");
            Guard.NotNull(variables, "The variable dictionary may not be null");

            try
            {
                var response = await clientFactory.DescribeChangeSetAsync(stack, changeSet);

                SetOutputVariable(variables, "ChangeCount", response.Changes.Count.ToString());
                SetOutputVariable(variables, "Changes",
                                  JsonConvert.SerializeObject(response.Changes, Formatting.Indented));
            }
            catch (AmazonCloudFormationException ex) when(ex.ErrorCode == "AccessDenied")
            {
                throw new PermissionException(
                          "The AWS account used to perform the operation does not have the required permissions to describe the change set.\n" +
                          "Please ensure the current account has permission to perfrom action 'cloudformation:DescribeChangeSet'." +
                          ex.Message + "\n");
            }
            catch (AmazonCloudFormationException ex)
            {
                throw new UnknownException("An unrecognized exception was thrown while describing the CloudFormation change set.", ex);
            }
        }
        public void DescribeChangeset(StackArn stack, ChangeSetArn changeSet, CalamariVariableDictionary variables)
        {
            Guard.NotNull(stack, "The provided stack identifer or name may not be null");
            Guard.NotNull(changeSet, "The provided change set identifier or name may not be null");
            Guard.NotNull(variables, "The variable dictionary may not be null");

            try
            {
                var response = clientFactory.DescribeChangeSet(stack, changeSet);
                SetOutputVariable(variables, "ChangeCount", response.Changes.Count.ToString());
                SetOutputVariable(variables, "Changes", JsonConvert.SerializeObject(response.Changes, Formatting.Indented));
            }
            catch (AmazonCloudFormationException ex)
            {
                if (ex.ErrorCode == "AccessDenied")
                {
                    throw new PermissionException(
                              @"AWS-CLOUDFORMATION-ERROR-0015: The AWS account used to perform the operation does not have " +
                              "the required permissions to describe the change set.\n" +
                              ex.Message + "\n" +
                              "For more information visit the [octopus docs](https://g.octopushq.com/AwsCloudFormationDeploy#aws-cloudformation-error-0015)");
                }

                throw new UnknownException(
                          "AWS-CLOUDFORMATION-ERROR-0016: An unrecognised exception was thrown while describing the CloudFormation change set.\n" +
                          "For more information visit https://g.octopushq.com/AwsCloudFormationDeploy#aws-cloudformation-error-0016",
                          ex);
            }
        }
コード例 #3
0
        private async Task <RunningChangeSet> ExecuteChangeset(Func <IAmazonCloudFormation> factory, StackArn stack,
                                                               ChangeSetArn changeSet)
        {
            try
            {
                var changes = await factory.WaitForChangeSetCompletion(CloudFormationDefaults.StatusWaitPeriod,
                                                                       new RunningChangeSet(stack, changeSet));


                if (changes.Status == ChangeSetStatus.FAILED)
                {
                    throw new UnknownException($"The changeset failed to create.\n{changes.StatusReason}");
                }

                await factory().ExecuteChangeSetAsync(new ExecuteChangeSetRequest
                {
                    ChangeSetName = changeSet.Value,
                    StackName     = stack.Value
                });

                return(new RunningChangeSet(stack, changeSet));
            }
            catch (AmazonCloudFormationException exception) when(exception.ErrorCode == "AccessDenied")
            {
                throw new PermissionException(
                          "The AWS account used to perform the operation does not have the required permission to execute the changeset.\n" +
                          "Please ensure the current account has permission to perfrom action 'cloudformation:ExecuteChangeSet'.\n" +
                          exception.Message + "\n");
            }
            catch (AmazonServiceException exception)
            {
                LogAmazonServiceException(exception);
                throw;
            }
        }
コード例 #4
0
        private Maybe <RunningChangeSet> ExecuteChangeset(Func <IAmazonCloudFormation> factory, StackArn stack,
                                                          ChangeSetArn changeSet)
        {
            try
            {
                var changes = factory.WaitForChangeSetCompletion(CloudFormationDefaults.StatusWaitPeriod,
                                                                 new RunningChangeSet(stack, changeSet));

                if (changes.Status == ChangeSetStatus.FAILED &&
                    string.Compare(changes.StatusReason, "No updates are to be performed.",
                                   StringComparison.InvariantCultureIgnoreCase) == 0)
                {
                    //We don't need the failed changeset to hang around if there are no changes
                    factory().DeleteChangeSet(new DeleteChangeSetRequest
                    {
                        ChangeSetName = changeSet.Value,
                        StackName     = stack.Value
                    });

                    return(Maybe <RunningChangeSet> .None);
                }

                if (changes.Status == ChangeSetStatus.FAILED)
                {
                    throw new UnknownException($"AWS-CLOUDFORMATION-ERROR-0019: The changeset failed to create.\n{changes.StatusReason}");
                }


                factory().ExecuteChangeSet(new ExecuteChangeSetRequest
                {
                    ChangeSetName = changeSet.Value,
                    StackName     = stack.Value
                });

                return(new RunningChangeSet(stack, changeSet).AsSome());
            }
            catch (AmazonCloudFormationException exception)
            {
                if (exception.ErrorCode == "AccessDenied")
                {
                    throw new PermissionException(
                              "AWS-CLOUDFORMATION-ERROR-0011: The AWS account used to perform the operation does not have " +
                              "the required permissions to update the stack.\n" +
                              exception.Message + "\n" +
                              "For more information visit https://g.octopushq.com/AwsCloudFormationDeploy#aws-cloudformation-error-0011");
                }

                throw new UnknownException(
                          "AWS-CLOUDFORMATION-ERROR-0011: An unrecognised exception was thrown while updating a CloudFormation stack.\n" +
                          "For more information visit https://g.octopushq.com/AwsCloudFormationDeploy#aws-cloudformation-error-0011",
                          exception);
            }
            catch (AmazonServiceException exception)
            {
                HandleAmazonServiceException(exception);
                throw;
            }
        }
コード例 #5
0
        private async Task <Maybe <RunningChangeSet> > ExecuteChangeset(Func <IAmazonCloudFormation> factory, StackArn stack,
                                                                        ChangeSetArn changeSet)
        {
            try
            {
                var changes = await factory.WaitForChangeSetCompletion(CloudFormationDefaults.StatusWaitPeriod,
                                                                       new RunningChangeSet(stack, changeSet));

                if (changes.Status == ChangeSetStatus.FAILED &&
                    string.Compare(changes.StatusReason, "No updates are to be performed.",
                                   StringComparison.InvariantCultureIgnoreCase) == 0)
                {
                    //We don't need the failed changeset to hang around if there are no changes
                    await factory().DeleteChangeSetAsync(new DeleteChangeSetRequest
                    {
                        ChangeSetName = changeSet.Value,
                        StackName     = stack.Value
                    });

                    return(Maybe <RunningChangeSet> .None);
                }

                if (changes.Status == ChangeSetStatus.FAILED)
                {
                    throw new UnknownException($"The changeset failed to create.\n{changes.StatusReason}");
                }

                await factory().ExecuteChangeSetAsync(new ExecuteChangeSetRequest
                {
                    ChangeSetName = changeSet.Value,
                    StackName     = stack.Value
                });

                return(new RunningChangeSet(stack, changeSet).AsSome());
            }
            catch (AmazonCloudFormationException exception) when(exception.ErrorCode == "AccessDenied")
            {
                throw new PermissionException(
                          "The AWS account used to perform the operation does not have the required permission to execute the changeset.\n" +
                          "Please ensure the current account has permission to perfrom action 'cloudformation:ExecuteChangeSet'.\n" +
                          exception.Message + "\n");
            }
            catch (AmazonServiceException exception)
            {
                LogAmazonServiceException(exception);
                throw;
            }
        }