diff --git a/dockers/docker-dhcp-relay/docker-dhcp-relay.supervisord.conf.j2 b/dockers/docker-dhcp-relay/docker-dhcp-relay.supervisord.conf.j2
index 799cddd5db3e..19a6cc294f7f 100644
--- a/dockers/docker-dhcp-relay/docker-dhcp-relay.supervisord.conf.j2
+++ b/dockers/docker-dhcp-relay/docker-dhcp-relay.supervisord.conf.j2
@@ -39,11 +39,11 @@ dependent_startup=true
dependent_startup_wait_for=rsyslogd:running
{# If our configuration has VLANs... #}
-{% if VLAN %}
+{% if VLAN_INTERFACE %}
{# Count how many VLANs require a DHCP relay agent... #}
{% set num_relays = { 'count': 0 } %}
-{% for vlan_name in VLAN %}
-{% if VLAN[vlan_name]['dhcp_servers'] and vlan_name in VLAN_INTERFACE %}
+{% for vlan_name in VLAN_INTERFACE %}
+{% if VLAN and vlan_name in VLAN and VLAN[vlan_name]['dhcp_servers'] %}
{% set _dummy = num_relays.update({'count': num_relays.count + 1}) %}
{% endif %}
{% endfor %}
@@ -52,8 +52,8 @@ dependent_startup_wait_for=rsyslogd:running
[group:isc-dhcp-relay]
programs=
{%- set add_preceding_comma = { 'flag': False } %}
-{% for vlan_name in VLAN %}
-{% if VLAN[vlan_name]['dhcp_servers'] and vlan_name in VLAN_INTERFACE %}
+{% for vlan_name in VLAN_INTERFACE %}
+{% if VLAN and vlan_name in VLAN and VLAN[vlan_name]['dhcp_servers'] %}
{% if add_preceding_comma.flag %},{% endif %}
{% set _dummy = add_preceding_comma.update({'flag': True}) %}
isc-dhcp-relay-{{ vlan_name }}
@@ -63,8 +63,8 @@ isc-dhcp-relay-{{ vlan_name }}
{# Create a program entry for each DHCP relay agent instance #}
{% set relay_for_ipv4 = { 'flag': False } %}
-{% for vlan_name in VLAN %}
-{% if VLAN[vlan_name]['dhcp_servers'] and vlan_name in VLAN_INTERFACE %}
+{% for vlan_name in VLAN_INTERFACE %}
+{% if VLAN and vlan_name in VLAN and VLAN[vlan_name]['dhcp_servers'] %}
{% for dhcp_server in VLAN[vlan_name]['dhcp_servers'] %}
{% if dhcp_server | ipv4 %}
{% set _dummy = relay_for_ipv4.update({'flag': True}) %}
@@ -106,8 +106,8 @@ dependent_startup_wait_for=start:exited
[group:dhcpmon]
programs=
{%- set add_preceding_comma = { 'flag': False } %}
-{% for vlan_name in VLAN %}
-{% if VLAN[vlan_name]['dhcp_servers'] and vlan_name in VLAN_INTERFACE %}
+{% for vlan_name in VLAN_INTERFACE %}
+{% if VLAN and vlan_name in VLAN and VLAN[vlan_name]['dhcp_servers'] %}
{% if add_preceding_comma.flag %},{% endif %}
{% set _dummy = add_preceding_comma.update({'flag': True}) %}
dhcpmon-{{ vlan_name }}
@@ -117,8 +117,8 @@ dhcpmon-{{ vlan_name }}
{# Create a program entry for each DHCP MONitor instance #}
{% set relay_for_ipv4 = { 'flag': False } %}
-{% for vlan_name in VLAN %}
-{% if VLAN[vlan_name]['dhcp_servers'] and vlan_name in VLAN_INTERFACE %}
+{% for vlan_name in VLAN_INTERFACE %}
+{% if VLAN and vlan_name in VLAN and VLAN[vlan_name]['dhcp_servers'] %}
{% for dhcp_server in VLAN[vlan_name]['dhcp_servers'] %}
{% if dhcp_server | ipv4 %}
{% set _dummy = relay_for_ipv4.update({'flag': True}) %}
diff --git a/src/sonic-config-engine/tests/t0-sample-graph.xml b/src/sonic-config-engine/tests/t0-sample-graph.xml
index 237a2ff0f532..63f892fe6d04 100644
--- a/src/sonic-config-engine/tests/t0-sample-graph.xml
+++ b/src/sonic-config-engine/tests/t0-sample-graph.xml
@@ -237,11 +237,28 @@
fortyGigE0/4;fortyGigE0/8;fortyGigE0/12;fortyGigE0/16;fortyGigE0/20;fortyGigE0/24;fortyGigE0/28;fortyGigE0/32;fortyGigE0/36;fortyGigE0/40;fortyGigE0/44;fortyGigE0/48;fortyGigE0/52;fortyGigE0/56;fortyGigE0/60;fortyGigE0/64;fortyGigE0/68;fortyGigE0/72;fortyGigE0/76;fortyGigE0/80;fortyGigE0/84;fortyGigE0/88;fortyGigE0/92;fortyGigE0/96
False
0.0.0.0/0
+
192.0.0.1;192.0.0.2
1000
1000
192.168.0.0/27
+
+
+
+
+ Vlan99
+ fortyGigE0/100
+ False
+ 0.0.0.0/0
+
+ UserDefinedL2Vlan
+ 192.0.0.1;192.0.0.2
+ 99
+ 99
+
+
+