- Newest
- Most votes
- Most comments
Hello.
The following documentation provides an example of a GitHub Actions self-hosted runner:
I think it's possible to configure it using "aws_codebuild_webhook".
https://docs.aws.amazon.com/codebuild/latest/userguide/action-runner.html#sample-github-action-runners-webhooks-terraform
https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/codebuild_webhook
resource "aws_codebuild_webhook" "example" {
project_name = aws_codebuild_project.example.name
build_type = "BUILD"
filter_group {
filter {
type = "EVENT"
pattern = "WORKFLOW_JOB_QUEUED"
}
}
}
The AI response from re:Post Agent suggests setting it up with "aws_codebuild_project", but I've checked the Terraform documentation and I don't think it's possible to write it this way.
https://registry.terraform.io/providers/hashicorp/aws/4.39.0/docs/resources/codebuild_project.html
To define a "Runner project" for CodeBuild in Terraform, you need to configure specific settings in your CodeBuild project resource. While there isn't a direct "Runner project" option in Terraform, you can achieve this functionality by setting up the project with the appropriate configurations.
Here's how you can set up a CodeBuild project as a runner for GitHub Actions:
-
In your Terraform configuration for the CodeBuild project, you need to set up a webhook with specific filter patterns.
-
The webhook should have a filter group with the following settings:
- Set the
build_typeto "RUNNER_BUILDKITE_BUILD" or "RUNNER_GITHUB_ACTIONS_BUILD" depending on your use case. - Add an event filter with the type "EVENT" and pattern "WORKFLOW_JOB_QUEUED".
- Set the
-
Configure the project's environment variables to include necessary settings for the runner. For GitHub Actions, you might need to set
CODEBUILD_CONFIG_GITHUB_ACTIONS_ENTERPRISE_REGISTRATION_NAMEif you're registering runners at the enterprise level. -
Set the source type to "NO_SOURCE" as runner projects don't typically have a source code repository.
-
Ensure the service role associated with the CodeBuild project has the necessary permissions for runner operations.
Here's a basic example of how your Terraform configuration might look:
resource "aws_codebuild_project" "github_actions_runner" { name = "github-actions-runner" service_role = aws_iam_role.codebuild_service_role.arn artifacts { type = "NO_ARTIFACTS" } environment { compute_type = "BUILD_GENERAL1_SMALL" image = "aws/codebuild/amazonlinux2-x86_64-standard:3.0" type = "LINUX_CONTAINER" image_pull_credentials_type = "CODEBUILD" environment_variable { name = "CODEBUILD_CONFIG_GITHUB_ACTIONS_ENTERPRISE_REGISTRATION_NAME" value = "your-enterprise-name" } } source { type = "NO_SOURCE" } webhook { build_type = "RUNNER_GITHUB_ACTIONS_BUILD" filter_group { filter { type = "EVENT" pattern = "WORKFLOW_JOB_QUEUED" } } } }
Remember to adjust the configuration based on your specific requirements, such as the compute type, image, and any additional environment variables or settings needed for your runner project.
After applying this Terraform configuration, you should have a CodeBuild project set up as a runner for GitHub Actions, similar to what you would achieve through the AWS Console.
Sources
Tutorial: Configure a CodeBuild-hosted GitHub Actions runner - AWS CodeBuild
Setting up a Buildkite runner programmatically - AWS CodeBuild
answered a year ago
Relevant content
- AWS OFFICIALUpdated 9 months ago
