DevOps: Jenkins & AWS Series, Part 2- Setup AWS CloudShell & Install Terraform in Persistent Storage
Technology behind CloudShell.
AWS CloudShell provides a persistent storage space in the user’s home directory that can be used to store data across sessions. This storage space is provisioned using Amazon Elastic File System (EFS), which provides scalable and highly available file storage for use with AWS CloudShell.
The home directory for AWS CloudShell is located at /home/cloudshell-user
. This directory is automatically mounted to an EFS file system when the user logs in to the CloudShell, and the data stored in this directory is persisted across sessions. This means that any files or configurations that you store in this directory will be available to you the next time you log in to the CloudShell.
AWS CloudShell provides 1 GB of persistent storage by default, and you can request additional storage by contacting AWS Support. The storage space is encrypted using AWS Key Management Service (KMS) and is backed up regularly to ensure data durability and availability.
One of the benefits of using AWS CloudShell’s persistent storage is that you can store your scripts, configurations, and other important files in a centralized location that is accessible from anywhere with an internet connection. This allows you to easily access and manage your files without having to worry about local storage limitations or data loss.
Difference between Persistence & Non Persistence storage.
In summary, AWS CloudShell offers both persistent and non-persistent storage options.
Non Persistent Data
The packages that you install in the AWS CloudShell using package managers like yum
or apt-get
are not persistent across sessions.
The AWS CloudShell provides a temporary Linux compute environment that is pre-configured with various command-line tools and AWS SDKs. When you launch a new session of AWS CloudShell, the environment is provisioned on-demand using an Amazon EC2 instance.
The underlying EC2 instance that powers the AWS CloudShell is terminated when you close the session or after a period of inactivity. Any packages that you installed using package managers during your session are not saved, and the next time you launch the Cloud Shell, you will need to install them again.
To mitigate this, you can create a script that automates the installation of your required packages, or you can create your own Docker image with all the necessary packages installed and use that image in the CloudShell. Alternatively, you can use AWS CloudFormation or AWS Elastic Beanstalk to create and deploy custom environments with persistent resources like EC2 instances and EBS volumes.
Terraform INstallation as a Persistent or Non Volatile data:
To install Terraform on AWS CloudShell and then make use of the persistent home directory to store your Terraform configurations and other files.
Set of commands installs tfenv, a Terraform version manager, and sets the default Terraform version to 1.4.4. in home directory.
Once Terraform is installed, you can create and modify Terraform configurations in your home directory. Any files that you create or modify in your home directory are automatically persisted across sessions, so you can easily resume your work on Terraform the next time you log in to AWS CloudShell.
For example, you can create a new Terraform project in your home directory by running terraform init
and terraform create
commands. The Terraform configuration files and other related files will be automatically stored in your home directory, and you can modify them as needed.
Installation Process:
Before we start, make sure that you have an AWS account and you have launched the CloudShell environment. You can launch the CloudShell from the AWS Management Console by clicking on the CloudShell icon in the top right corner of the screen.
Step-by-step instructions to install Terraform on AWS CloudShell using tfenv:
Step 1: Clone the tfenv repository to your home directory using the following command:
git clone https://github.com/tfutils/tfenv.git ~/.tfenv
This command will clone the tfenv repository to the ~/.tfenv directory in your home directory.
Step 2: Create a new bin directory in your home directory using the following command:
mkdir ~/bin
Step 3: Create a symlink from the ~/.tfenv/bin directory to the ~/bin directory using the following command:
ln -s ~/.tfenv/bin/* ~/bin/
Step 4: Install a specific version of Terraform using the following command:
tfenv install
Step 5: Set the installed Terraform version as the default version using the following command:
tfenv use 1.4.4
Step 6: Confirm that Terraform is installed by running the following command:
terraform — version
This command will display the version of Terraform that you have installed on your AWS CloudShell.
All in one command
git clone https://github.com/tfutils/tfenv.git ~/.tfenv
mkdir ~/bin
ln -s ~/.tfenv/bin/* ~/bin/
tfenv install
tfenv use 1.4.4
terraform --version
In summary, these steps install tfenv and Terraform on AWS CloudShell, and set the installed Terraform version as the default version to use. By installing Terraform with tfenv, you can easily switch between different versions of Terraform, as well as manage the installation of plugins and other dependencies.
For more info please connect & Follow me:
Github: https://github.com/manikcloud
LinkedIn: https://www.linkedin.com/in/vkmanik/
Email: varunmanik1@gmail.com
Facebook: https://www.facebook.com/cloudvirtualization/
YouTube: https://bit.ly/32fknRN
Twitter: https://twitter.com/varunkmanik