mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-20 11:48:24 -06:00
* 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
207 lines
4.4 KiB
Go
207 lines
4.4 KiB
Go
package aws
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"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/terraform/helper/resource"
|
|
"github.com/hashicorp/terraform/terraform"
|
|
)
|
|
|
|
func TestAccAWSSubnet_basic(t *testing.T) {
|
|
var v ec2.Subnet
|
|
|
|
testCheck := func(*terraform.State) error {
|
|
if *v.CidrBlock != "10.1.1.0/24" {
|
|
return fmt.Errorf("bad cidr: %s", *v.CidrBlock)
|
|
}
|
|
|
|
if *v.MapPublicIpOnLaunch != true {
|
|
return fmt.Errorf("bad MapPublicIpOnLaunch: %t", *v.MapPublicIpOnLaunch)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
IDRefreshName: "aws_subnet.foo",
|
|
Providers: testAccProviders,
|
|
CheckDestroy: testAccCheckSubnetDestroy,
|
|
Steps: []resource.TestStep{
|
|
{
|
|
Config: testAccSubnetConfig,
|
|
Check: resource.ComposeTestCheckFunc(
|
|
testAccCheckSubnetExists(
|
|
"aws_subnet.foo", &v),
|
|
testCheck,
|
|
),
|
|
},
|
|
},
|
|
})
|
|
}
|
|
|
|
func TestAccAWSSubnet_ipv6(t *testing.T) {
|
|
var v ec2.Subnet
|
|
|
|
testCheck := func(*terraform.State) error {
|
|
if v.Ipv6CidrBlockAssociationSet == nil {
|
|
return fmt.Errorf("Expected IPV6 CIDR Block Association")
|
|
}
|
|
|
|
if *v.AssignIpv6AddressOnCreation != true {
|
|
return fmt.Errorf("bad AssignIpv6AddressOnCreation: %t", *v.AssignIpv6AddressOnCreation)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
testCheckUpdated := func(*terraform.State) error {
|
|
if *v.AssignIpv6AddressOnCreation != false {
|
|
return fmt.Errorf("bad AssignIpv6AddressOnCreation: %t", *v.AssignIpv6AddressOnCreation)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
IDRefreshName: "aws_subnet.foo",
|
|
Providers: testAccProviders,
|
|
CheckDestroy: testAccCheckSubnetDestroy,
|
|
Steps: []resource.TestStep{
|
|
{
|
|
Config: testAccSubnetConfigIpv6,
|
|
Check: resource.ComposeTestCheckFunc(
|
|
testAccCheckSubnetExists(
|
|
"aws_subnet.foo", &v),
|
|
testCheck,
|
|
),
|
|
},
|
|
{
|
|
Config: testAccSubnetConfigIpv6Updated,
|
|
Check: resource.ComposeTestCheckFunc(
|
|
testAccCheckSubnetExists(
|
|
"aws_subnet.foo", &v),
|
|
testCheckUpdated,
|
|
),
|
|
},
|
|
},
|
|
})
|
|
}
|
|
|
|
func testAccCheckSubnetDestroy(s *terraform.State) error {
|
|
conn := testAccProvider.Meta().(*AWSClient).ec2conn
|
|
|
|
for _, rs := range s.RootModule().Resources {
|
|
if rs.Type != "aws_subnet" {
|
|
continue
|
|
}
|
|
|
|
// Try to find the resource
|
|
resp, err := conn.DescribeSubnets(&ec2.DescribeSubnetsInput{
|
|
SubnetIds: []*string{aws.String(rs.Primary.ID)},
|
|
})
|
|
if err == nil {
|
|
if len(resp.Subnets) > 0 {
|
|
return fmt.Errorf("still exist.")
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// Verify the error is what we want
|
|
ec2err, ok := err.(awserr.Error)
|
|
if !ok {
|
|
return err
|
|
}
|
|
if ec2err.Code() != "InvalidSubnetID.NotFound" {
|
|
return err
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func testAccCheckSubnetExists(n string, v *ec2.Subnet) 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 ID is set")
|
|
}
|
|
|
|
conn := testAccProvider.Meta().(*AWSClient).ec2conn
|
|
resp, err := conn.DescribeSubnets(&ec2.DescribeSubnetsInput{
|
|
SubnetIds: []*string{aws.String(rs.Primary.ID)},
|
|
})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if len(resp.Subnets) == 0 {
|
|
return fmt.Errorf("Subnet not found")
|
|
}
|
|
|
|
*v = *resp.Subnets[0]
|
|
|
|
return nil
|
|
}
|
|
}
|
|
|
|
const testAccSubnetConfig = `
|
|
resource "aws_vpc" "foo" {
|
|
cidr_block = "10.1.0.0/16"
|
|
}
|
|
|
|
resource "aws_subnet" "foo" {
|
|
cidr_block = "10.1.1.0/24"
|
|
vpc_id = "${aws_vpc.foo.id}"
|
|
map_public_ip_on_launch = true
|
|
tags {
|
|
Name = "tf-subnet-acc-test"
|
|
}
|
|
}
|
|
`
|
|
|
|
const testAccSubnetConfigIpv6 = `
|
|
resource "aws_vpc" "foo" {
|
|
cidr_block = "10.10.0.0/16"
|
|
assign_generated_ipv6_cidr_block = true
|
|
}
|
|
|
|
resource "aws_subnet" "foo" {
|
|
cidr_block = "10.10.1.0/24"
|
|
vpc_id = "${aws_vpc.foo.id}"
|
|
ipv6_cidr_block = "${cidrsubnet(aws_vpc.foo.ipv6_cidr_block, 8, 1)}"
|
|
map_public_ip_on_launch = true
|
|
assign_ipv6_address_on_creation = true
|
|
tags {
|
|
Name = "tf-subnet-acc-test"
|
|
}
|
|
}
|
|
`
|
|
|
|
const testAccSubnetConfigIpv6Updated = `
|
|
resource "aws_vpc" "foo" {
|
|
cidr_block = "10.10.0.0/16"
|
|
assign_generated_ipv6_cidr_block = true
|
|
}
|
|
|
|
resource "aws_subnet" "foo" {
|
|
cidr_block = "10.10.1.0/24"
|
|
vpc_id = "${aws_vpc.foo.id}"
|
|
ipv6_cidr_block = "${cidrsubnet(aws_vpc.foo.ipv6_cidr_block, 8, 3)}"
|
|
map_public_ip_on_launch = true
|
|
assign_ipv6_address_on_creation = false
|
|
tags {
|
|
Name = "tf-subnet-acc-test"
|
|
}
|
|
}
|
|
`
|