Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat: expose is_prebuild_claim attribute #396

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 9, 2025
Merged

Conversation

dannykopping
Copy link
Contributor

@dannykopping dannykopping commented May 9, 2025

Template authors may need to augment their templates to execute scripts once a prebuilt workspace has been claimed.

is_prebuild_claim will be set only when a prebuilt workspace has just been claimed and its subsequent terraform apply is in progress.

Also adds some missing tests to ensure correct input (environment variables) handling.

Can be used in a template like so:

resource "coder_agent" "main" {
  arch           = data.coder_provisioner.me.arch
  os             = "linux"
  startup_script = <<-EOT
    set -e
if [[ "${data.coder_workspace.me.is_prebuild}" = "true" ]]; then
  echo "Created at $(date)" > ~/.prebuild_note # persists across restarts
fi
  EOT

  metadata {
    display_name = "Was Prebuild"
    key          = "prebuild"
    script       = "[[ -e ~/.prebuild_note ]] && echo 'Yes' || echo 'No'"
    interval     = 10
    timeout      = 1
  }
  metadata {
    display_name = "Was Claimed"
    key          = "prebuild_claim"
    script       = "[ '${data.coder_workspace.me.is_prebuild_claim}' = 'true' ] && echo 'Yes' || echo 'No'"
    interval     = 10
    timeout      = 1
  }
}

@dannykopping dannykopping requested a review from SasSwart May 9, 2025 12:08
@dannykopping dannykopping merged commit 50ed1c1 into main May 9, 2025
6 checks passed
@dannykopping dannykopping deleted the dk/is-prebuild-claim branch May 9, 2025 16:44
@github-actions github-actions bot locked and limited conversation to collaborators May 9, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants