// CreateStackChangeSet returns the DescribeChangeSetOutput
// for a given stack transformation
509247
func CreateStackChangeSet(changeSetRequestName string,
	serviceName string,
	cfTemplate *gocf.Template,
	templateURL string,
	awsTags []*cloudformation.Tag,
	awsCloudFormation *cloudformation.CloudFormation,
	logger *logrus.Logger) (*cloudformation.DescribeChangeSetOutput, error) {

	capabilities := stackCapabilities(cfTemplate)
	changeSetInput := &cloudformation.CreateChangeSetInput{
		Capabilities:  capabilities,
		ChangeSetName: aws.String(changeSetRequestName),
		ClientToken:   aws.String(changeSetRequestName),
		Description:   aws.String(fmt.Sprintf("Change set for service: %s", serviceName)),
		StackName:     aws.String(serviceName),
		TemplateURL:   aws.String(templateURL),
	}
	if len(awsTags) != 0 {
		changeSetInput.Tags = awsTags
	}
	_, changeSetError := awsCloudFormation.CreateChangeSet(changeSetInput)
	if nil != changeSetError {
		return nil, changeSetError
	}

	logger.WithFields(logrus.Fields{
		"StackName": serviceName,
	}).Info("Issued CreateChangeSet request")

	describeChangeSetInput := cloudformation.DescribeChangeSetInput{
		ChangeSetName: aws.String(changeSetRequestName),
		StackName:     aws.String(serviceName),
	}

	var describeChangeSetOutput *cloudformation.DescribeChangeSetOutput

	// Loop, with a total timeout of 3 minutes
	startTime := time.Now()
	changeSetStabilized := false
	for !changeSetStabilized {
		sleepDuration := cloudformationPollingDelay()
		time.Sleep(sleepDuration)

		changeSetOutput, describeChangeSetError := awsCloudFormation.DescribeChangeSet(&describeChangeSetInput)

		if nil != describeChangeSetError {
			return nil, describeChangeSetError
		}
		describeChangeSetOutput = changeSetOutput
		// The current status of the change set, such as CREATE_IN_PROGRESS, CREATE_COMPLETE,
		// or FAILED.
		if nil != describeChangeSetOutput {
			switch *describeChangeSetOutput.Status {
			case "CREATE_IN_PROGRESS":
				// If this has taken more than 3 minutes, then that's an error
				elapsedTime := time.Since(startTime)
				if elapsedTime > cloudformationPollingTimeout {
					return nil, fmt.Errorf("failed to finalize ChangeSet within window: %s", elapsedTime.String())
				}
			case "CREATE_COMPLETE":
				changeSetStabilized = true
			case "FAILED":
				return nil, fmt.Errorf("failed to create ChangeSet: %#v", *describeChangeSetOutput)
			}
		}
	}

	logger.WithFields(logrus.Fields{
		"DescribeChangeSetOutput": describeChangeSetOutput,
	}).Debug("DescribeChangeSet result")

	//////////////////////////////////////////////////////////////////////////////
	// If there aren't any changes, then skip it...
	if len(describeChangeSetOutput.Changes) <= 0 {
		logger.WithFields(logrus.Fields{
			"StackName": serviceName,
		}).Info("No changes detected for service")

		// Delete it...
		_, deleteChangeSetResultErr := DeleteChangeSet(serviceName,
			changeSetRequestName,
			awsCloudFormation)
		return nil, deleteChangeSetResultErr
	}
	return describeChangeSetOutput, nil
}
1076378
func (s *StackInstanceSummary) SetStackSetId(v string) *StackInstanceSummary {
	s.StackSetId = &v
	return s
}
599096
func NewChangeWatchResp(ctx context.Context, delegate datasync.ProtoWatchResp, prevVal datasync.LazyValue) *ChangeWatchResp {
	return &ChangeWatchResp{
		ctx: ctx,
		changes: []datasync.ProtoWatchResp{
			&changePrev{
				ProtoWatchResp: delegate,
				prev:           prevVal,
			},
		},
		DoneChannel: &syncbase.DoneChannel{DoneChan: nil},
	}
}
392896
func (s *StackEvent) SetStackName(v string) *StackEvent {
	s.StackName = &v
	return s
}
364423
func (s *DescribeElasticIpsInput) SetStackId(v string) *DescribeElasticIpsInput {
	s.StackId = &v
	return s
}
1304591
func (s *Stack) SetChangeSetId(v string) *Stack {
	s.ChangeSetId = &v
	return s
}
988038
func (s *CreateStackSetOutput) SetStackSetId(v string) *CreateStackSetOutput {
	s.StackSetId = &v
	return s
}
661781
func (s *Scheduler) createStack(ctx context.Context, input *createStackInput, output chan stackOperationOutput, ss twelvefactor.StatusStream) error {
	waiter := s.waitFor(ctx, createStack, ss)

	submitted := make(chan error)
	fn := func() error {
		_, err := s.cloudformation.CreateStack(&cloudformation.CreateStackInput{
			StackName:   input.StackName,
			TemplateURL: input.Template.URL,
			Tags:        input.Tags,
			Parameters:  input.Parameters,
		})
		submitted <- err
		return err
	}
	go func() {
		stack, err := s.performStackOperation(ctx, *input.StackName, fn, waiter, ss)
		output <- stackOperationOutput{stack, err}
	}()

	return <-submitted
}
92639
func (c *configuration) removeStack(i int) {
	c.stack = c.stack[:i+copy(c.stack[i:], c.stack[i+1:])]
}
594930
func (c *CloudFormation) WaitUntilStackCreateComplete(input *DescribeStacksInput) error {
	return c.WaitUntilStackCreateCompleteWithContext(aws.BackgroundContext(), input)
}
535106
func (logger *Logger) SetStackMinLevel(level event.Level) {
	atomic.StoreInt32(&logger.stackMinLevel, int32(level))
}
1307506
func (s *ExecuteChangeSetInput) SetChangeSetName(v string) *ExecuteChangeSetInput {
	s.ChangeSetName = &v
	return s
}
595665
func trackSyncPtrChangesInCreate(
	mostRecentTargetPtr data.BlockPointer, unmergedChain *crChain,
	unmergedChains *crChains, toName string) {
	targetChain, ok := unmergedChains.byMostRecent[mostRecentTargetPtr]
	var refs, unrefs []data.BlockPointer
	if ok && targetChain.isFile() {
		// The create op also needs to reference the child block ptrs
		// created by any sync ops (and not unreferenced by future
		// ones).
		for _, op := range targetChain.ops {
			syncOp, ok := op.(*syncOp)
			if !ok {
				continue
			}
			for _, ref := range op.Refs() {
				if !unmergedChains.isDeleted(ref) {
					refs = append(refs, ref)
				}
			}
			for _, unref := range op.Unrefs() {
				unrefs = append(unrefs, unref)
			}
			// Account for the file ptr too, if it's the most recent.
			filePtr := syncOp.File.Ref
			_, isMostRecent := unmergedChains.byMostRecent[filePtr]
			if isMostRecent && !unmergedChains.isDeleted(filePtr) {
				refs = append(refs, filePtr)
			}
		}
	}
	if len(refs) > 0 {
		for _, uop := range unmergedChain.ops {
			cop, ok := uop.(*createOp)
			if !ok || cop.NewName != toName {
				continue
			}
			for _, ref := range refs {
				cop.AddRefBlock(ref)
			}
			for _, unref := range unrefs {
				cop.AddUnrefBlock(unref)
			}
			break
		}
	}
}
209162
func (s *CreateStackOutput) SetStack(v *Stack) *CreateStackOutput {
	s.Stack = v
	return s
}
1139879
func (s *CreateChangeSetInput) SetChangeSetType(v string) *CreateChangeSetInput {
	s.ChangeSetType = &v
	return s
}
980318
func (t *MockTransactor) CreateTransactionHeader(opts ...fab.TxnHeaderOpt) (fab.TransactionHeader, error) {
	txh, err := txn.NewHeader(t.Ctx, t.ChannelID)
	if err != nil {
		return nil, errors.WithMessage(err, "new transaction ID failed")
	}

	return txh, nil
}
1134196
func (s *DescribeChangeSetOutput) SetStackId(v string) *DescribeChangeSetOutput {
	s.StackId = &v
	return s
}