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

Add AWS Classiclink for AWS VPC resource #3994

Merged
merged 1 commit into from
Jan 12, 2016
Merged
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
50 changes: 50 additions & 0 deletions builtin/providers/aws/resource_aws_vpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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 {
Expand Down
25 changes: 25 additions & 0 deletions builtin/providers/aws/resource_aws_vpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
`
2 changes: 2 additions & 0 deletions website/source/docs/providers/aws/r/vpc.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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).
Expand Down