Install on AWS
Before proceeding with Cloud to Code CLI, you’ll need to meet the requirements listed below.
Windows OS
Click to view
If you want to use the cli using an executable file follow this guide.
-
Install Docker Desktop and Docker CLI on your Windows system.
Recommended system requirements: 4 vCPU and 8 GB RAM. -
Pull the container image from the public repository using the command:
docker pull ghcr.io/stackgenhq/cloud2code
-
Now run the container using the following command:
docker run --platform linux/arm64 --rm `
-e AWS_ACCESS_KEY_ID="***************" ` // access key id
-e AWS_SECRET_ACCESS_KEY="***************" ` // secret access key
-e AWS_SESSION_TOKEN="***************" ` // enter an aws session token
-v C:\Users\abc\output:/output `
ghcr.io/stackgenhq/cloud2code import aws --region us-east-1 --include aws_s3_bucket --output-dir /output
Usage
Option | Description |
---|---|
--platform | Ensures that the ghcr.io/stackgenhq/cloud2code container runs using the ARM64 architecture, regardless of your host machine's architecture. |
-e | Sets the environment variables. |
-v | Used for volume mounting. C:\Users\username\output is the directory path on your local Windows machine, while /output is the directory path inside the Docker container. |
Once you install the Docker CLI ensure that you install the rest of the dependencies mentioned in the document.
Install Terraform
Check if you’ve installed Terraform by running the following command:
- macOS
- Windows OS
terraform version
terraform version
To install Terraform, run the following command:
- macOS
- Windows OS
Run the following command to install Terraform using Homebrew:
brew install terraform
If you do not have Homebrew installed, run the following command:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
-
Using Chocolatey (Recommended for Windows):
If you have Chocolatey installed, run:
choco install terraform
If you don’t have Chocolatey, install it from chocolatey.org.
-
Using Scoop (Another Windows Package Manager): If you use Scoop, install Terraform with:
scoop install terraform
You'll need to install Scoop from scoop.sh.
Authenticate Your AWS CLI
Run the following command to authenticate your AWS CLI:
aws configure
Enter your Access Key, Secret Key, Region, and Output Format.
- Follow the on-screen instructions to finish authenticating. Refer to the AWS documentation to learn more about CLI authentication.
- If you do not have AWS CLI installed, refer to the AWS documentation.
Read Access to Regions
Ensure you have the necessary permissions to access your cloud regions and resources. If unsure, check with your cloud administrator or run the following command to verify your account details:
aws iam get-user
Install Cloud to Code CLI
To install the latest version of the Cloud to Code CLI tool using Homebrew, run the following:
brew install stackgenhq/homebrew-stackgen/cloud2code
Cloud to Code CLI lets you download a tfstate from the cloud. However, to provision the same using StackGen CLI, you would need to install it separately. To do so, run the following command if you haven’t done so already:
brew install stackgenhq/stackgen/stackgen
Upgrade Cloud to Code CLI
To check the version of your Cloud to Code CLI installed, run the command:
cloud2code version
To upgrade to the latest version of the Cloud to Code CLI tool, run the following:
brew upgrade stackgenhq/homebrew-stackgen/cloud2code
Create a Terraform State File
Follow these steps to create and import a tfstate
file:
- Use the command line to create a local Terraform folder and switch your directory to the local folder.
- Run the following command to create a terraform state file for S3 buckets and EC2 instances from a specified region. You will find your tfstate file in the directory specified in Step 1.
Usage
cloud2code import aws --region <region> --include <resource_types> --output-dir
Flag | Description | Required |
---|---|---|
--region | The AWS region from which resources will be imported. | Yes |
--include | Comma-separated list of specific AWS resource types to import. | Yes |
--output-dir | Output Terraform state file path. | Yes |
Example:
cloud2code import aws --region us-east-1 --include aws_s3_bucket,aws_instance --output-dir “/Users/abc/Downloads/terraform”
The command above imports S3 buckets and EC2 instances from the us-east-1 region
into Terraform configuration files (.tf
).