Skip to content

Latest commit

 

History

History

linux

Requirements

Name Version
aws >= 5.47.0
circleci 1.0.1

Providers

Name Version
aws 5.47.0
circleci 1.0.1

Modules

No modules.

Resources

Name Type
aws_lightsail_instance.circleci_runner3_linux resource
aws_lightsail_key_pair.key_pair resource
circleci_runner_resource_class.machine_linux resource
circleci_runner_token.admin resource
aws_availability_zones.zones data source

Inputs

Name Description Type Default Required
aws_region AWS region string n/a yes
aws_tags AWS default tags for all resources map(string) {} no
circleci_hostname Set this to your CircleCI Server (>= 4.4.x) domain if for Server string "runner.circleci.com" no
cleanup_working_directory true if cleanup of working directory after each run is required. See https://circleci.com/docs/machine-runner-3-configuration-reference/#runner-cleanup-working-directory bool true no
command_prefix Command prefix used to invoke job. See https://circleci.com/docs/machine-runner-3-configuration-reference/#runner-command-prefix list(string)
[
""
]
no
lightsail_blueprint_id The ID for a virtual private server image. See https://awscli.amazonaws.com/v2/documentation/api/latest/reference/lightsail/get-blueprints.html string n/a yes
lightsail_bundle_id AWS Lightsail bundle ID. See https://awscli.amazonaws.com/v2/documentation/api/latest/reference/lightsail/get-bundles.html string n/a yes
lightsail_instance_name Name (identifier) for the AWS Lightsail instance string n/a yes
num_machines Fleet size (number of instances) number 1 no
public_ssh_key Public SSH key used for accessing your AWS Lightsail instance(s) string "" no
runner_resource_class CircleCI Runner resource-class name (e.g., acmeorg/machine-runner-aws-lightsail) string n/a yes
runner_resource_class_desc Description for CircleCI Runner resource-class string "" no
runner_token CircleCI Runner resource-class token, if already created string "" no
user_data Custom configuration (Bash) used as part of the user-data (provisioning script). Script will be run before starting the CircleCI runner agent. string "echo \"replace me\"\necho \"Check custom_config input for this module.\n\"" no
working_directory Working directory for job. See https://circleci.com/docs/machine-runner-3-configuration-reference/#runner-working-directory string "/tmp/circleci-runner" no

Outputs

Name Description
public_ips Public IP addresses of AWS Lightsail instance(s)
public_ssh_key Public key for SSH key set up on AWS Lightsail instance(s)
username Username of AWS Lightsail instance(s), used for SSH

Examples

Basic configuration

terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "5.57.0"
    }
  }
}

provider "aws" {
  # Configuration options
  # You can set the AWS_PROFILE env var to point to your SSO profile
}

provider "circleci" {
  # Configuration options
  # Uses the CIRCLE_TOKEN env var by default
}

module "machine3_runners" {
  source = "git::https://github.com/kelvintaywl-cci/run.git//machine/linux"

  aws_region = "ap-northeast-1"
  aws_tags = {
    iac : "true"
  }

  num_machines = 1

  lightsail_blueprint_id  = "ubuntu_22_04"
  lightsail_bundle_id     = "medium_3_0"
  lightsail_instance_name = "kelvintaywl-machine3-runner-medium"

  runner_resource_class      = "kelvintaywl-cci/lightsail-medium"
  runner_resource_class_desc = "AWS Lightsail (medium) Ubuntu 22.04"

  # NOTE: point this to your public SSH key on your local machine, for instance
  public_ssh_key = file(...)

  # NOTE: use file() to load your local Bash script
  user_data = file(...)
}

output "public_ips" {
  value = module.machine3_runners.public_ips
}

Using command prefix and custom userdata

terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "5.57.0"
    }
  }
}

provider "aws" {
  # Configuration options
  # You can set the AWS_PROFILE env var to point to your SSO profile
}

provider "circleci" {
  # Configuration options
  # Uses the CIRCLE_TOKEN env var by default
}

module "machine3_runners" {
  source = "git::https://github.com/kelvintaywl-cci/run.git//machine/linux"

  aws_region = "ap-northeast-1"
  aws_tags = {
    iac : "true"
  }

  num_machines = 1

  lightsail_blueprint_id  = "ubuntu_22_04"
  lightsail_bundle_id     = "medium_3_0"
  lightsail_instance_name = "kelvintaywl-machine3-runner-medium"

  runner_resource_class      = "kelvintaywl-cci/lightsail-medium"
  runner_resource_class_desc = "AWS Lightsail (medium) Ubuntu 22.04"
  public_ssh_key = file(...)

  user_data = <<EOT
# add circleci user to sudo group
usermod -aG sudo circleci

# Lightsail applies the /etc/sudoers.d/ directories' files
# So we add a new rule for our circleci user to not require password prompts during sudo
touch /etc/sudoers.d/99-circleci-runner
echo "circleci ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers.d/99-circleci-runner
  EOT
  # run job steps with elevated privileges
  command_prefix = ["sudo", "-niHu", "circleci", "--"]
}

output "public_ips" {
  value = module.machine3_runners.public_ips
}