Terraform AWS
You can deploy CubeAPM on AWS (EC2 Server) using our Terraform code.
Prerequisites
Before getting started, ensure you have the following configuration ready:
- Terraform installed (v1.0.0 or higher).
- AWS Credentials configured locally (e.g., via
aws configure). - An existing AWS VPC and Subnet where CubeAPM will be deployed.
- An SSH Key Pair created in your AWS account to access the CubeAPM server.
Installation
-
Clone the
CubeAPM-Terraform-AWSrepository:git clone https://github.com/cubeapm/CubeAPM-Terraform-AWS.git -
Initialize Terraform:
cd CubeAPM-Terraform-AWS
terraform init -
Deploy CubeAPM:
While applying terraform it asks for following values, provide as per your requirement:
Variable Type Default Description aws_profilestringThe AWS profile to use for authentication (example: ~/.aws/credentials).aws_regionstring"ap-south-1"The AWS region to deploy the resources to. aws_ec2_amistring"ami-0f10ad22bd55251b2"The AWS AMI to use for the EC2 instance. aws_ec2_instance_typestring"m8g.xlarge"The AWS instance type to use for the EC2 instance. aws_vpc_idstringThe ID of the VPC where the resources will be deployed. aws_subnet_idstringThe ID of the subnet where the CubeAPM instance will run. aws_key_namestringThe name of the SSH key pair to access the CubeAPM server. aws_vpc_cidrstringThe CIDR block for the VPC. create_albbooleantrueSet to trueto create a new Application Load Balancer. Iffalse, an existing ALB listener will be used.lb_subnet_idslist(string)[]List of Public/Private subnet IDs for the ALB. Required if create_albistrue.load_balancer_internalbooleanfalseSet to trueto create an internal ALB, orfalsefor an internet-facing ALB.certificate_arnstring""The ARN of the ACM certificate to use for the ALB. Required if create_albistrue.existing_alb_listener_arnstring""The ARN of the existing ALB listener to attach to. Required if create_albisfalse.cubeapm_host_headerlist(string)[]The host header(s) to use for routing traffic from an existing ALB (e.g., ["cubeapm.example.com"]).alb_listener_rule_prioritynumber100The priority of the listener rule when using an existing ALB. existing_alb_security_group_idstring""The security group ID of the existing ALB. If empty and create_albisfalse, defaults to allowing the VPC CIDR.warningTo avoid being prompted for these variables every time you run Terraform, create a
terraform.tfvarsfile in the same directory: -
Here's a sample
terraform.tfvarsfile you can take a reference from here and update your terraform.tfvars file based on your infrastructure requirements:- Creating new LB
- Using existing LB
Example 1: Creating a New ALB
aws_profile = "my-aws-profile"
aws_region = "ap-south-1" # Optional: defaults to ap-south-1
aws_ec2_ami = "ami-0f10ad22bd55251b2" # Optional: defaults to Ubuntu 24.04 arm64
aws_ec2_instance_type = "m8g.xlarge" # Optional: defaults to m8g.xlarge
aws_vpc_id = "vpc-0123456789abcdef0"
aws_subnet_id = "subnet-0123456789abcdef0"
aws_key_name = "my-ssh-key-pair"
aws_vpc_cidr = "10.0.0.0/16" # Required: The CIDR block for the VPC
# Specific to creating the ALB:
create_alb = true
lb_subnet_ids = ["subnet-0123456789abcdef0", "subnet-0987654321fedcba0"]
load_balancer_internal = false
certificate_arn = "arn:aws:acm:ap-south-1:123456789012:certificate/abcdef01-2345-6789-abcd-ef0123456789"Example 2: Using an Existing ALB
aws_profile = "my-aws-profile"
aws_region = "ap-south-1" # Optional: defaults to ap-south-1
aws_ec2_ami = "ami-0f10ad22bd55251b2" # Optional: defaults to Ubuntu 24.04 arm64
aws_ec2_instance_type = "m8g.xlarge" # Optional: defaults to m8g.xlarge
aws_vpc_id = "vpc-0123456789abcdef0"
aws_subnet_id = "subnet-0123456789abcdef0"
aws_key_name = "my-ssh-key-pair"
aws_vpc_cidr = "10.0.0.0/16" # Required: The CIDR block for the VPC
# Specific to using an existing ALB:
create_alb = false
existing_alb_listener_arn = "arn:aws:elasticloadbalancing:ap-south-1:123456789012:listener/app/my-alb/abcdef0123456789/0987654321fedcba"
cubeapm_host_header = ["cubeapm.mydomain.com"]
alb_listener_rule_priority = 50
existing_alb_security_group_id = "sg-0123456789abcdef0" -
Once your variables are configured, run the following command to provision the infrastructure:
# use this syntax if you have created `terraform.tfvars` file.
terraform apply
# use this syntax if you don't want to create the `terraform.tfvars` file.
terraform apply -var="variable_name=variable_value" ...
Knowledge Base
For more information about Terraform for AWS, please refer to the Terraform AWS documentation.