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.
- 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.
Leave a Reply