From ed3f54cc47810d291e989bada385f486f1138a8c Mon Sep 17 00:00:00 2001 From: Julien Fabre Date: Fri, 20 Nov 2015 16:48:48 +0100 Subject: [PATCH] Add AWS Classiclink for AWS VPC resource --- builtin/providers/aws/resource_aws_vpc.go | 50 +++++++++++++++++++ .../providers/aws/resource_aws_vpc_test.go | 25 ++++++++++ .../docs/providers/aws/r/vpc.html.markdown | 2 + 3 files changed, 77 insertions(+) diff --git a/builtin/providers/aws/resource_aws_vpc.go b/builtin/providers/aws/resource_aws_vpc.go index 0de908f0d..03beb8a78 100644 --- a/builtin/providers/aws/resource_aws_vpc.go +++ b/builtin/providers/aws/resource_aws_vpc.go @@ -55,6 +55,12 @@ func resourceAwsVpc() *schema.Resource { Computed: true, }, + "enable_classiclink": &schema.Schema{ + Type: schema.TypeBool, + Optional: true, + Computed: true, + }, + "main_route_table_id": &schema.Schema{ Type: schema.TypeString, Computed: true, @@ -170,6 +176,22 @@ func resourceAwsVpcRead(d *schema.ResourceData, meta interface{}) error { } d.Set("enable_dns_hostnames", *resp.EnableDnsHostnames) + DescribeClassiclinkOpts := &ec2.DescribeVpcClassicLinkInput{ + VpcIds: []*string{ &vpcid }, + } + respClassiclink, err := conn.DescribeVpcClassicLink(DescribeClassiclinkOpts) + if err != nil { + return err + } + classiclink_enabled := false + for _, v := range respClassiclink.Vpcs { + if *v.VpcId == vpcid { + classiclink_enabled = *v.ClassicLinkEnabled + break + } + } + d.Set("enable_classiclink", classiclink_enabled) + // Get the main routing table for this VPC // Really Ugly need to make this better - rmenn filter1 := &ec2.Filter{ @@ -241,6 +263,34 @@ func resourceAwsVpcUpdate(d *schema.ResourceData, meta interface{}) error { d.SetPartial("enable_dns_support") } + if d.HasChange("enable_classiclink") { + val := d.Get("enable_classiclink").(bool) + + if val { + modifyOpts := &ec2.EnableVpcClassicLinkInput{ + VpcId: &vpcid, + } + log.Printf( + "[INFO] Modifying enable_classiclink vpc attribute for %s: %#v", + d.Id(), modifyOpts) + if _, err := conn.EnableVpcClassicLink(modifyOpts); err != nil { + return err + } + } else { + modifyOpts := &ec2.DisableVpcClassicLinkInput{ + VpcId: &vpcid, + } + log.Printf( + "[INFO] Modifying enable_classiclink vpc attribute for %s: %#v", + d.Id(), modifyOpts) + if _, err := conn.DisableVpcClassicLink(modifyOpts); err != nil { + return err + } + } + + d.SetPartial("enable_classiclink") + } + if err := setTags(conn, d); err != nil { return err } else { diff --git a/builtin/providers/aws/resource_aws_vpc_test.go b/builtin/providers/aws/resource_aws_vpc_test.go index e87762115..cd01bbf5d 100644 --- a/builtin/providers/aws/resource_aws_vpc_test.go +++ b/builtin/providers/aws/resource_aws_vpc_test.go @@ -206,6 +206,23 @@ func TestAccAWSVpc_bothDnsOptionsSet(t *testing.T) { }) } +func TestAccAWSVpc_classiclinkOptionSet(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckVpcDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccVpcConfig_ClassiclinkOption, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr( + "aws_vpc.bar", "enable_classiclink", "true"), + ), + }, + }, + }) +} + const testAccVpcConfig = ` resource "aws_vpc" "foo" { cidr_block = "10.1.0.0/16" @@ -254,3 +271,11 @@ resource "aws_vpc" "bar" { enable_dns_support = true } ` + +const testAccVpcConfig_ClassiclinkOption = ` +resource "aws_vpc" "bar" { + cidr_block = "172.2.0.0/16" + + enable_classiclink = true +} +` diff --git a/website/source/docs/providers/aws/r/vpc.html.markdown b/website/source/docs/providers/aws/r/vpc.html.markdown index 48e56d340..0e88ea309 100644 --- a/website/source/docs/providers/aws/r/vpc.html.markdown +++ b/website/source/docs/providers/aws/r/vpc.html.markdown @@ -41,6 +41,7 @@ The following arguments are supported: * `instance_tenancy` - (Optional) A tenancy option for instances launched into the VPC * `enable_dns_support` - (Optional) A boolean flag to enable/disable DNS support in the VPC. Defaults true. * `enable_dns_hostnames` - (Optional) A boolean flag to enable/disable DNS hostnames in the VPC. Defaults false. +* `enable_classiclink` - (Optional) A boolean flag to enable/disable ClassicLink for the VPC. Defaults false. * `tags` - (Optional) A mapping of tags to assign to the resource. ## Attributes Reference @@ -52,6 +53,7 @@ The following attributes are exported: * `instance_tenancy` - Tenancy of instances spin up within VPC. * `enable_dns_support` - Whether or not the VPC has DNS support * `enable_dns_hostnames` - Whether or not the VPC has DNS hostname support +* `enable_classiclink` - Whether or not the VPC has Classiclink enabled * `main_route_table_id` - The ID of the main route table associated with this VPC. Note that you can change a VPC's main route table by using an [`aws_main_route_table_association`](/docs/providers/aws/r/main_route_table_assoc.html).