func()

in internal/pkg/deploy/cloudformation/cloudformation.go [137:173]


func (cf CloudFormation) create(stackConfig stackConfiguration) (bool, error) {
	describeStackInput := &cloudformation.DescribeStacksInput{StackName: aws.String(stackConfig.StackName())}
	existingStack, err := cf.describeStack(describeStackInput)
	// Create the stack if it doesn't already exists.
	if err != nil {

		var stackNotFound *ErrStackNotFound
		if !errors.As(err, &stackNotFound) {
			return false, err
		}
		// If there's no existing stack, we can go ahead and create it.
		return cf.deploy(stackConfig, cloudformation.ChangeSetTypeCreate)
	}

	// If the stack exists, but failed to create, we'll clean it up and
	// then re-create it.
	if StackStatus(*existingStack.StackStatus).RequiresCleanup() {
		if err := cf.delete(stackConfig.StackName()); err != nil {
			return false, fmt.Errorf("cleaning up a previous failed stack: %w", err)
		}
		return cf.deploy(stackConfig, cloudformation.ChangeSetTypeCreate)
	}

	if StackStatus(*existingStack.StackStatus).InProgress() {
		return false, &ErrStackUpdateInProgress{
			stackName:   stackConfig.StackName(),
			stackStatus: aws.StringValue(existingStack.StackStatus),
		}
	}

	// If the stack exists and has been successfully created - return
	// a ErrStackAlreadyExists error.
	return false, &ErrStackAlreadyExists{
		stackName: stackConfig.StackName(),
		parentErr: fmt.Errorf("with status: %s", *existingStack.StackStatus),
	}
}