func resource_aws_internet_gateway_attach(
	ec2conn *ec2.EC2,
	s *terraform.ResourceState,
	vpcId string) error {
	log.Printf(
		"[INFO] Attaching Internet Gateway '%s' to VPC '%s'",
		s.ID,
		vpcId)
	_, err := ec2conn.AttachInternetGateway(s.ID, vpcId)
	if err != nil {
		return err
	}

	// Wait for it to be fully attached before continuing
	log.Printf("[DEBUG] Waiting for internet gateway (%s) to attach", s.ID)
	stateConf := &resource.StateChangeConf{
		Pending: []string{"detached", "attaching"},
		Target:  "available",
		Refresh: IGAttachStateRefreshFunc(ec2conn, s.ID, "available"),
		Timeout: 1 * time.Minute,
	}
	if _, err := stateConf.WaitForState(); err != nil {
		return fmt.Errorf(
			"Error waiting for internet gateway (%s) to attach: %s",
			s.ID, err)
	}

	return nil
}