Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] provider/aws: Availability Zone helper resource #6669

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions builtin/providers/aws/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ func Provider() terraform.ResourceProvider {
"aws_autoscaling_notification": resourceAwsAutoscalingNotification(),
"aws_autoscaling_policy": resourceAwsAutoscalingPolicy(),
"aws_autoscaling_schedule": resourceAwsAutoscalingSchedule(),
"aws_availability_zones": resourceAwsAvailabilityZones(),
"aws_cloudformation_stack": resourceAwsCloudFormationStack(),
"aws_cloudfront_distribution": resourceAwsCloudFrontDistribution(),
"aws_cloudfront_origin_access_identity": resourceAwsCloudFrontOriginAccessIdentity(),
Expand Down
64 changes: 64 additions & 0 deletions builtin/providers/aws/resource_aws_availability_zones.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package aws

import (
"fmt"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/hashicorp/terraform/helper/schema"
)

func resourceAwsAvailabilityZones() *schema.Resource {
return &schema.Resource{
Create: resourceAwsAZCreate,
Read: resourceAwsAZRead,
//Update: resourceAwsAZUpdate,
Delete: resourceAwsAZDelete,

Schema: map[string]*schema.Schema{
"name": &schema.Schema{
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"availability_zones": &schema.Schema{
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
Set: schema.HashString,
},
},
}
}

func resourceAwsAZCreate(d *schema.ResourceData, meta interface{}) error {
name := d.Get("name").(string)
d.SetId(name)
return resourceAwsAZRead(d, meta)
}

func resourceAwsAZRead(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).ec2conn
req := &ec2.DescribeAvailabilityZonesInput{DryRun: aws.Bool(false)}
azresp, err := conn.DescribeAvailabilityZones(req)
if err != nil {
return fmt.Errorf("Error listing availability zones: %s", err)
}

raw := schema.NewSet(schema.HashString, nil)

for _, v := range azresp.AvailabilityZones {
raw.Add(*v.ZoneName)
}

azErr := d.Set("availability_zones", raw)

if azErr != nil {
return fmt.Errorf("[WARN] Error setting availability zones")
}
return nil
}

func resourceAwsAZDelete(d *schema.ResourceData, meta interface{}) error {
return nil
}