From f8faea1855fb5fbb4db99d34421b5d6999b17ca3 Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Sat, 16 Dec 2023 19:00:50 +0300 Subject: [PATCH] feat(vault-github): use `coder_env` to set `VAULT_ADDR` in workspace (#112) --- vault-github/README.md | 10 ---------- vault-github/main.tf | 9 ++++++++- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/vault-github/README.md b/vault-github/README.md index d515d01..76550cf 100644 --- a/vault-github/README.md +++ b/vault-github/README.md @@ -17,16 +17,6 @@ module "vault" { agent_id = coder_agent.example.id vault_addr = "https://vault.example.com" } - -# A workaround until we have https://github.com/coder/terraform-provider-coder/issues/170 -resource "coder_agent" "example" { - ... - env = { - VAULT_ADDR = "https://vault.example.com" - } - ... -} - ``` Then you can use the Vault CLI in your workspaces to fetch secrets from Vault: diff --git a/vault-github/main.tf b/vault-github/main.tf index d194f8c..f059b3a 100644 --- a/vault-github/main.tf +++ b/vault-github/main.tf @@ -4,7 +4,7 @@ terraform { required_providers { coder = { source = "coder/coder" - version = ">= 0.12" + version = ">= 0.12.4" } } } @@ -43,6 +43,7 @@ variable "vault_cli_version" { } data "coder_workspace" "me" {} + resource "coder_script" "vault" { agent_id = var.agent_id display_name = "Vault (GitHub)" @@ -57,6 +58,12 @@ resource "coder_script" "vault" { start_blocks_login = true } +resource "coder_env" "vault_addr" { + agent_id = var.agent_id + name = "VAULT_ADDR" + value = var.vault_addr +} + data "coder_external_auth" "github" { id = var.coder_github_auth_id }