You do not need any extra code if all you want to do is have a LED go on when the switch is closed and off when it is open.
When the toggle is to the left, the LED is grounded which turns is ON and D2 reads LOW.
When the toggle is to the right, the D2 is pulled HIGH since you configured the pin as INPUT_PULLUP and the LED is OFF.
