github.com/bradfeehan/terraform@v0.7.0-rc3.0.20170529055808-34b45c5ad841/builtin/providers/aws/resource_aws_default_vpc.go (about)

     1  package aws
     2  
     3  import (
     4  	"log"
     5  
     6  	"github.com/aws/aws-sdk-go/aws"
     7  	"github.com/aws/aws-sdk-go/service/ec2"
     8  	"github.com/hashicorp/terraform/helper/schema"
     9  )
    10  
    11  func resourceAwsDefaultVpc() *schema.Resource {
    12  	// reuse aws_vpc schema, and methods for READ, UPDATE
    13  	dvpc := resourceAwsVpc()
    14  	dvpc.Create = resourceAwsDefaultVpcCreate
    15  	dvpc.Delete = resourceAwsDefaultVpcDelete
    16  
    17  	// cidr_block is a computed value for Default VPCs
    18  	dvpc.Schema["cidr_block"] = &schema.Schema{
    19  		Type:     schema.TypeString,
    20  		Computed: true,
    21  	}
    22  	// instance_tenancy is a computed value for Default VPCs
    23  	dvpc.Schema["instance_tenancy"] = &schema.Schema{
    24  		Type:     schema.TypeString,
    25  		Computed: true,
    26  	}
    27  	// assign_generated_ipv6_cidr_block is a computed value for Default VPCs
    28  	dvpc.Schema["assign_generated_ipv6_cidr_block"] = &schema.Schema{
    29  		Type:     schema.TypeBool,
    30  		Computed: true,
    31  	}
    32  
    33  	return dvpc
    34  }
    35  
    36  func resourceAwsDefaultVpcCreate(d *schema.ResourceData, meta interface{}) error {
    37  	conn := meta.(*AWSClient).ec2conn
    38  	req := &ec2.DescribeVpcsInput{
    39  		Filters: []*ec2.Filter{
    40  			&ec2.Filter{
    41  				Name:   aws.String("isDefault"),
    42  				Values: aws.StringSlice([]string{"true"}),
    43  			},
    44  		},
    45  	}
    46  
    47  	resp, err := conn.DescribeVpcs(req)
    48  	if err != nil {
    49  		return err
    50  	}
    51  
    52  	d.SetId(aws.StringValue(resp.Vpcs[0].VpcId))
    53  
    54  	return resourceAwsVpcUpdate(d, meta)
    55  }
    56  
    57  func resourceAwsDefaultVpcDelete(d *schema.ResourceData, meta interface{}) error {
    58  	log.Printf("[WARN] Cannot destroy Default VPC. Terraform will remove this resource from the state file, however resources may remain.")
    59  	d.SetId("")
    60  	return nil
    61  }