Exemplo n.º 1
0
// updateStack updates a stack
//   template is url to a template or empty string to reuse previous
//   changes is a list of parameter changes to make (does not need to include every param)
func (p *AWSProvider) updateStack(name string, template string, changes map[string]string) error {
	cache.Clear("describeStacks", nil)
	cache.Clear("describeStacks", name)

	req := &cloudformation.UpdateStackInput{
		Capabilities: []*string{aws.String("CAPABILITY_IAM")},
		StackName:    aws.String(name),
	}

	params := map[string]bool{}
	pexisting := map[string]bool{}

	stack, err := p.describeStack(name)
	if err != nil {
		return err
	}

	for _, p := range stack.Parameters {
		pexisting[*p.ParameterKey] = true
	}

	if template != "" {
		req.TemplateURL = aws.String(template)

		fp, err := formationParameters(template)
		if err != nil {
			return err
		}

		for p := range fp {
			params[p] = true
		}
	} else {
		req.UsePreviousTemplate = aws.Bool(true)

		for param := range pexisting {
			params[param] = true
		}
	}

	sorted := []string{}

	for param := range params {
		sorted = append(sorted, param)
	}

	// sort params for easier testing
	sort.Strings(sorted)

	for _, param := range sorted {
		if value, ok := changes[param]; ok {
			req.Parameters = append(req.Parameters, &cloudformation.Parameter{
				ParameterKey:   aws.String(param),
				ParameterValue: aws.String(value),
			})
		} else if pexisting[param] {
			req.Parameters = append(req.Parameters, &cloudformation.Parameter{
				ParameterKey:     aws.String(param),
				UsePreviousValue: aws.Bool(true),
			})
		}
	}

	_, err = p.cloudformation().UpdateStack(req)

	cache.Clear("describeStacks", nil)
	cache.Clear("describeStacks", name)

	return err
}
Exemplo n.º 2
0
func (p *AWSProvider) updateStack(input *cloudformation.UpdateStackInput) (*cloudformation.UpdateStackOutput, error) {
	cache.Clear("describeStacks", nil)
	cache.Clear("describeStacks", input.StackName)

	return p.cloudformation().UpdateStack(input)
}