package ec2

import (
	"errors"

	goaws "github.com/aws/aws-sdk-go/aws"
	awsec2 "github.com/aws/aws-sdk-go/service/ec2"
)

type AvailabilityZoneRetriever struct {
	ec2ClientProvider ec2ClientProvider
}

func NewAvailabilityZoneRetriever(ec2ClientProvider ec2ClientProvider) AvailabilityZoneRetriever {
	return AvailabilityZoneRetriever{
		ec2ClientProvider: ec2ClientProvider,
	}
}

func (r AvailabilityZoneRetriever) Retrieve(region string) ([]string, error) {
	output, err := r.ec2ClientProvider.GetEC2Client().DescribeAvailabilityZones(&awsec2.DescribeAvailabilityZonesInput{
		Filters: []*awsec2.Filter{{
			Name:   goaws.String("region-name"),
			Values: []*string{goaws.String(region)},
		}},
	})
	if err != nil {
		return []string{}, err
	}

	azList := []string{}
	for _, az := range output.AvailabilityZones {
		if az == nil {
			return []string{}, errors.New("aws returned nil availability zone")
		}
		if az.ZoneName == nil {
			return []string{}, errors.New("aws returned availability zone with nil zone name")
		}

		if *az.ZoneName != "us-east-1d" {
			azList = append(azList, *az.ZoneName)
		}
	}

	return azList, nil
}

package ec2

import (
	"errors"

	goaws "github.com/aws/aws-sdk-go/aws"
	awsec2 "github.com/aws/aws-sdk-go/service/ec2"
)

type AvailabilityZoneRetriever struct {
	ec2ClientProvider ec2ClientProvider
}

func NewAvailabilityZoneRetriever(ec2ClientProvider ec2ClientProvider) AvailabilityZoneRetriever {
	return AvailabilityZoneRetriever{
		ec2ClientProvider: ec2ClientProvider,
	}
}

func (r AvailabilityZoneRetriever) Retrieve(region string) ([]string, error) {
	output, err := r.ec2ClientProvider.GetEC2Client().DescribeAvailabilityZones(&awsec2.DescribeAvailabilityZonesInput{
		Filters: []*awsec2.Filter{{
			Name:   goaws.String("region-name"),
			Values: []*string{goaws.String(region)},
		}},
	})
	if err != nil {
		return []string{}, err
	}

	azList := []string{}
	for _, az := range output.AvailabilityZones {
		if az == nil {
			return []string{}, errors.New("aws returned nil availability zone")
		}
		if az.ZoneName == nil {
			return []string{}, errors.New("aws returned availability zone with nil zone name")
		}

		azList = append(azList, *az.ZoneName)
	}

	return azList, nil
}

Revert "Fix bbl up for AWS"
Revert "Fix bbl up for AWS"

This reverts commit 94599faddf4921e2ad53ffe47755b4b89ebd3a41.

[#139857703]

Signed-off-by: Christian Ang <15ae83feccf4d84083a62aba1cdf46bd8ce2e33b@pivotal.io>
