code: func (m *Map) Apply(
  	info *terraform.InstanceInfo,
  	s *terraform.InstanceState,
  	d *terraform.InstanceDiff,
  	meta interface{}) (*terraform.InstanceState, error) {
  	r, ok := m.Mapping[info.Type]
  	if !ok {
  		return nil, fmt.Errorf("Unknown resource type: %s", info.Type)
  	}
  
  	if d.Destroy || d.RequiresNew() {
  		if s.ID != "" {
  			// Destroy the resource if it is created
  			err := r.Destroy(s, meta)
  			if err != nil {
  				return s, err
  			}
  
  			s.ID = ""
  		}
  
  		// If we're only destroying, and not creating, then return now.
  		// Otherwise, we continue so that we can create a new resource.
  		if !d.RequiresNew() {
  			return nil, nil
  		}
  	}
  
  	var result *terraform.InstanceState
  	var err error
  	if s.ID == "" {
  		result, err = r.Create(s, d, meta)
  	} else {
  		if r.Update == nil {
  			return s, fmt.Errorf(
  				"Resource type '%s' doesn't support update",
  				info.Type)
  		}
  
  		result, err = r.Update(s, d, meta)
  	}
  	if result != nil {
  		if result.Attributes == nil {
  			result.Attributes = make(map[string]string)
  		}
  
  		result.Attributes["id"] = result.ID
  	}
  
  	return result, err
  }
docs: // Apply performs a create or update depending on the diff, and calls
  // the proper function on the matching Resource.