How to create a vocabulary and populate it with terms using features I'd like to create a feature that creates a vocabulary and populates it with taxonomy terms.

Creating a vocabulary is easy with features and it can be done using UI (I only need to select the desired existing vocabulary and add it as dependency and a file features.taxonomy will be created)

However, there's no way to export terms to a feature, so I created a feature_name.install file and added the following function on it:

/**
 * Implements hook_install().
 */
function feature_name_install() {
  // Populates 'Vocabulary name' vocabulary with taxonomy terms.
  $vocabulary = taxonomy_vocabulary_machine_name_load('vocabulary_machine_name');
  $terms = array();

  $terms[] = t('Term 1');
  $terms[] = t('Term 2');
  $terms[] = t('Term 3');

  foreach($terms as $name) {
    $term = new stdClass();
    $term-&gt;vid = $vocabulary-&gt;vid;
    $term-&gt;name = $name;
    taxonomy_term_save($term);
  }
} 


The problem with this code is that when installing the feature it is loaded before creating the vocabulary so tries to add terms to a vocabulary that does not exist yet and produces an error.

I have tried using hook_post_features_enable_feature but I didn't succeeded (I may be using a wrong syntaxis, see code below).

/**
 * Implements hook_post_features_enable_feature($component).
 */
function feature_name_post_features_enable_feature($component) {
  $component = 'feature_name';
  // Populates 'Vocabulary name' vocabulary with taxonomy terms.
  $vocabulary = taxonomy_vocabulary_machine_name_load('vocabulary_machine_name');
  $terms = array();

  $terms[] = t('Term 1');
  $terms[] = t('Term 2');
  $terms[] = t('Term 3');

  foreach($terms as $name) {
    $term = new stdClass();
    $term-&gt;vid = $vocabulary-&gt;vid;
    $term-&gt;name = $name;
    taxonomy_term_save($term);
  }
} 


Can anyone tell me how to solve this?
The problem with exporting content like taxonomy terms is keeping the taxonomy id intact when migrating it from site to site which is exactly what the features extension module UUID Features solves by using the UUID api:


  The UUID Features Integration module provides a mechanism for
  exporting content (nodes, taxonomy, fields) into a features module.
  What's that you say? You thought features was only for configuration?
  This module is meant to be used in the cases where certain pieces of
  content straddle the line between pure content and configuration.