forked from hashicorp/terraform
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
provider/aws: Implement IPV6 Support for ec2 / VPC (hashicorp#10538)
* provider/aws: Add support for IPV6 enabled VPC ``` % make testacc TEST=./builtin/providers/aws TESTARGS='-run=TestAccAWSVpc' ==> Checking that code complies with gofmt requirements... go generate $(go list ./... | grep -v /terraform/vendor/) 2016/12/09 14:07:31 Generated command/internal_plugin_list.go TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAccAWSVpc -timeout 120m === RUN TestAccAWSVpc_importBasic --- PASS: TestAccAWSVpc_importBasic (43.03s) === RUN TestAccAWSVpc_basic --- PASS: TestAccAWSVpc_basic (36.32s) === RUN TestAccAWSVpc_enableIpv6 --- PASS: TestAccAWSVpc_enableIpv6 (29.37s) === RUN TestAccAWSVpc_dedicatedTenancy --- PASS: TestAccAWSVpc_dedicatedTenancy (36.63s) === RUN TestAccAWSVpc_tags --- PASS: TestAccAWSVpc_tags (67.54s) === RUN TestAccAWSVpc_update --- PASS: TestAccAWSVpc_update (66.16s) === RUN TestAccAWSVpc_bothDnsOptionsSet --- PASS: TestAccAWSVpc_bothDnsOptionsSet (16.82s) === RUN TestAccAWSVpc_DisabledDnsSupport --- PASS: TestAccAWSVpc_DisabledDnsSupport (36.52s) === RUN TestAccAWSVpc_classiclinkOptionSet --- PASS: TestAccAWSVpc_classiclinkOptionSet (38.13s) PASS ok github.com/hashicorp/terraform/builtin/providers/aws 739.543s ``` * provider/aws: New Resource: aws_egress_only_internet_gateway ``` make testacc TEST=./builtin/providers/aws TESTARGS='-run=TestAccAWSEgressOnlyInternetGateway_' ==> Checking that code complies with gofmt requirements... go generate $(go list ./... | grep -v /terraform/vendor/) 2016/12/09 14:22:16 Generated command/internal_plugin_list.go TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAccAWSEgressOnlyInternetGateway_ -timeout 120m === RUN TestAccAWSEgressOnlyInternetGateway_basic --- PASS: TestAccAWSEgressOnlyInternetGateway_basic (32.67s) PASS ok github.com/hashicorp/terraform/builtin/providers/aws 32.692s ``` * provider/aws: Add IPV6 support to aws_subnet ``` % make testacc TEST=./builtin/providers/aws % TESTARGS='-run=TestAccAWSSubnet_' % 1 ↵ ✹ ✭ ==> Checking that code complies with gofmt requirements... go generate $(go list ./... | grep -v /terraform/vendor/) 2017/02/27 19:08:34 Generated command/internal_plugin_list.go TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAccAWSSubnet_ -timeout 120m === RUN TestAccAWSSubnet_importBasic --- PASS: TestAccAWSSubnet_importBasic (69.88s) === RUN TestAccAWSSubnet_basic --- PASS: TestAccAWSSubnet_basic (51.28s) === RUN TestAccAWSSubnet_ipv6 --- PASS: TestAccAWSSubnet_ipv6 (90.39s) PASS ok github.com/hashicorp/terraform/builtin/providers/aws211.574s ``` * provider/aws: Add support for running aws_instances with ipv6 addresses
- Loading branch information
Showing
14 changed files
with
568 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
126 changes: 126 additions & 0 deletions
126
builtin/providers/aws/resource_aws_egress_only_internet_gateway.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
package aws | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"time" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/aws/awserr" | ||
"github.com/aws/aws-sdk-go/service/ec2" | ||
"github.com/hashicorp/errwrap" | ||
"github.com/hashicorp/terraform/helper/resource" | ||
"github.com/hashicorp/terraform/helper/schema" | ||
) | ||
|
||
func resourceAwsEgressOnlyInternetGateway() *schema.Resource { | ||
return &schema.Resource{ | ||
Create: resourceAwsEgressOnlyInternetGatewayCreate, | ||
Read: resourceAwsEgressOnlyInternetGatewayRead, | ||
Delete: resourceAwsEgressOnlyInternetGatewayDelete, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"vpc_id": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func resourceAwsEgressOnlyInternetGatewayCreate(d *schema.ResourceData, meta interface{}) error { | ||
conn := meta.(*AWSClient).ec2conn | ||
|
||
resp, err := conn.CreateEgressOnlyInternetGateway(&ec2.CreateEgressOnlyInternetGatewayInput{ | ||
VpcId: aws.String(d.Get("vpc_id").(string)), | ||
}) | ||
if err != nil { | ||
return fmt.Errorf("Error creating egress internet gateway: %s", err) | ||
} | ||
|
||
d.SetId(*resp.EgressOnlyInternetGateway.EgressOnlyInternetGatewayId) | ||
|
||
err = resource.Retry(5*time.Minute, func() *resource.RetryError { | ||
igRaw, _, err := EIGWStateRefreshFunc(conn, d.Id())() | ||
if igRaw != nil { | ||
return nil | ||
} | ||
if err == nil { | ||
return resource.RetryableError(err) | ||
} else { | ||
return resource.NonRetryableError(err) | ||
} | ||
}) | ||
|
||
if err != nil { | ||
return errwrap.Wrapf("{{err}}", err) | ||
} | ||
|
||
return resourceAwsEgressOnlyInternetGatewayRead(d, meta) | ||
} | ||
|
||
func EIGWStateRefreshFunc(conn *ec2.EC2, id string) resource.StateRefreshFunc { | ||
return func() (interface{}, string, error) { | ||
resp, err := conn.DescribeEgressOnlyInternetGateways(&ec2.DescribeEgressOnlyInternetGatewaysInput{ | ||
EgressOnlyInternetGatewayIds: []*string{aws.String(id)}, | ||
}) | ||
if err != nil { | ||
ec2err, ok := err.(awserr.Error) | ||
if ok && ec2err.Code() == "InvalidEgressInternetGatewayID.NotFound" { | ||
resp = nil | ||
} else { | ||
log.Printf("[ERROR] Error on EIGWStateRefreshFunc: %s", err) | ||
return nil, "", err | ||
} | ||
} | ||
|
||
if resp == nil { | ||
// Sometimes AWS just has consistency issues and doesn't see | ||
// our instance yet. Return an empty state. | ||
return nil, "", nil | ||
} | ||
|
||
ig := resp.EgressOnlyInternetGateways[0] | ||
return ig, "available", nil | ||
} | ||
} | ||
|
||
func resourceAwsEgressOnlyInternetGatewayRead(d *schema.ResourceData, meta interface{}) error { | ||
conn := meta.(*AWSClient).ec2conn | ||
|
||
resp, err := conn.DescribeEgressOnlyInternetGateways(&ec2.DescribeEgressOnlyInternetGatewaysInput{ | ||
EgressOnlyInternetGatewayIds: []*string{aws.String(d.Id())}, | ||
}) | ||
if err != nil { | ||
return fmt.Errorf("Error describing egress internet gateway: %s", err) | ||
} | ||
|
||
found := false | ||
for _, igw := range resp.EgressOnlyInternetGateways { | ||
if *igw.EgressOnlyInternetGatewayId == d.Id() { | ||
found = true | ||
} | ||
} | ||
|
||
if !found { | ||
log.Printf("[Error] Cannot find Egress Only Internet Gateway: %q", d.Id()) | ||
d.SetId("") | ||
return nil | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func resourceAwsEgressOnlyInternetGatewayDelete(d *schema.ResourceData, meta interface{}) error { | ||
conn := meta.(*AWSClient).ec2conn | ||
|
||
_, err := conn.DeleteEgressOnlyInternetGateway(&ec2.DeleteEgressOnlyInternetGatewayInput{ | ||
EgressOnlyInternetGatewayId: aws.String(d.Id()), | ||
}) | ||
if err != nil { | ||
return fmt.Errorf("Error deleting egress internet gateway: %s", err) | ||
} | ||
|
||
return nil | ||
} |
92 changes: 92 additions & 0 deletions
92
builtin/providers/aws/resource_aws_egress_only_internet_gateway_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package aws | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/ec2" | ||
"github.com/hashicorp/terraform/helper/resource" | ||
"github.com/hashicorp/terraform/terraform" | ||
) | ||
|
||
func TestAccAWSEgressOnlyInternetGateway_basic(t *testing.T) { | ||
var igw ec2.EgressOnlyInternetGateway | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccCheckAWSEgressOnlyInternetGatewayDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccAWSEgressOnlyInternetGatewayConfig_basic, | ||
Check: resource.ComposeAggregateTestCheckFunc( | ||
testAccCheckAWSEgressOnlyInternetGatewayExists("aws_egress_only_internet_gateway.foo", &igw), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccCheckAWSEgressOnlyInternetGatewayDestroy(s *terraform.State) error { | ||
conn := testAccProvider.Meta().(*AWSClient).ec2conn | ||
|
||
for _, rs := range s.RootModule().Resources { | ||
if rs.Type != "aws_egress_only_internet_gateway" { | ||
continue | ||
} | ||
|
||
describe, err := conn.DescribeEgressOnlyInternetGateways(&ec2.DescribeEgressOnlyInternetGatewaysInput{ | ||
EgressOnlyInternetGatewayIds: []*string{aws.String(rs.Primary.ID)}, | ||
}) | ||
|
||
if err == nil { | ||
if len(describe.EgressOnlyInternetGateways) != 0 && | ||
*describe.EgressOnlyInternetGateways[0].EgressOnlyInternetGatewayId == rs.Primary.ID { | ||
return fmt.Errorf("Egress Only Internet Gateway %q still exists", rs.Primary.ID) | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func testAccCheckAWSEgressOnlyInternetGatewayExists(n string, igw *ec2.EgressOnlyInternetGateway) resource.TestCheckFunc { | ||
return func(s *terraform.State) error { | ||
rs, ok := s.RootModule().Resources[n] | ||
if !ok { | ||
return fmt.Errorf("Not found: %s", n) | ||
} | ||
|
||
if rs.Primary.ID == "" { | ||
return fmt.Errorf("No Egress Only IGW ID is set") | ||
} | ||
|
||
conn := testAccProvider.Meta().(*AWSClient).ec2conn | ||
resp, err := conn.DescribeEgressOnlyInternetGateways(&ec2.DescribeEgressOnlyInternetGatewaysInput{ | ||
EgressOnlyInternetGatewayIds: []*string{aws.String(rs.Primary.ID)}, | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
if len(resp.EgressOnlyInternetGateways) == 0 { | ||
return fmt.Errorf("Egress Only IGW not found") | ||
} | ||
|
||
*igw = *resp.EgressOnlyInternetGateways[0] | ||
|
||
return nil | ||
} | ||
} | ||
|
||
const testAccAWSEgressOnlyInternetGatewayConfig_basic = ` | ||
resource "aws_vpc" "foo" { | ||
cidr_block = "10.1.0.0/16" | ||
assign_generated_ipv6_cidr_block = true | ||
} | ||
resource "aws_egress_only_internet_gateway" "foo" { | ||
vpc_id = "${aws_vpc.foo.id}" | ||
} | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.