Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
376 changes: 376 additions & 0 deletions github-self-hosted-runner/ARCHITECTURE.md

Large diffs are not rendered by default.

466 changes: 466 additions & 0 deletions github-self-hosted-runner/README.md

Large diffs are not rendered by default.

48 changes: 48 additions & 0 deletions github-self-hosted-runner/data.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# ==========================================
# 生成资源后缀,避免命名冲突
# ==========================================

resource "random_string" "resource_suffix" {
length = 6
upper = false
lower = true
numeric = true
special = false
}

# ==========================================
# 查询可用的 Ubuntu 镜像
# ==========================================

data "qiniu_compute_images" "available_official_images" {
type = "Official"
state = "Available"
}

# ==========================================
# 本地变量定义
# ==========================================

locals {
# 资源后缀
runner_suffix = random_string.resource_suffix.result

# 选用 Ubuntu 24.04 LTS 镜像
ubuntu_image_id = one([
for item in data.qiniu_compute_images.available_official_images.items : item
if item.os_distribution == "Ubuntu" && item.os_version == "24.04 LTS"
]).id
Comment on lines +31 to +34
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ HIGH: Missing Null Check for Image Lookup

If no Ubuntu 24.04 LTS image is found, one() returns null, and accessing .id will fail with a cryptic error during terraform plan.

Fix: Add proper validation:

locals {
  # Find Ubuntu 24.04 images
  ubuntu_images = [
    for item in data.qiniu_compute_images.available_official_images.items : item
    if item.os_distribution == "Ubuntu" && item.os_version == "24.04 LTS"
  ]
  
  # Validate image exists
  ubuntu_image_id = length(local.ubuntu_images) > 0 ? local.ubuntu_images[0].id : null
}

# Add validation
resource "null_resource" "validate_image" {
  lifecycle {
    precondition {
      condition     = local.ubuntu_image_id != null
      error_message = "No Ubuntu 24.04 LTS image found in available official images. Please verify image availability."
    }
  }
}


# Runner 名称(用户指定或自动生成)
runner_name = var.runner_name != "" ? var.runner_name : "runner-${local.runner_suffix}"

# 合并默认标签和用户自定义标签
runner_labels = concat(
["self-hosted", "linux", "x64"],
var.runner_labels
)

# 从 GitHub URL 提取 owner 和 repo
github_owner = split("/", trimprefix(var.github_repo_url, "https://github.com/"))[0]
github_repo = split("/", trimprefix(var.github_repo_url, "https://github.com/"))[1]
}
Loading