Microgrids are small power systems, often equipped with renewable energy sources, that are alternatives or supplementary to utility grids. Many studies have been conducted on the design and implementation of microgrids and their interconnects to utility grids, and investigations have been extended to the use of Internet of Things technology (IoT) to monitor and operate such power grids. However, the broad applications of the IoT technology itself also call for a green energy solution. This paper investigates how to power local IoT applications via an integration of a microgrid and the utility grid. Together, we call such a system an IoT microgrid. The goal of an IoT microgrid is to maintain the availability of IoT applications while saving energy costs, and this is achieved by sustaining IoT applications via local renewable energy from a microgrid and by mitigating the intermittent power supply using the utility grid. This paper characterizes the IoT microgrid and proposes a configurable cyber-physical testbed for its design and validation. The testbed incorporates the hardware-in-the-loop (HIL) approach, where real-time simulation is integrated with physical elements for quick prototyping of those components in an IoT microgrid. The paper concludes with an example implementation of the proposed testbed, which demonstrates its use for validating both an IoT microgrid and the IoT application it sustains.