From 7d31865c94070c640e0c31c72427bdfe2cb0eeb0 Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Fri, 26 Jan 2024 16:13:03 +0300 Subject: [PATCH] feat!(git-clone): change `path` input to `base_dir` and return `repo_dir` as output (#132) --- git-clone/README.md | 4 ++-- git-clone/main.tf | 15 ++++++++++++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/git-clone/README.md b/git-clone/README.md index db4ce5f..817a22c 100644 --- a/git-clone/README.md +++ b/git-clone/README.md @@ -9,7 +9,7 @@ tags: [git, helper] # Git Clone -This module allows you to automatically clone a repository by URL and skip if it exists in the path provided. +This module allows you to automatically clone a repository by URL and skip if it exists in the base directory provided. ```hcl module "git-clone" { @@ -38,6 +38,6 @@ module "git-clone" { version = "1.0.0" agent_id = coder_agent.example.id url = "https://github.com/coder/coder" - path = "~/projects/coder/coder" + base_dir = "~/projects/coder" } ``` diff --git a/git-clone/main.tf b/git-clone/main.tf index 4f32232..c1e65cf 100644 --- a/git-clone/main.tf +++ b/git-clone/main.tf @@ -14,9 +14,9 @@ variable "url" { type = string } -variable "path" { +variable "base_dir" { default = "" - description = "The path to clone the repository. Defaults to \"$HOME/\"." + description = "The base directory to clone the repository. Defaults to \"$HOME\"." type = string } @@ -25,10 +25,19 @@ variable "agent_id" { type = string } +locals { + clone_path = var.base_dir != "" ? join("/", [var.base_dir, replace(basename(var.url), ".git", "")]) : join("/", ["~", replace(basename(var.url), ".git", "")]) +} + +output "repo_dir" { + value = local.clone_path + description = "Full path of cloned repo directory" +} + resource "coder_script" "git_clone" { agent_id = var.agent_id script = templatefile("${path.module}/run.sh", { - CLONE_PATH = var.path != "" ? join("/", [var.path, replace(basename(var.url), ".git", "")]) : join("/", ["~", replace(basename(var.url), ".git", "")]) + CLONE_PATH = local.clone_path REPO_URL : var.url, }) display_name = "Git Clone"