Cloud data centres, which are characteristic of dynamic workloads, if not optimized for energy consumption, may lead to increased heat dissipation and eventually impact the environment adversely. Consequently, optimizing the usage of energy has become a hard requirement in today's cloud data centres wherein the major part of energy consumption is mostly attributed to computing and cooling systems. Motivated by which this paper proposes an online algorithm for dynamic resource allocation, namely, temperature aware online dynamic resource allocation algorithm (TARA). TARA demonstrates a novel algorithm design to adapt dynamic resource allocation based on the temperature of a data centre using computational fluid dynamics (CFD). Also, TARA demonstrates a new dynamic resource reclaim strategy for making efficient resource allocations leading to efficient energy consumptions in dynamic environments. The proposed algorithm provides optimal resource allocation considering energy efficiency without being overwhelmed by online dynamic workloads. The optimal energy-efficient dynamic resource allocation for online workloads eventually optimizes the computing and cooling energy consumption. We show through theoretical analysis the correctness, efficiency and optimality bounds given as $TARA(P) \leq 2OPT(P)$, relative to the optimal solution provided by offline dynamic resource allocation algorithm $(OPT(P))$. We show through empirical analysis that the proposed method is efficient and significantly saves energy by 26\% when the data centre utilization is 100\% compared to batched reclaim. The performance analysis shows significant improvement in optimizing computing and cooling efficiency. TARA can be used in multiple areas of on-demand dynamic resource allocation in cloud computing like resource allocation for virtual machine creation, resource allocation for virtual machine migrations, and virtual resources assignment for elastic cloud applications.