Skip to content

Commit 71aef62

Browse files
committed
pkg/asset/machines/aws: Only return available zones
Zones can also be impaired, unavailable, or "information" [1,2]. I dunno what that last one is about. But we only want to put machines in available zones ;). This is a bit racy, because we could get different responses at both call-sites. Moving forward, we'll want to shift this request into a single available-zones asset. [1]: https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeAvailabilityZones.html [2]: https://www.terraform.io/docs/providers/aws/d/availability_zones.html#state
1 parent 02842c6 commit 71aef62

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

data/data/aws/vpc/common.tf

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
data "aws_region" "current" {}
44

55
// Fetch a list of available AZs
6-
data "aws_availability_zones" "azs" {}
6+
data "aws_availability_zones" "azs" {
7+
state = "available"
8+
}
79

810
// Only reference data sources which are gauranteed to exist at any time (above) in this locals{} block
911
locals {

pkg/asset/machines/aws/zones.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,17 @@ func ec2Client(region string) (*ec2.EC2, error) {
3232
}
3333

3434
func fetchAvailabilityZones(client *ec2.EC2, region string) ([]string, error) {
35-
zoneFilter := &ec2.Filter{
36-
Name: aws.String("region-name"),
37-
Values: []*string{aws.String(region)},
38-
}
3935
req := &ec2.DescribeAvailabilityZonesInput{
40-
Filters: []*ec2.Filter{zoneFilter},
36+
Filters: []*ec2.Filter{
37+
{
38+
Name: aws.String("region-name"),
39+
Values: []*string{aws.String(region)},
40+
},
41+
{
42+
Name: aws.String("state"),
43+
Values: []*string{aws.String("available")},
44+
},
45+
},
4146
}
4247
resp, err := client.DescribeAvailabilityZones(req)
4348
if err != nil {

0 commit comments

Comments
 (0)