You can achieve that by using the procedure below:
Define an auxiliary binary variable Y which only takes values 0 and 1.
Add an equality constraint in the form of X = 2Y - 1
This will ensure that
X is equal to 1 when Y is 1 andX is equal to -1 when Y is 0.