Esempio n. 1
0
File: builder.go Progetto: mmb/boosh
func (builder *Builder) buildSecurityGroups(cloudformer.CloudFormer) error {
	for _, x := range builder.spec.SecurityGroups {
		group := builder.vpc.SecurityGroup(x.Name)

		for _, i := range x.Ingress {
			fromPort, toPort, err := parsePortRange(i.Ports)
			if err != nil {
				return err
			}

			group.Ingress(
				cloudformer.ProtocolType(i.Protocol),
				cloudformer.CIDR(i.CIDR),
				fromPort,
				toPort,
			)
		}

		for _, e := range x.Egress {
			fromPort, toPort, err := parsePortRange(e.Ports)
			if err != nil {
				return err
			}

			group.Egress(
				cloudformer.ProtocolType(e.Protocol),
				cloudformer.CIDR(e.CIDR),
				fromPort,
				toPort,
			)
		}

		builder.securityGroups[x.Name] = group
	}

	return nil
}
Esempio n. 2
0
File: builder.go Progetto: mmb/boosh
func (builder *Builder) buildLoadBalancers(former cloudformer.CloudFormer) error {
	for _, x := range builder.spec.LoadBalancers {
		balancer := former.LoadBalancer(x.Name)

		for _, name := range x.Subnets {
			subnet, found := builder.subnets[name]
			if !found {
				return fmt.Errorf("unknown subnet: %s", name)
			}

			balancer.Subnet(subnet)
		}

		for _, listener := range x.Listeners {
			destinationPort := listener.Port
			if listener.DestinationPort != nil {
				destinationPort = *listener.DestinationPort
			}

			destinationProtocol := listener.Protocol
			if listener.DestinationProtocol != nil {
				destinationProtocol = *listener.DestinationProtocol
			}

			balancer.Listener(
				cloudformer.ProtocolType(listener.Protocol),
				listener.Port,
				cloudformer.ProtocolType(destinationProtocol),
				destinationPort,
				listener.SSLCertificateId,
			)
		}

		for _, name := range x.SecurityGroups {
			securityGroup, found := builder.securityGroups[name]
			if !found {
				return fmt.Errorf("unknown security group: %s", name)
			}

			balancer.SecurityGroup(securityGroup)
		}

		balancer.HealthCheck(cloudformer.HealthCheck{
			Protocol:           cloudformer.ProtocolType(x.HealthCheck.Target.Protocol),
			Port:               x.HealthCheck.Target.Port,
			Path:               x.HealthCheck.Target.Path,
			Interval:           time.Duration(x.HealthCheck.Interval) * time.Second,
			Timeout:            time.Duration(x.HealthCheck.Timeout) * time.Second,
			HealthyThreshold:   x.HealthCheck.HealthyThreshold,
			UnhealthyThreshold: x.HealthCheck.UnhealthyThreshold,
		})

		if x.DNSRecord != "" {
			balancer.RecordSet(x.DNSRecord, builder.spec.Domain)
		}

		if x.Scheme != "" {
			balancer.Scheme(x.Scheme)
		}

		balancer.CrossZone(x.CrossZone)
	}

	return nil
}