terraform/builtin/providers/aws/resource_aws_vpc.go

484 lines
12 KiB
Go
Raw Normal View History

2014-07-07 21:16:58 +02:00
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"
2014-07-07 21:16:58 +02:00
"github.com/hashicorp/terraform/helper/resource"
2014-10-09 02:54:00 +02:00
"github.com/hashicorp/terraform/helper/schema"
2014-07-07 21:16:58 +02:00
)
func resourceAwsVpc() *schema.Resource {
return &schema.Resource{
Create: resourceAwsVpcCreate,
Read: resourceAwsVpcRead,
Update: resourceAwsVpcUpdate,
Delete: resourceAwsVpcDelete,
2016-05-13 02:57:12 +02:00
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},
Schema: map[string]*schema.Schema{
"cidr_block": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validateCIDRNetworkAddress,
},
"instance_tenancy": {
2014-12-10 11:39:14 +01:00
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Computed: true,
2014-12-10 11:39:14 +01:00
},
"enable_dns_hostnames": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
},
"enable_dns_support": {
Type: schema.TypeBool,
Optional: true,
Default: true,
},
2014-10-09 02:54:00 +02:00
"enable_classiclink": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
},
provider/aws: Implement IPV6 Support for ec2 / VPC (#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
2017-03-01 17:16:59 +01:00
"assign_generated_ipv6_cidr_block": {
Type: schema.TypeBool,
ForceNew: true,
Optional: true,
Default: false,
},
"main_route_table_id": {
Type: schema.TypeString,
Computed: true,
},
"default_network_acl_id": {
Type: schema.TypeString,
Computed: true,
},
"dhcp_options_id": {
Type: schema.TypeString,
Computed: true,
},
"default_security_group_id": {
Type: schema.TypeString,
Computed: true,
},
"default_route_table_id": {
Type: schema.TypeString,
Computed: true,
},
provider/aws: Implement IPV6 Support for ec2 / VPC (#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
2017-03-01 17:16:59 +01:00
"ipv6_association_id": {
Type: schema.TypeString,
Computed: true,
},
"ipv6_cidr_block": {
Type: schema.TypeString,
Computed: true,
},
2015-03-09 10:09:06 +01:00
"tags": tagsSchema(),
},
}
}
func resourceAwsVpcCreate(d *schema.ResourceData, meta interface{}) error {
2015-04-16 22:05:55 +02:00
conn := meta.(*AWSClient).ec2conn
2015-02-25 10:34:17 +01:00
instance_tenancy := "default"
if v, ok := d.GetOk("instance_tenancy"); ok {
instance_tenancy = v.(string)
}
provider/aws: Implement IPV6 Support for ec2 / VPC (#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
2017-03-01 17:16:59 +01:00
2014-07-07 21:16:58 +02:00
// Create the VPC
createOpts := &ec2.CreateVpcInput{
provider/aws: Implement IPV6 Support for ec2 / VPC (#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
2017-03-01 17:16:59 +01:00
CidrBlock: aws.String(d.Get("cidr_block").(string)),
InstanceTenancy: aws.String(instance_tenancy),
AmazonProvidedIpv6CidrBlock: aws.Bool(d.Get("assign_generated_ipv6_cidr_block").(bool)),
2014-07-07 21:16:58 +02:00
}
provider/aws: Implement IPV6 Support for ec2 / VPC (#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
2017-03-01 17:16:59 +01:00
2015-02-25 10:34:17 +01:00
log.Printf("[DEBUG] VPC create config: %#v", *createOpts)
vpcResp, err := conn.CreateVpc(createOpts)
2014-07-07 21:16:58 +02:00
if err != nil {
2015-03-12 21:13:45 +01:00
return fmt.Errorf("Error creating VPC: %s", err)
2014-07-07 21:16:58 +02:00
}
// Get the ID and store it
vpc := vpcResp.Vpc
d.SetId(*vpc.VpcId)
2015-02-25 10:34:17 +01:00
log.Printf("[INFO] VPC ID: %s", d.Id())
// Set partial mode and say that we setup the cidr block
d.Partial(true)
d.SetPartial("cidr_block")
2014-07-07 21:16:58 +02:00
// Wait for the VPC to become available
log.Printf(
"[DEBUG] Waiting for VPC (%s) to become available",
d.Id())
2014-07-07 21:16:58 +02:00
stateConf := &resource.StateChangeConf{
Pending: []string{"pending"},
Target: []string{"available"},
Refresh: VPCStateRefreshFunc(conn, d.Id()),
2014-07-07 21:16:58 +02:00
Timeout: 10 * time.Minute,
}
if _, err := stateConf.WaitForState(); err != nil {
return fmt.Errorf(
2014-07-07 21:16:58 +02:00
"Error waiting for VPC (%s) to become available: %s",
d.Id(), err)
2014-08-09 14:43:00 +02:00
}
2014-07-07 21:16:58 +02:00
// Update our attributes and return
return resourceAwsVpcUpdate(d, meta)
2014-07-07 21:16:58 +02:00
}
func resourceAwsVpcRead(d *schema.ResourceData, meta interface{}) error {
2015-04-16 22:05:55 +02:00
conn := meta.(*AWSClient).ec2conn
// Refresh the VPC state
vpcRaw, _, err := VPCStateRefreshFunc(conn, d.Id())()
if err != nil {
return err
}
if vpcRaw == nil {
d.SetId("")
return nil
}
// VPC stuff
vpc := vpcRaw.(*ec2.Vpc)
2015-02-25 10:34:17 +01:00
vpcid := d.Id()
d.Set("cidr_block", vpc.CidrBlock)
d.Set("dhcp_options_id", vpc.DhcpOptionsId)
d.Set("instance_tenancy", vpc.InstanceTenancy)
2015-03-04 14:07:30 +01:00
// Tags
d.Set("tags", tagsToMap(vpc.Tags))
provider/aws: Implement IPV6 Support for ec2 / VPC (#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
2017-03-01 17:16:59 +01:00
if vpc.Ipv6CidrBlockAssociationSet != nil {
d.Set("assign_generated_ipv6_cidr_block", true)
d.Set("ipv6_association_id", vpc.Ipv6CidrBlockAssociationSet[0].AssociationId)
d.Set("ipv6_cidr_block", vpc.Ipv6CidrBlockAssociationSet[0].Ipv6CidrBlock)
} else {
d.Set("assign_generated_ipv6_cidr_block", false)
}
// Attributes
2015-02-25 10:34:17 +01:00
attribute := "enableDnsSupport"
DescribeAttrOpts := &ec2.DescribeVpcAttributeInput{
2015-03-12 21:13:45 +01:00
Attribute: aws.String(attribute),
VpcId: aws.String(vpcid),
2015-02-25 10:34:17 +01:00
}
resp, err := conn.DescribeVpcAttribute(DescribeAttrOpts)
if err != nil {
return err
}
d.Set("enable_dns_support", *resp.EnableDnsSupport.Value)
2015-02-25 10:34:17 +01:00
attribute = "enableDnsHostnames"
DescribeAttrOpts = &ec2.DescribeVpcAttributeInput{
2015-02-25 10:34:17 +01:00
Attribute: &attribute,
VpcId: &vpcid,
2015-02-25 10:34:17 +01:00
}
resp, err = conn.DescribeVpcAttribute(DescribeAttrOpts)
if err != nil {
return err
}
d.Set("enable_dns_hostnames", *resp.EnableDnsHostnames.Value)
DescribeClassiclinkOpts := &ec2.DescribeVpcClassicLinkInput{
VpcIds: []*string{&vpcid},
}
// Classic Link is only available in regions that support EC2 Classic
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")
} else {
return err
}
} else {
classiclink_enabled := false
for _, v := range respClassiclink.Vpcs {
if *v.VpcId == vpcid {
if v.ClassicLinkEnabled != nil {
classiclink_enabled = *v.ClassicLinkEnabled
}
break
}
}
d.Set("enable_classiclink", classiclink_enabled)
}
// Get the main routing table for this VPC
2015-02-25 10:34:17 +01:00
// Really Ugly need to make this better - rmenn
filter1 := &ec2.Filter{
Name: aws.String("association.main"),
Values: []*string{aws.String("true")},
2015-02-25 10:34:17 +01:00
}
filter2 := &ec2.Filter{
Name: aws.String("vpc-id"),
Values: []*string{aws.String(d.Id())},
2015-02-25 10:34:17 +01:00
}
DescribeRouteOpts := &ec2.DescribeRouteTablesInput{
Filters: []*ec2.Filter{filter1, filter2},
2015-02-25 10:34:17 +01:00
}
routeResp, err := conn.DescribeRouteTables(DescribeRouteOpts)
if err != nil {
return err
}
if v := routeResp.RouteTables; len(v) > 0 {
d.Set("main_route_table_id", *v[0].RouteTableId)
}
if err := resourceAwsVpcSetDefaultNetworkAcl(conn, d); err != nil {
log.Printf("[WARN] Unable to set Default Network ACL: %s", err)
}
if err := resourceAwsVpcSetDefaultSecurityGroup(conn, d); err != nil {
log.Printf("[WARN] Unable to set Default Security Group: %s", err)
}
if err := resourceAwsVpcSetDefaultRouteTable(conn, d); err != nil {
log.Printf("[WARN] Unable to set Default Route Table: %s", err)
}
return nil
}
func resourceAwsVpcUpdate(d *schema.ResourceData, meta interface{}) error {
2015-04-16 22:05:55 +02:00
conn := meta.(*AWSClient).ec2conn
2014-08-09 14:43:00 +02:00
// Turn on partial mode
d.Partial(true)
2015-02-25 10:34:17 +01:00
vpcid := d.Id()
if d.HasChange("enable_dns_hostnames") {
2015-02-25 10:34:17 +01:00
val := d.Get("enable_dns_hostnames").(bool)
modifyOpts := &ec2.ModifyVpcAttributeInput{
VpcId: &vpcid,
EnableDnsHostnames: &ec2.AttributeBooleanValue{
Value: &val,
},
2015-02-25 10:34:17 +01:00
}
2014-08-09 14:43:00 +02:00
log.Printf(
"[INFO] Modifying enable_dns_hostnames vpc attribute for %s: %s",
2015-02-25 10:34:17 +01:00
d.Id(), modifyOpts)
if _, err := conn.ModifyVpcAttribute(modifyOpts); err != nil {
return err
2014-08-09 14:43:00 +02:00
}
d.SetPartial("enable_dns_hostnames")
2014-08-09 14:43:00 +02:00
}
_, hasEnableDnsSupportOption := d.GetOk("enable_dns_support")
if !hasEnableDnsSupportOption || d.HasChange("enable_dns_support") {
val := d.Get("enable_dns_support").(bool)
modifyOpts := &ec2.ModifyVpcAttributeInput{
VpcId: &vpcid,
EnableDnsSupport: &ec2.AttributeBooleanValue{
Value: &val,
},
2015-02-25 10:34:17 +01:00
}
2014-08-09 14:43:00 +02:00
log.Printf(
"[INFO] Modifying enable_dns_support vpc attribute for %s: %s",
2015-02-25 10:34:17 +01:00
d.Id(), modifyOpts)
if _, err := conn.ModifyVpcAttribute(modifyOpts); err != nil {
return err
2014-08-09 14:43:00 +02:00
}
d.SetPartial("enable_dns_support")
2014-08-09 14:43:00 +02:00
}
2015-03-04 14:07:30 +01:00
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 {
2015-03-04 14:07:30 +01:00
return err
} else {
d.SetPartial("tags")
}
2014-10-09 02:54:00 +02:00
d.Partial(false)
return resourceAwsVpcRead(d, meta)
2014-07-07 21:16:58 +02:00
}
func resourceAwsVpcDelete(d *schema.ResourceData, meta interface{}) error {
2015-04-16 22:05:55 +02:00
conn := meta.(*AWSClient).ec2conn
2015-02-25 10:34:17 +01:00
vpcID := d.Id()
DeleteVpcOpts := &ec2.DeleteVpcInput{
VpcId: &vpcID,
2015-02-25 10:34:17 +01:00
}
log.Printf("[INFO] Deleting VPC: %s", d.Id())
return resource.Retry(5*time.Minute, func() *resource.RetryError {
_, err := conn.DeleteVpc(DeleteVpcOpts)
if err == nil {
return nil
}
ec2err, ok := err.(awserr.Error)
if !ok {
return resource.NonRetryableError(err)
}
2014-07-07 21:16:58 +02:00
switch ec2err.Code() {
case "InvalidVpcID.NotFound":
return nil
case "DependencyViolation":
return resource.RetryableError(err)
}
return resource.NonRetryableError(fmt.Errorf("Error deleting VPC: %s", err))
})
2014-07-07 21:16:58 +02:00
}
// VPCStateRefreshFunc returns a resource.StateRefreshFunc that is used to watch
// a VPC.
func VPCStateRefreshFunc(conn *ec2.EC2, id string) resource.StateRefreshFunc {
return func() (interface{}, string, error) {
DescribeVpcOpts := &ec2.DescribeVpcsInput{
VpcIds: []*string{aws.String(id)},
2015-02-25 10:34:17 +01:00
}
resp, err := conn.DescribeVpcs(DescribeVpcOpts)
2014-07-07 21:16:58 +02:00
if err != nil {
if ec2err, ok := err.(awserr.Error); ok && ec2err.Code() == "InvalidVpcID.NotFound" {
resp = nil
} else {
log.Printf("Error on VPCStateRefresh: %s", err)
return nil, "", err
}
2014-07-07 21:16:58 +02:00
}
if resp == nil {
// Sometimes AWS just has consistency issues and doesn't see
// our instance yet. Return an empty state.
return nil, "", nil
}
vpc := resp.Vpcs[0]
2015-02-25 10:34:17 +01:00
return vpc, *vpc.State, nil
2014-07-07 21:16:58 +02:00
}
}
func resourceAwsVpcSetDefaultNetworkAcl(conn *ec2.EC2, d *schema.ResourceData) error {
2015-02-25 10:34:17 +01:00
filter1 := &ec2.Filter{
Name: aws.String("default"),
Values: []*string{aws.String("true")},
2015-02-25 10:34:17 +01:00
}
filter2 := &ec2.Filter{
Name: aws.String("vpc-id"),
Values: []*string{aws.String(d.Id())},
2015-02-25 10:34:17 +01:00
}
DescribeNetworkACLOpts := &ec2.DescribeNetworkAclsInput{
Filters: []*ec2.Filter{filter1, filter2},
2015-02-25 10:34:17 +01:00
}
networkAclResp, err := conn.DescribeNetworkAcls(DescribeNetworkACLOpts)
if err != nil {
return err
}
if v := networkAclResp.NetworkAcls; len(v) > 0 {
d.Set("default_network_acl_id", v[0].NetworkAclId)
}
return nil
}
func resourceAwsVpcSetDefaultSecurityGroup(conn *ec2.EC2, d *schema.ResourceData) error {
2015-02-25 10:34:17 +01:00
filter1 := &ec2.Filter{
Name: aws.String("group-name"),
Values: []*string{aws.String("default")},
2015-02-25 10:34:17 +01:00
}
filter2 := &ec2.Filter{
Name: aws.String("vpc-id"),
Values: []*string{aws.String(d.Id())},
2015-02-25 10:34:17 +01:00
}
DescribeSgOpts := &ec2.DescribeSecurityGroupsInput{
Filters: []*ec2.Filter{filter1, filter2},
2015-02-25 10:34:17 +01:00
}
securityGroupResp, err := conn.DescribeSecurityGroups(DescribeSgOpts)
if err != nil {
return err
}
2015-02-25 10:34:17 +01:00
if v := securityGroupResp.SecurityGroups; len(v) > 0 {
d.Set("default_security_group_id", v[0].GroupId)
}
return nil
}
func resourceAwsVpcSetDefaultRouteTable(conn *ec2.EC2, d *schema.ResourceData) error {
filter1 := &ec2.Filter{
Name: aws.String("association.main"),
Values: []*string{aws.String("true")},
}
filter2 := &ec2.Filter{
Name: aws.String("vpc-id"),
Values: []*string{aws.String(d.Id())},
}
findOpts := &ec2.DescribeRouteTablesInput{
Filters: []*ec2.Filter{filter1, filter2},
}
resp, err := conn.DescribeRouteTables(findOpts)
if err != nil {
return err
}
if len(resp.RouteTables) < 1 || resp.RouteTables[0] == nil {
return fmt.Errorf("Default Route table not found")
}
// There Can Be Only 1 ... Default Route Table
d.Set("default_route_table_id", resp.RouteTables[0].RouteTableId)
return nil
}