The recommended way is by using the regularizer argument .You can either set it in your variable_scope or in the get_variable to make all your variables regularized.You can follow this steps:
1.Defining a regularizer
regularizer = tf.contrib.layers.l2_regularizer(scale=0.1)
2.Creating variables
var = tf.get_variable(
name=”var",
regularizer=regularizer,
)
3.Defining some loss terms and then adding the regularizer term:
regvar = tf.get_collection(tf.GraphKeys.REGULARIZATION_LOSSES)
regterm=tf.contrib.layers.apply_regularization(regularizer, regvar)
loss = loss+ regterm
Hope this answer helps.