func resource_aws_vpc_update( s *terraform.ResourceState, d *terraform.ResourceDiff, meta interface{}) (*terraform.ResourceState, error) { p := meta.(*ResourceProvider) ec2conn := p.ec2conn rs := s.MergeDiff(d) log.Printf("[DEBUG] attributes: %#v", d.Attributes) if attr, ok := d.Attributes["enable_dns_support"]; ok { options := new(ec2.ModifyVpcAttribute) options.EnableDnsSupport = attr.New != "" && attr.New != "false" options.SetEnableDnsSupport = true rs.Attributes["enable_dns_support"] = strconv.FormatBool(options.EnableDnsSupport) log.Printf("[INFO] Modifying enable_dns_support vpc attribute for %s: %#v", s.ID, options) if _, err := ec2conn.ModifyVpcAttribute(s.ID, options); err != nil { return s, err } } if attr, ok := d.Attributes["enable_dns_hostnames"]; ok { options := new(ec2.ModifyVpcAttribute) options.EnableDnsHostnames = attr.New != "" && attr.New != "false" options.SetEnableDnsHostnames = true rs.Attributes["enable_dns_hostnames"] = strconv.FormatBool(options.EnableDnsHostnames) log.Printf("[INFO] Modifying enable_dns_hostnames vpc attribute for %s: %#v", s.ID, options) if _, err := ec2conn.ModifyVpcAttribute(s.ID, options); err != nil { return s, err } } return rs, nil }
func resource_aws_vpc_create( s *terraform.ResourceState, d *terraform.ResourceDiff, meta interface{}) (*terraform.ResourceState, error) { p := meta.(*ResourceProvider) ec2conn := p.ec2conn // Merge the diff so that we have all the proper attributes s = s.MergeDiff(d) // Create the VPC createOpts := &ec2.CreateVpc{ CidrBlock: s.Attributes["cidr_block"], } log.Printf("[DEBUG] VPC create config: %#v", createOpts) vpcResp, err := ec2conn.CreateVpc(createOpts) if err != nil { return nil, fmt.Errorf("Error creating VPC: %s", err) } // Get the ID and store it vpc := &vpcResp.VPC log.Printf("[INFO] VPC ID: %s", vpc.VpcId) s.ID = vpc.VpcId // Wait for the VPC to become available log.Printf( "[DEBUG] Waiting for VPC (%s) to become available", s.ID) stateConf := &resource.StateChangeConf{ Pending: []string{"pending"}, Target: "available", Refresh: VPCStateRefreshFunc(ec2conn, s.ID), Timeout: 10 * time.Minute, } vpcRaw, err := stateConf.WaitForState() if err != nil { return s, fmt.Errorf( "Error waiting for VPC (%s) to become available: %s", s.ID, err) } if attr, ok := d.Attributes["enable_dns_support"]; ok { options := new(ec2.ModifyVpcAttribute) options.EnableDnsSupport = attr.New != "" && attr.New != "false" options.SetEnableDnsSupport = true s.Attributes["enable_dns_support"] = strconv.FormatBool(options.EnableDnsSupport) log.Printf("[INFO] Modifying vpc attributes for %s: %#v", s.ID, options) if _, err := ec2conn.ModifyVpcAttribute(s.ID, options); err != nil { return s, err } } if attr, ok := d.Attributes["enable_dns_hostnames"]; ok { options := new(ec2.ModifyVpcAttribute) options.EnableDnsHostnames = attr.New != "" && attr.New != "false" options.SetEnableDnsHostnames = true s.Attributes["enable_dns_hostnames"] = strconv.FormatBool(options.EnableDnsHostnames) log.Printf("[INFO] Modifying enable_dns_hostnames vpc attribute for %s: %#v", s.ID, options) if _, err := ec2conn.ModifyVpcAttribute(s.ID, options); err != nil { return s, err } } // Update our attributes and return return resource_aws_vpc_update_state(s, vpcRaw.(*ec2.VPC)) }