This is my docker file
FROM python:3.7
# Install necessary packages
RUN apt-get update &&
apt-get install -y curl unzip &&
rm -rf /var/lib/apt/lists/*
# Download and install Terraform 1.8.1
RUN curl -LO https://releases.hashicorp.com/terraform/1.8.1/terraform_1.8.1_linux_amd64.zip &&
unzip terraform_1.8.1_linux_amd64.zip -d /usr/local/bin &&
rm terraform_1.8.1_linux_amd64.zip
# Download and install Terraformer
RUN curl -LO https://github.com/GoogleCloudPlatform/terraformer/releases/download/$(curl -s https://api.github.com/repos/GoogleCloudPlatform/terraformer/releases/latest | grep tag_name | cut -d '"' -f 4)/terraformer-linux-amd64 &&
chmod +x terraformer-linux-amd64 &&
mv terraformer-linux-amd64 /usr/local/bin/terraformer
# Set working directory
WORKDIR /app
# Add /usr/local/bin to PATH
ENV PATH="/usr/local/bin:${PATH}"
ADD https://github.com/ufoscout/docker-compose-wait/releases/download/2.2.1/wait /wait
RUN chmod +x /wait
ENV LOGLEVEL INFO
EXPOSE 5000
COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt
COPY src /app
CMD /wait && python ./app.py
This is the code where I am trying to run the terraform command using python
def initialize_terraform():
logging.info("Initializing terraform")
subprocess.run(['terraform', 'init'], shell=True, check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
logging.info("completed the terraform initialization")
When I run the docker file, my expectation is, it should run the terraform command and return the exit status code 0
I cross verified by checking terraform –version inside the container and it is working and installed properly. The terraform is installed in this particular path inside container /usr/local/bin/terraform
But the terraform init command that I have mentioned above returns the code 127, which means that the executable terraform file is not accessible for it in the container, I tried some ways like setting it as PATH like this ENV PATH=”/usr/local/bin:${PATH}”
But I still get the same 127 return code
Any help is greatly appreciated
Thank you in advance
Kavya is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.