Use .profile to create a persistent state in cloud shell

Cloud Shell can make your life simple. However, state is lost between cloud shell start ups and shut downs. This post walks through an actual example of how to persist state across cloud shell restarts.

  1. Create an ENV variable (my_project_id) and save it
mkdir myconfig

touch infraclass/config

MY_PROJECT_ID=[YOUR_PROJECT_ID]

echo MY_PROJECT_ID=$MY_PROJECT_ID >> ~/myconfig/config

2.. Add the above to the .profile file to store it across VM sessions

nano .profile

source myconfig/config (followed by Ctrl+O, ENTER to save the file, and then press Ctrl+X to exit)

3. Test it out. Close the shell session and start a new one.

echo $MY_PROJECT_ID



Need an experienced AWS/GCP/Azure/DevSecOps Professional to help out with your Public Cloud Strategy? Set up a time with Anuj Varma.

anuj

I am passionate about getting cloud solutions right the first time. I help customers transition to the public cloud with the appropriate security controls and guardrails. GCP, AWS and Azure Security Specialist. <a href="https://calendly.com/anujvarma/google-cloud-architect-initial-consultation">Initial Consultation</a>

Leave a reply

Your email address will not be published. Required fields are marked *