This example demonstrates how to use the CircleCI Machine Runner Terraform module to deploy a basic autoscaling group of self-hosted Linux runners in AWS.
- AWS account with appropriate permissions
- Terraform >= 1.5.0 installed
- CircleCI runner token stored in AWS Secrets Manager in your target region
- Existing VPC with subnet and security group in your target region
- EC2 keypair created in your target region
Important: All resources (Secrets Manager secret, VPC, subnet, security group, keypair) must exist in the same AWS region that you configure in the provider block.
-
Copy the
terraform.tfvars.examplefile toterraform.tfvars:cp terraform.tfvars.example terraform.tfvars
-
Edit
terraform.tfvarsand update the required values:subnet_id: Your VPC subnet IDsecurity_group_id: Your security group IDkeypair: Your EC2 keypair namerunner_token_secret_name: Name of your AWS Secrets Manager secret containing the CircleCI runner token
-
Initialize Terraform:
terraform init
-
Review the plan:
terraform plan
-
Apply the configuration:
terraform apply
Your AWS Secrets Manager secret should contain a JSON object with the following structure:
{
"circleci_runner_token": "your-runner-token-from-circleci"
}To create the secret:
aws secretsmanager create-secret \
--name your-runner-token-secret \
--secret-string '{"circleci_runner_token":"your-token-here"}'You can customize the deployment by modifying variables in terraform.tfvars:
- Scaling: Adjust
asg_desired_capacityandasg_max_capacity - Instance Type: Change
instance_typefor different compute requirements - Storage: Modify
volume_sizeandvolume_type - AMI: Update
ami_idto use a different base image - Tags: Customize
default_tagsfor your organization's tagging strategy
After deployment, the following information will be available:
autoscaling_group_name: Name of the ASGautoscaling_group_arn: ARN of the ASGlaunch_template_id: ID of the launch templatelaunch_template_latest_version: Current version of the launch templatescaling_policy_name: Name of the predictive scaling policy
To destroy the resources:
terraform destroy