Automating miniconda installation along with dependencies for a Python app

Hi,

I am doing a Terraform automation and in the VM provisioning, I am running all of the necessary installations, but I am stuck at miniconda part.

Manually, my steps are as follow:

  1. sudo apt install -y python3-pip && mkdir -p ~/miniconda3
  2. wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda3/miniconda.sh && bash ~/miniconda3/miniconda.sh -b -u -p ~/miniconda3 && ~/miniconda3/bin/conda init bash
  3. conda create -y -n myenv python=3.10
  4. conda activate myenv
  5. pip install -r ~/myapp/requirements.txt

If I do all 5 steps above manually, I can get things up just fine.

Automation in Terraform, however, after step 2, this is where it gets tricky - it requires logout and re-login and I don’t think it is possible in Terraform to logout and re-login in this case.

So with this, for step 3, 4 and 5, which are associated with myenv environment, is it possible to execute them in a way that we do not need to logout and re-login in this case? Is there a way to do this?

Source ~/miniconda3/etc/profile.d/conda.sh