-
Notifications
You must be signed in to change notification settings - Fork 22
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
chore!: remove deprecated items from coder_workspace
data source
#255
Changes from all commits
d14d6ee
1da8ba7
4d5b168
4dbf571
c7ce74a
d38e383
ff0131f
c916802
f604605
f4a4746
28d764d
396eaff
4ede0cd
001c185
7337eac
025afb1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, | ||
} | ||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there was no var defined so used the already defined agent. |
||
name = "GIT_AUTHOR_EMAIL" | ||
value = data.coder_workspace_owner.me.email | ||
count = data.coder_workspace_owner.me.email != "" ? 1 : 0 | ||
|
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 | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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-]+`, | ||
Comment on lines
-81
to
-87
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. removed all owner related items from the integration test. We already have a separate integration test for |
||
"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`, | ||
}, | ||
}, | ||
{ | ||
|
@@ -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`, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,6 @@ package provider | |
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"reflect" | ||
"strconv" | ||
|
||
|
@@ -28,37 +27,9 @@ func workspaceDataSource() *schema.Resource { | |
} | ||
_ = rd.Set("start_count", count) | ||
|
||
owner := helpers.OptionalEnvOrDefault("CODER_WORKSPACE_OWNER", "default") | ||
_ = rd.Set("owner", owner) | ||
|
||
ownerEmail := helpers.OptionalEnvOrDefault("CODER_WORKSPACE_OWNER_EMAIL", "[email protected]") | ||
_ = rd.Set("owner_email", ownerEmail) | ||
|
||
ownerGroupsText := helpers.OptionalEnv("CODER_WORKSPACE_OWNER_GROUPS") | ||
var ownerGroups []string | ||
if ownerGroupsText != "" { | ||
err := json.Unmarshal([]byte(ownerGroupsText), &ownerGroups) | ||
if err != nil { | ||
return diag.Errorf("couldn't parse owner groups %q", ownerGroupsText) | ||
} | ||
} | ||
_ = rd.Set("owner_groups", ownerGroups) | ||
|
||
ownerName := helpers.OptionalEnvOrDefault("CODER_WORKSPACE_OWNER_NAME", "default") | ||
_ = rd.Set("owner_name", ownerName) | ||
|
||
ownerID := helpers.OptionalEnvOrDefault("CODER_WORKSPACE_OWNER_ID", uuid.Nil.String()) | ||
_ = rd.Set("owner_id", ownerID) | ||
|
||
ownerOIDCAccessToken := helpers.OptionalEnv("CODER_WORKSPACE_OWNER_OIDC_ACCESS_TOKEN") | ||
_ = rd.Set("owner_oidc_access_token", ownerOIDCAccessToken) | ||
|
||
name := helpers.OptionalEnvOrDefault("CODER_WORKSPACE_NAME", "default") | ||
rd.Set("name", name) | ||
|
||
sessionToken := helpers.OptionalEnv("CODER_WORKSPACE_OWNER_SESSION_TOKEN") | ||
_ = rd.Set("owner_session_token", sessionToken) | ||
|
||
id := helpers.OptionalEnvOrDefault("CODER_WORKSPACE_ID", uuid.NewString()) | ||
rd.SetId(id) | ||
|
||
|
@@ -122,47 +93,6 @@ func workspaceDataSource() *schema.Resource { | |
Computed: true, | ||
Description: "Either `start` or `stop`. Use this to start/stop resources with `count`.", | ||
}, | ||
"owner": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "Username of the workspace owner.", | ||
Deprecated: "Use `coder_workspace_owner.name` instead.", | ||
}, | ||
"owner_email": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "Email address of the workspace owner.", | ||
Deprecated: "Use `coder_workspace_owner.email` instead.", | ||
}, | ||
"owner_id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "UUID of the workspace owner.", | ||
Deprecated: "Use `coder_workspace_owner.id` instead.", | ||
}, | ||
"owner_name": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "Name of the workspace owner.", | ||
Deprecated: "Use `coder_workspace_owner.full_name` instead.", | ||
}, | ||
"owner_oidc_access_token": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "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.", | ||
Deprecated: "Use `coder_workspace_owner.oidc_access_token` instead.", | ||
}, | ||
"owner_groups": { | ||
Type: schema.TypeList, | ||
Elem: &schema.Schema{ | ||
Type: schema.TypeString, | ||
}, | ||
Computed: true, | ||
Description: "List of groups the workspace owner belongs to.", | ||
Deprecated: "Use `coder_workspace_owner.groups` instead.", | ||
}, | ||
"id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
|
@@ -173,12 +103,6 @@ func workspaceDataSource() *schema.Resource { | |
Computed: true, | ||
Description: "Name of the workspace.", | ||
}, | ||
"owner_session_token": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "Session token for authenticating with a Coder deployment. It is regenerated everytime a workspace is started.", | ||
Deprecated: "Use `coder_workspace_owner.session_token` instead.", | ||
}, | ||
"template_id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Elaborated example usage. If its too much happy to simply it.