From e827180887ddd8f82d4deb0a0e0bed51d396e638 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 10 Oct 2014 16:57:32 -0700 Subject: [PATCH] providers/aws: main_route_table_id attribute for VPC [GH-193] --- CHANGELOG.md | 1 + builtin/providers/aws/resource_aws_vpc.go | 21 +++++++++++++++++-- .../docs/providers/aws/r/vpc.html.markdown | 3 ++- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a74b7f26e..60415a410 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,6 +43,7 @@ IMPROVEMENTS: `aws_launch_configuration`. [GH-371] * providers/aws: Non-destructive update of `desired_capacity` for autoscale groups. + * providers/aws: Add `main_route_table_id` attribute to VPCs. [GH-193] * providers/google: Support `target_tags` for firewalls. [GH-324] * providers/google: `google_compute_instance` supports `can_ip_forward` [GH-375] * providers/google: `google_compute_disk` supports `type` to support disks diff --git a/builtin/providers/aws/resource_aws_vpc.go b/builtin/providers/aws/resource_aws_vpc.go index cde7b9065..e399384bd 100644 --- a/builtin/providers/aws/resource_aws_vpc.go +++ b/builtin/providers/aws/resource_aws_vpc.go @@ -36,6 +36,11 @@ func resourceAwsVpc() *schema.Resource { Computed: true, }, + "main_route_table_id": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + }, + "tags": tagsSchema(), }, } @@ -90,7 +95,6 @@ func resourceAwsVpcUpdate(d *schema.ResourceData, meta interface{}) error { // Turn on partial mode d.Partial(true) - defer d.Partial(false) if d.HasChange("enable_dns_hostnames") { options := new(ec2.ModifyVpcAttribute) @@ -128,7 +132,8 @@ func resourceAwsVpcUpdate(d *schema.ResourceData, meta interface{}) error { d.SetPartial("tags") } - return nil + d.Partial(false) + return resourceAwsVpcRead(d, meta) } func resourceAwsVpcDelete(d *schema.ResourceData, meta interface{}) error { @@ -181,6 +186,18 @@ func resourceAwsVpcRead(d *schema.ResourceData, meta interface{}) error { } d.Set("enable_dns_hostnames", resp.EnableDnsHostnames) + // Get the main routing table for this VPC + filter := ec2.NewFilter() + filter.Add("association.main", "true") + filter.Add("vpc-id", d.Id()) + routeResp, err := ec2conn.DescribeRouteTables(nil, filter) + if err != nil { + return err + } + if v := routeResp.RouteTables; len(v) > 0 { + d.Set("main_route_table_id", v[0].RouteTableId) + } + return nil } diff --git a/website/source/docs/providers/aws/r/vpc.html.markdown b/website/source/docs/providers/aws/r/vpc.html.markdown index 5955c401b..be9337713 100644 --- a/website/source/docs/providers/aws/r/vpc.html.markdown +++ b/website/source/docs/providers/aws/r/vpc.html.markdown @@ -47,4 +47,5 @@ The following attributes are exported: * `cidr_block` - The CIDR block of the VPC * `enable_dns_support` - Whether or not the VPC has DNS support * `enable_dns_hostnames` - Whether or not the VPC has DNS hostname support - +* `main_route_table_id` - The ID of the main route table associated with + this VPC.