Skip to content

Commit

Permalink
Merge branch 'main' into matifali/coder-agent-remove
Browse files Browse the repository at this point in the history
  • Loading branch information
matifali authored Jul 5, 2024
2 parents 533c613 + f46148f commit 85ff397
Show file tree
Hide file tree
Showing 17 changed files with 109 additions and 354 deletions.
8 changes: 2 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,11 @@ jobs:
fail-fast: false
matrix:
terraform:
- "1.0.*"
- "1.1.*"
- "1.2.*"
- "1.3.*"
- "1.4.*"
- "1.5.*"
- "1.6.*"
- "1.7.*"
- "1.8.*"
- "1.9.*"
steps:
- name: Set up Go
uses: actions/setup-go@v5
Expand Down Expand Up @@ -112,7 +108,7 @@ jobs:

- uses: hashicorp/setup-terraform@v3
with:
terraform_version: "1.3.*"
terraform_version: "latest"
terraform_wrapper: false

- name: Check out code into the Go module directory
Expand Down
52 changes: 0 additions & 52 deletions docs/data-sources/git_auth.md

This file was deleted.

53 changes: 43 additions & 10 deletions docs/data-sources/workspace.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,51 @@ Use this data source to get information for the active workspace build.
## Example Usage

```terraform
data "coder_workspace" "dev" {
provider "coder" {}
provider "docker" {}
data "coder_workspace" "me" {}
data "coder_workspace_owner" "me" {}
resource "coder_agent" "dev" {
arch = "amd64"
os = "linux"
dir = "/workspace"
}
resource "kubernetes_pod" "dev" {
count = data.coder_workspace.dev.transition == "start" ? 1 : 0
resource "docker_container" "workspace" {
count = data.coder_workspace.me.start_count
image = docker_image.main.name
# Uses lower() to avoid Docker restriction on container names.
name = "coder-${data.coder_workspace_owner.me.name}-${lower(data.coder_workspace.me.name)}"
# Hostname makes the shell more user friendly: coder@my-workspace:~$
hostname = data.coder_workspace.me.name
# Use the docker gateway if the access URL is 127.0.0.1
entrypoint = ["sh", "-c", replace(coder_agent.main.init_script, "/localhost|127\\.0\\.0\\.1/", "host.docker.internal")]
env = ["CODER_AGENT_TOKEN=${coder_agent.main.token}"]
host {
host = "host.docker.internal"
ip = "host-gateway"
}
# Add labels in Docker to keep track of orphan resources.
labels {
label = "coder.owner"
value = data.coder_workspace_owner.me.name
}
labels {
label = "coder.owner_id"
value = data.coder_workspace_owner.me.id
}
labels {
label = "coder.workspace_id"
value = data.coder_workspace.me.id
}
labels {
label = "coder.workspace_name"
value = data.coder_workspace.me.name
}
}
```

Expand All @@ -30,13 +70,6 @@ resource "kubernetes_pod" "dev" {
- `access_url` (String) The access URL of the Coder deployment provisioning this workspace.
- `id` (String) UUID of the workspace.
- `name` (String) Name of the workspace.
- `owner` (String, **Deprecated**: Use `coder_workspace_owner.name` instead.) Username of the workspace owner.
- `owner_email` (String, **Deprecated**: Use `coder_workspace_owner.email` instead.) Email address of the workspace owner.
- `owner_groups` (List of String, **Deprecated**: Use `coder_workspace_owner.groups` instead.) List of groups the workspace owner belongs to.
- `owner_id` (String, **Deprecated**: Use `coder_workspace_owner.id` instead.) UUID of the workspace owner.
- `owner_name` (String, **Deprecated**: Use `coder_workspace_owner.full_name` instead.) Name of the workspace owner.
- `owner_oidc_access_token` (String, **Deprecated**: Use `coder_workspace_owner.oidc_access_token` instead.) A valid OpenID Connect access token of the workspace owner. This is only available if the workspace owner authenticated with OpenID Connect. If a valid token cannot be obtained, this value will be an empty string.
- `owner_session_token` (String, **Deprecated**: Use `coder_workspace_owner.session_token` instead.) Session token for authenticating with a Coder deployment. It is regenerated everytime a workspace is started.
- `start_count` (Number) A computed count based on `transition` state. If `start`, count will equal 1.
- `template_id` (String) ID of the workspace's template.
- `template_name` (String) Name of the workspace's template.
Expand Down
6 changes: 2 additions & 4 deletions docs/data-sources/workspace_owner.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,12 @@ Use this data source to fetch information about the workspace owner.
```terraform
provider "coder" {}
data "coder_workspace" "me" {}
data "coder_workspace_owner" "me" {}
resource "coder_agent" "dev" {
arch = "amd64"
os = "linux"
dir = local.repo_dir
dir = "/workspace"
env = {
OIDC_TOKEN : data.coder_workspace_owner.me.oidc_access_token,
}
Expand All @@ -36,7 +34,7 @@ resource "coder_env" "git_author_name" {
}
resource "coder_env" "git_author_email" {
agent_id = var.agent_id
agent_id = coder_agent.dev.id
name = "GIT_AUTHOR_EMAIL"
value = data.coder_workspace_owner.me.email
count = data.coder_workspace_owner.me.email != "" ? 1 : 0
Expand Down
1 change: 0 additions & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,4 @@ resource "google_compute_instance" "dev" {

### Optional

- `feature_use_managed_variables` (Boolean, **Deprecated**: Terraform variables are now exclusively utilized for template-wide variables after the removal of support for legacy parameters.) Feature: use managed Terraform variables. The feature flag is not used anymore as Terraform variables are now exclusively utilized for template-wide variables.
- `url` (String) The URL to access Coder.
20 changes: 0 additions & 20 deletions examples/data-sources/coder_git_auth/data-source.tf

This file was deleted.

46 changes: 43 additions & 3 deletions examples/data-sources/coder_workspace/data-source.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,46 @@
data "coder_workspace" "dev" {
provider "coder" {}

provider "docker" {}

data "coder_workspace" "me" {}

data "coder_workspace_owner" "me" {}

resource "coder_agent" "dev" {
arch = "amd64"
os = "linux"
dir = "/workspace"
}

resource "kubernetes_pod" "dev" {
count = data.coder_workspace.dev.transition == "start" ? 1 : 0
resource "docker_container" "workspace" {
count = data.coder_workspace.me.start_count
image = docker_image.main.name
# Uses lower() to avoid Docker restriction on container names.
name = "coder-${data.coder_workspace_owner.me.name}-${lower(data.coder_workspace.me.name)}"
# Hostname makes the shell more user friendly: coder@my-workspace:~$
hostname = data.coder_workspace.me.name
# Use the docker gateway if the access URL is 127.0.0.1
entrypoint = ["sh", "-c", replace(coder_agent.main.init_script, "/localhost|127\\.0\\.0\\.1/", "host.docker.internal")]
env = ["CODER_AGENT_TOKEN=${coder_agent.main.token}"]
host {
host = "host.docker.internal"
ip = "host-gateway"
}
# Add labels in Docker to keep track of orphan resources.
labels {
label = "coder.owner"
value = data.coder_workspace_owner.me.name
}
labels {
label = "coder.owner_id"
value = data.coder_workspace_owner.me.id
}
labels {
label = "coder.workspace_id"
value = data.coder_workspace.me.id
}
labels {
label = "coder.workspace_name"
value = data.coder_workspace.me.name
}
}
6 changes: 2 additions & 4 deletions examples/data-sources/coder_workspace_owner/data-source.tf
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
provider "coder" {}

data "coder_workspace" "me" {}

data "coder_workspace_owner" "me" {}

resource "coder_agent" "dev" {
arch = "amd64"
os = "linux"
dir = local.repo_dir
dir = "/workspace"
env = {
OIDC_TOKEN : data.coder_workspace_owner.me.oidc_access_token,
}
Expand All @@ -21,7 +19,7 @@ resource "coder_env" "git_author_name" {
}

resource "coder_env" "git_author_email" {
agent_id = var.agent_id
agent_id = coder_agent.dev.id
name = "GIT_AUTHOR_EMAIL"
value = data.coder_workspace_owner.me.email
count = data.coder_workspace_owner.me.email != "" ? 1 : 0
Expand Down
38 changes: 12 additions & 26 deletions integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,25 +71,18 @@ func TestIntegration(t *testing.T) {
name: "test-data-source",
minVersion: "v0.0.0",
expectedOutput: map[string]string{
"provisioner.arch": runtime.GOARCH,
"provisioner.id": `[a-zA-Z0-9-]+`,
"provisioner.os": runtime.GOOS,
"workspace.access_port": `\d+`,
"workspace.access_url": `https?://\D+:\d+`,
"workspace.id": `[a-zA-z0-9-]+`,
"workspace.name": `test-data-source`,
"workspace.owner": `testing`,
"workspace.owner_email": `testing@coder\.com`,
"workspace.owner_groups": `\[\]`,
"workspace.owner_id": `[a-zA-Z0-9]+`,
"workspace.owner_name": `default`,
"workspace.owner_oidc_access_token": `^$`, // TODO: need a test OIDC integration
"workspace.owner_session_token": `[a-zA-Z0-9-]+`,
"workspace.start_count": `1`,
"workspace.template_id": `[a-zA-Z0-9-]+`,
"workspace.template_name": `test-data-source`,
"workspace.template_version": `.+`,
"workspace.transition": `start`,
"provisioner.arch": runtime.GOARCH,
"provisioner.id": `[a-zA-Z0-9-]+`,
"provisioner.os": runtime.GOOS,
"workspace.access_port": `\d+`,
"workspace.access_url": `https?://\D+:\d+`,
"workspace.id": `[a-zA-z0-9-]+`,
"workspace.name": `test-data-source`,
"workspace.start_count": `1`,
"workspace.template_id": `[a-zA-Z0-9-]+`,
"workspace.template_name": `test-data-source`,
"workspace.template_version": `.+`,
"workspace.transition": `start`,
},
},
{
Expand All @@ -103,13 +96,6 @@ func TestIntegration(t *testing.T) {
"workspace.access_url": `https?://\D+:\d+`,
"workspace.id": `[a-zA-z0-9-]+`,
"workspace.name": ``,
"workspace.owner": `testing`,
"workspace.owner_email": `testing@coder\.com`,
"workspace.owner_groups": `\[\]`,
"workspace.owner_id": `[a-zA-Z0-9]+`,
"workspace.owner_name": `default`,
"workspace.owner_oidc_access_token": `^$`, // TODO: need a test OIDC integration
"workspace.owner_session_token": `[a-zA-Z0-9-]+`,
"workspace.start_count": `1`,
"workspace.template_id": `[a-zA-Z0-9-]+`,
"workspace.template_name": `workspace-owner`,
Expand Down
10 changes: 1 addition & 9 deletions integration/test-data-source/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ terraform {
}
}

// TODO: test coder_external_auth and coder_git_auth
// TODO: test coder_external_auth
// data coder_external_auth "me" {}
// data coder_git_auth "me" {}
data "coder_provisioner" "me" {}
data "coder_workspace" "me" {}
data "coder_workspace_owner" "me" {}
Expand All @@ -26,13 +25,6 @@ locals {
"workspace.access_url" : data.coder_workspace.me.access_url,
"workspace.id" : data.coder_workspace.me.id,
"workspace.name" : data.coder_workspace.me.name,
"workspace.owner" : data.coder_workspace.me.owner,
"workspace.owner_email" : data.coder_workspace.me.owner_email,
"workspace.owner_groups" : jsonencode(data.coder_workspace.me.owner_groups),
"workspace.owner_id" : data.coder_workspace.me.owner_id,
"workspace.owner_name" : data.coder_workspace.me.owner_name,
"workspace.owner_oidc_access_token" : data.coder_workspace.me.owner_oidc_access_token,
"workspace.owner_session_token" : data.coder_workspace.me.owner_session_token,
"workspace.start_count" : tostring(data.coder_workspace.me.start_count),
"workspace.template_id" : data.coder_workspace.me.template_id,
"workspace.template_name" : data.coder_workspace.me.template_name,
Expand Down
10 changes: 1 addition & 9 deletions integration/workspace-owner/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ terraform {
}
}

// TODO: test coder_external_auth and coder_git_auth
// TODO: test coder_external_auth
// data coder_external_auth "me" {}
// data coder_git_auth "me" {}
data "coder_provisioner" "me" {}
data "coder_workspace" "me" {}
data "coder_workspace_owner" "me" {}
Expand All @@ -26,13 +25,6 @@ locals {
"workspace.access_url" : data.coder_workspace.me.access_url,
"workspace.id" : data.coder_workspace.me.id,
"workspace.name" : data.coder_workspace.me.name,
"workspace.owner" : data.coder_workspace.me.owner,
"workspace.owner_email" : data.coder_workspace.me.owner_email,
"workspace.owner_groups" : jsonencode(data.coder_workspace.me.owner_groups),
"workspace.owner_id" : data.coder_workspace.me.owner_id,
"workspace.owner_name" : data.coder_workspace.me.owner_name,
"workspace.owner_oidc_access_token" : data.coder_workspace.me.owner_oidc_access_token,
"workspace.owner_session_token" : data.coder_workspace.me.owner_session_token,
"workspace.start_count" : tostring(data.coder_workspace.me.start_count),
"workspace.template_id" : data.coder_workspace.me.template_id,
"workspace.template_name" : data.coder_workspace.me.template_name,
Expand Down
Loading

0 comments on commit 85ff397

Please sign in to comment.