This Terraform project simplifies the deployment of Rancher on AWS. With just a few commands, you get a fully configured EC2 instance, VPC, security groups, and optional RKE2 and Cert-Manager installation. The setup is highly flexible, allowing you to deploy in any VPC and manage multiple environments effortlessly.
- 🔹 One-click Rancher Deployment – Automatically sets up Rancher on an EC2 instance.
- 🔹 AWS Infrastructure as Code – Creates a VPC, security groups, and inbound rules.
- 🔹 Customizable Installation – Toggle RKE2 and Cert-Manager installation.
- 🔹 Multi-Workspace Support – Deploy to different environments easily.
- 🔹 Version Control – Use the
prefixvariable to separate multiple environments. - 🔹 IP Retention for Seamless Migration – Preserve critical IP configurations for reusability.
Before you start, ensure you have:
- Terraform installed
- AWS credentials set up (Access Key & Secret Key)
- A valid SSH key pair for accessing the instance
Customize your infrastructure by editing terraform.tfvars:
prefix = "your-environment"
aws_region_instance = "us-west-2"
aws_region_s3 = "us-west-2"
vpc_cidr = "10.2.0.0/16"
subnet_cidr = "10.2.0.0/24"
aws_zone = "us-west-2b"
ami_id = "ami-87654321"
instance_type = "t3.medium"
key_name = "your-key"
root_volume_size = 50
encryption_secret_key = ""Get your Rancher setup running in minutes:
- Initialize Terraform
terraform init
- Validate the configuration
terraform validate
- Preview changes
terraform plan -var-file=terraform.tfvars
- Deploy Rancher
terraform apply -var-file=terraform.tfvars -auto-approve
To ensure your Rancher instance retains the same IP after redeployment, use the preserved instance configuration:
cp instance_preserve.tf.bk instance.tfThis ensures Rancher keeps the same IP address, making migration and reconfiguration seamless.
To tear down the infrastructure, simply run:
terraform destroy -var-file=terraform.tfvars -auto-approve- The
prefixvariable ensures you can manage multiple deployments easily. - Terraform workspaces allow seamless multi-environment support.
- The
.bkfiles help retain important configurations like static IPs for redeployment.
To create and switch between Terraform workspaces, use:
terraform workspace new dev
terraform workspace select devThen apply changes within the selected workspace:
terraform apply -var-file=terraform.tfvars -auto-approveThis project is licensed under the MIT License.
💡 Pro Tip: Use Terraform workspaces to manage different environments efficiently!