diff --git a/lib/dib b/lib/dib
index 809217bc93..88d9fd8434 100644
--- a/lib/dib
+++ b/lib/dib
@@ -35,15 +35,6 @@ OCC_DIR=$DEST/os-collect-config
 ORC_DIR=$DEST/os-refresh-config
 OAC_DIR=$DEST/os-apply-config
 
-# Include the apt-sources element in builds if we have an
-# alternative sources.list specified.
-if [ -n "$DIB_APT_SOURCES" ]; then
-    if [ ! -e "$DIB_APT_SOURCES" ]; then
-        die $LINENO "DIB_APT_SOURCES set but not found at $DIB_APT_SOURCES"
-    fi
-    EXTRA_ELEMENTS="apt-sources"
-fi
-
 # Functions
 # ---------
 
@@ -106,6 +97,15 @@ function disk_image_create_upload {
 
     local image_path=$TOP_DIR/files/$image_name.qcow2
 
+    # Include the apt-sources element in builds if we have an
+    # alternative sources.list specified.
+    if [ -n "$DIB_APT_SOURCES" ]; then
+        if [ ! -e "$DIB_APT_SOURCES" ]; then
+            die $LINENO "DIB_APT_SOURCES set but not found at $DIB_APT_SOURCES"
+        fi
+        local extra_elements="apt-sources"
+    fi
+
     # Set the local pip repo as the primary index mirror so the
     # image is built with local packages
     local pypi_mirror_url=http://$SERVICE_HOST:$DIB_PIP_REPO_PORT/
@@ -127,7 +127,7 @@ function disk_image_create_upload {
     DIB_OFFLINE=$DIB_BUILD_OFFLINE \
     PYPI_MIRROR_URL=$pypi_mirror_url \
     PYPI_MIRROR_URL_1=$pypi_mirror_url_1 \
-    disk-image-create -a amd64 $image_elements $EXTRA_ELEMENTS \
+    disk-image-create -a amd64 $image_elements ${extra_elements:-} \
         --image-cache $DIB_IMAGE_CACHE \
         -o $image_path