Skip to content

Commit

Permalink
Merge pull request #1176 from terraform-providers/b-r-vpc-classic-link
Browse files Browse the repository at this point in the history
r/vpc: Ignore ClassicLink DNS support in unsupported regions
  • Loading branch information
radeksimko authored Jul 18, 2017
2 parents 0743bf7 + f3672e8 commit 7a33d59
Showing 1 changed file with 20 additions and 19 deletions.
39 changes: 20 additions & 19 deletions aws/resource_aws_vpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,32 +196,32 @@ func resourceAwsVpcRead(d *schema.ResourceData, meta interface{}) error {

// Attributes
attribute := "enableDnsSupport"
DescribeAttrOpts := &ec2.DescribeVpcAttributeInput{
describeAttrOpts := &ec2.DescribeVpcAttributeInput{
Attribute: aws.String(attribute),
VpcId: aws.String(vpcid),
}
resp, err := conn.DescribeVpcAttribute(DescribeAttrOpts)
resp, err := conn.DescribeVpcAttribute(describeAttrOpts)
if err != nil {
return err
}
d.Set("enable_dns_support", *resp.EnableDnsSupport.Value)
attribute = "enableDnsHostnames"
DescribeAttrOpts = &ec2.DescribeVpcAttributeInput{
describeAttrOpts = &ec2.DescribeVpcAttributeInput{
Attribute: &attribute,
VpcId: &vpcid,
}
resp, err = conn.DescribeVpcAttribute(DescribeAttrOpts)
resp, err = conn.DescribeVpcAttribute(describeAttrOpts)
if err != nil {
return err
}
d.Set("enable_dns_hostnames", *resp.EnableDnsHostnames.Value)

DescribeClassiclinkOpts := &ec2.DescribeVpcClassicLinkInput{
describeClassiclinkOpts := &ec2.DescribeVpcClassicLinkInput{
VpcIds: []*string{&vpcid},
}

// Classic Link is only available in regions that support EC2 Classic
respClassiclink, err := conn.DescribeVpcClassicLink(DescribeClassiclinkOpts)
respClassiclink, err := conn.DescribeVpcClassicLink(describeClassiclinkOpts)
if err != nil {
if awsErr, ok := err.(awserr.Error); ok && awsErr.Code() == "UnsupportedOperation" {
log.Printf("[WARN] VPC Classic Link is not supported in this region")
Expand All @@ -241,13 +241,14 @@ func resourceAwsVpcRead(d *schema.ResourceData, meta interface{}) error {
d.Set("enable_classiclink", classiclink_enabled)
}

DescribeClassiclinkDnsOpts := &ec2.DescribeVpcClassicLinkDnsSupportInput{
describeClassiclinkDnsOpts := &ec2.DescribeVpcClassicLinkDnsSupportInput{
VpcIds: []*string{&vpcid},
}

respClassiclinkDnsSupport, err := conn.DescribeVpcClassicLinkDnsSupport(DescribeClassiclinkDnsOpts)
respClassiclinkDnsSupport, err := conn.DescribeVpcClassicLinkDnsSupport(describeClassiclinkDnsOpts)
if err != nil {
if awsErr, ok := err.(awserr.Error); ok && awsErr.Code() == "UnsupportedOperation" {
if isAWSErr(err, "UnsupportedOperation", "The functionality you requested is not available in this region") ||
isAWSErr(err, "AuthFailure", "This request has been administratively disabled") {
log.Printf("[WARN] VPC Classic Link DNS Support is not supported in this region")
} else {
return err
Expand Down Expand Up @@ -275,10 +276,10 @@ func resourceAwsVpcRead(d *schema.ResourceData, meta interface{}) error {
Name: aws.String("vpc-id"),
Values: []*string{aws.String(d.Id())},
}
DescribeRouteOpts := &ec2.DescribeRouteTablesInput{
describeRouteOpts := &ec2.DescribeRouteTablesInput{
Filters: []*ec2.Filter{filter1, filter2},
}
routeResp, err := conn.DescribeRouteTables(DescribeRouteOpts)
routeResp, err := conn.DescribeRouteTables(describeRouteOpts)
if err != nil {
return err
}
Expand Down Expand Up @@ -474,13 +475,13 @@ func resourceAwsVpcUpdate(d *schema.ResourceData, meta interface{}) error {
func resourceAwsVpcDelete(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).ec2conn
vpcID := d.Id()
DeleteVpcOpts := &ec2.DeleteVpcInput{
deleteVpcOpts := &ec2.DeleteVpcInput{
VpcId: &vpcID,
}
log.Printf("[INFO] Deleting VPC: %s", d.Id())

return resource.Retry(5*time.Minute, func() *resource.RetryError {
_, err := conn.DeleteVpc(DeleteVpcOpts)
_, err := conn.DeleteVpc(deleteVpcOpts)
if err == nil {
return nil
}
Expand All @@ -505,10 +506,10 @@ func resourceAwsVpcDelete(d *schema.ResourceData, meta interface{}) error {
// a VPC.
func VPCStateRefreshFunc(conn *ec2.EC2, id string) resource.StateRefreshFunc {
return func() (interface{}, string, error) {
DescribeVpcOpts := &ec2.DescribeVpcsInput{
describeVpcOpts := &ec2.DescribeVpcsInput{
VpcIds: []*string{aws.String(id)},
}
resp, err := conn.DescribeVpcs(DescribeVpcOpts)
resp, err := conn.DescribeVpcs(describeVpcOpts)
if err != nil {
if ec2err, ok := err.(awserr.Error); ok && ec2err.Code() == "InvalidVpcID.NotFound" {
resp = nil
Expand Down Expand Up @@ -573,10 +574,10 @@ func resourceAwsVpcSetDefaultNetworkAcl(conn *ec2.EC2, d *schema.ResourceData) e
Name: aws.String("vpc-id"),
Values: []*string{aws.String(d.Id())},
}
DescribeNetworkACLOpts := &ec2.DescribeNetworkAclsInput{
describeNetworkACLOpts := &ec2.DescribeNetworkAclsInput{
Filters: []*ec2.Filter{filter1, filter2},
}
networkAclResp, err := conn.DescribeNetworkAcls(DescribeNetworkACLOpts)
networkAclResp, err := conn.DescribeNetworkAcls(describeNetworkACLOpts)

if err != nil {
return err
Expand All @@ -597,10 +598,10 @@ func resourceAwsVpcSetDefaultSecurityGroup(conn *ec2.EC2, d *schema.ResourceData
Name: aws.String("vpc-id"),
Values: []*string{aws.String(d.Id())},
}
DescribeSgOpts := &ec2.DescribeSecurityGroupsInput{
describeSgOpts := &ec2.DescribeSecurityGroupsInput{
Filters: []*ec2.Filter{filter1, filter2},
}
securityGroupResp, err := conn.DescribeSecurityGroups(DescribeSgOpts)
securityGroupResp, err := conn.DescribeSecurityGroups(describeSgOpts)

if err != nil {
return err
Expand Down

0 comments on commit 7a33d59

Please sign in to comment.