Ejemplo n.º 1
0
Archivo: ecs.go Proyecto: brianz/empire
func (p *ECSServiceResource) Provision(ctx context.Context, req customresources.Request) (string, interface{}, error) {
	properties := req.ResourceProperties.(*ECSServiceProperties)
	oldProperties := req.OldResourceProperties.(*ECSServiceProperties)
	data := make(map[string]string)

	switch req.RequestType {
	case customresources.Create:
		id, deploymentId, err := p.create(ctx, req.Hash(), properties)
		if err == nil {
			data["DeploymentId"] = deploymentId
		}
		return id, data, err
	case customresources.Delete:
		id := req.PhysicalResourceId
		err := p.delete(ctx, aws.String(id), properties.Cluster)
		return id, nil, err
	case customresources.Update:
		id := req.PhysicalResourceId

		// TODO: Update this to use hashstructure.
		if serviceRequiresReplacement(properties, oldProperties) {
			// If we can't update the service, we'll need to create a new
			// one, and destroy the old one.
			oldId := id
			id, deploymentId, err := p.create(ctx, req.Hash(), properties)
			if err != nil {
				return oldId, nil, err
			}
			data["DeploymentId"] = deploymentId

			// There's no need to delete the old service here, since
			// CloudFormation will send us a DELETE request for the old
			// service.

			return id, data, err
		}

		resp, err := p.ecs.UpdateService(&ecs.UpdateServiceInput{
			Service:        aws.String(id),
			Cluster:        properties.Cluster,
			DesiredCount:   properties.DesiredCount.Value(),
			TaskDefinition: properties.TaskDefinition,
		})
		if err == nil {
			d := primaryDeployment(resp.Service)
			if d != nil {
				data["DeploymentId"] = *d.Id
			} else {
				err = fmt.Errorf("no primary deployment found")
			}
		}
		return id, data, err
	default:
		return "", nil, fmt.Errorf("%s is not supported", req.RequestType)
	}
}
Ejemplo n.º 2
0
func (c *CustomResourceProvisioner) provision(ctx context.Context, m Message, req customresources.Request) (string, interface{}, error) {
	p, ok := c.Provisioners[req.ResourceType]
	if !ok {
		return "", nil, fmt.Errorf("no provisioner for %v", req.ResourceType)
	}

	// If the provisioner defines a type for the properties, let's unmarhsal
	// into that Go type.
	req.ResourceProperties = p.Properties()
	req.OldResourceProperties = p.Properties()
	err := json.Unmarshal([]byte(m.Message), &req)
	if err != nil {
		return "", nil, fmt.Errorf("error unmarshalling to cloudformation request: %v", err)
	}

	return p.Provision(ctx, req)
}
Ejemplo n.º 3
0
Archivo: ecs.go Proyecto: brianz/empire
func (p *ECSTaskDefinitionResource) Create(ctx context.Context, req customresources.Request) (string, interface{}, error) {
	properties := req.ResourceProperties.(*ECSTaskDefinitionProperties)
	id, err := p.register(properties, req.Hash())
	return id, nil, err
}