From 935f99ffeed283110713898653ba7466685f122e Mon Sep 17 00:00:00 2001 From: Ben Date: Wed, 13 Jul 2022 08:39:55 +0000 Subject: [PATCH 1/6] example: add a bare/custom template example --- examples/templates/bare/README.md | 7 +++++ examples/templates/bare/main.tf | 50 +++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 examples/templates/bare/README.md create mode 100644 examples/templates/bare/main.tf diff --git a/examples/templates/bare/README.md b/examples/templates/bare/README.md new file mode 100644 index 0000000000000..fff556b7e0a2e --- /dev/null +++ b/examples/templates/bare/README.md @@ -0,0 +1,7 @@ +--- +name: Bare (custom template) +description: Use this template as a starting point for writing custom templates with Terraform +tags: [bare] +--- + +See diff --git a/examples/templates/bare/main.tf b/examples/templates/bare/main.tf new file mode 100644 index 0000000000000..5a31b851db952 --- /dev/null +++ b/examples/templates/bare/main.tf @@ -0,0 +1,50 @@ +terraform { + required_providers { + coder = { + source = "coder/coder" + } + } +} + +# This example does not provision any resources. Use this +# template as a starting point for writing custom templates +# using any Terraform resource/provider. +# +# see: https://coder.com/docs/coder-oss/latest/templates + +data "coder_workspace" "me" { + +} + +resource "coder_agent" "dev1" { + os = "linux" + arch = "amd64" + auth = "token" +} + +resource "null_resource" "fake-compute" { + # When a workspace is stopped, this resource is destroyed. + count = data.coder_workspace.me.transition == "start" ? 1 : 0 + + provisioner "local-exec" { + command = "echo 🔊 ${data.coder_workspace.me.owner} has started a workspace named ${data.coder_workspace.me.name}" + } + + # Run the Coder agent init script on resources + # to access web apps and SSH: + # + # ${coder_agent.dev1.init_script} +} + +resource "null_resource" "fake-disk" { + # This resource will remain even when workspaces are restarted + count = 1 +} + +resource "coder_app" "fake-app" { + # Access :8080 in the workspace from the Coder dashboard + name = "VS Code" + icon = "/icon/code.svg" + agent_id = "fake-compute" + url = "http://localhost:8080" +} From 336a627f6def47372645a3553760b879ff6873e9 Mon Sep 17 00:00:00 2001 From: Ben Date: Tue, 19 Jul 2022 12:59:49 +0000 Subject: [PATCH 2/6] mention Coder Agent token --- examples/templates/bare/main.tf | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/templates/bare/main.tf b/examples/templates/bare/main.tf index 5a31b851db952..a619620e55958 100644 --- a/examples/templates/bare/main.tf +++ b/examples/templates/bare/main.tf @@ -33,6 +33,7 @@ resource "null_resource" "fake-compute" { # Run the Coder agent init script on resources # to access web apps and SSH: # + # export CODER_AGENT_TOKEN=${coder_agent.dev1.token} # ${coder_agent.dev1.init_script} } From d3432d86257faed0a4008fd7ad9b09128ccbf12f Mon Sep 17 00:00:00 2001 From: Ben Potter Date: Tue, 19 Jul 2022 08:00:24 -0500 Subject: [PATCH 3/6] Update examples/templates/bare/main.tf Co-authored-by: Mathias Fredriksson --- examples/templates/bare/main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/templates/bare/main.tf b/examples/templates/bare/main.tf index a619620e55958..74ec9440e4c04 100644 --- a/examples/templates/bare/main.tf +++ b/examples/templates/bare/main.tf @@ -10,7 +10,7 @@ terraform { # template as a starting point for writing custom templates # using any Terraform resource/provider. # -# see: https://coder.com/docs/coder-oss/latest/templates +# See: https://coder.com/docs/coder-oss/latest/templates data "coder_workspace" "me" { From 01a49b9f342fb65d3c2eb89d7dc26c32a971b179 Mon Sep 17 00:00:00 2001 From: Ben Potter Date: Tue, 19 Jul 2022 08:00:28 -0500 Subject: [PATCH 4/6] Update examples/templates/bare/main.tf Co-authored-by: Mathias Fredriksson --- examples/templates/bare/main.tf | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/templates/bare/main.tf b/examples/templates/bare/main.tf index 74ec9440e4c04..a9780f175082f 100644 --- a/examples/templates/bare/main.tf +++ b/examples/templates/bare/main.tf @@ -13,7 +13,6 @@ terraform { # See: https://coder.com/docs/coder-oss/latest/templates data "coder_workspace" "me" { - } resource "coder_agent" "dev1" { From 6d891224759715f52e17aae74535f438cdf00991 Mon Sep 17 00:00:00 2001 From: Ben Potter Date: Tue, 19 Jul 2022 08:00:34 -0500 Subject: [PATCH 5/6] Update examples/templates/bare/main.tf Co-authored-by: Mathias Fredriksson --- examples/templates/bare/main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/templates/bare/main.tf b/examples/templates/bare/main.tf index a9780f175082f..b7949043c72dd 100644 --- a/examples/templates/bare/main.tf +++ b/examples/templates/bare/main.tf @@ -37,7 +37,7 @@ resource "null_resource" "fake-compute" { } resource "null_resource" "fake-disk" { - # This resource will remain even when workspaces are restarted + # This resource will remain even when workspaces are restarted. count = 1 } From bec4adfc0c8e5f1a66d5264789be1936df475100 Mon Sep 17 00:00:00 2001 From: Ben Potter Date: Tue, 19 Jul 2022 08:00:38 -0500 Subject: [PATCH 6/6] Update examples/templates/bare/main.tf Co-authored-by: Mathias Fredriksson --- examples/templates/bare/main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/templates/bare/main.tf b/examples/templates/bare/main.tf index b7949043c72dd..98619f38ee293 100644 --- a/examples/templates/bare/main.tf +++ b/examples/templates/bare/main.tf @@ -42,7 +42,7 @@ resource "null_resource" "fake-disk" { } resource "coder_app" "fake-app" { - # Access :8080 in the workspace from the Coder dashboard + # Access :8080 in the workspace from the Coder dashboard. name = "VS Code" icon = "/icon/code.svg" agent_id = "fake-compute"