Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: Add app support#17

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
kylecarbs merged 1 commit intomainfromdevurl
May 6, 2022
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletionsdocs/resources/app.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "coder_app Resource - terraform-provider-coder"
subcategory: ""
description: |-
Use this resource to define shortcuts to access applications in a workspace.
---

# coder_app (Resource)

Use this resource to define shortcuts to access applications in a workspace.

## Example Usage

```terraform
data "coder_workspace" "me" {}

resource "coder_agent" "dev" {
os = "linux"
arch = "amd64"
dir = "/workspace"
startup_script = <<EOF
curl -fsSL https://code-server.dev/install.sh | sh
code-server --auth none --port 13337
EOF
}

resource "coder_app" "code-server" {
agent_id = coder_agent.dev.id
name = "VS Code"
icon = data.coder_workspace.me.access_url + "/icons/vscode.svg"
target = "http://localhost:13337"
}

resource "coder_app" "vim" {
agent_id = coder_agent.dev.id
name = "Vim"
icon = data.coder_workspace.me.access_url + "/icons/vim.svg"
command = "vim"
}

resource "coder_app" "intellij" {
agent_id = coder_agent.dev.id
icon = data.coder_workspace.me.access_url + "/icons/intellij.svg"
name = "JetBrains IntelliJ"
command = "projector run"
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `agent_id` (String) The "id" property of a "coder_agent" resource to associate with.

### Optional

- `command` (String) A command to run in a terminal opening this app. In the web, this will open in a new tab. In the CLI, this will SSH and execute the command.
- `icon` (String) A URL to an icon that will display in the dashboard. View built-in icons here: https://github.com/coder/coder/tree/main/site/static/icons. Use a built-in icon with `data.coder_workspace.me.access_url + "/icons/<path>"`.
- `id` (String) The ID of this resource.
- `name` (String) A display name to identify the app.
- `target` (String) A URL to be proxied to from inside the workspace.


32 changes: 32 additions & 0 deletionsexamples/resources/coder_app/resource.tf
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
data "coder_workspace" "me" {}

resource "coder_agent" "dev" {
os = "linux"
arch = "amd64"
dir = "/workspace"
startup_script = <<EOF
curl -fsSL https://code-server.dev/install.sh | sh
code-server --auth none --port 13337
EOF
}

resource "coder_app" "code-server" {
agent_id = coder_agent.dev.id
name = "VS Code"
icon = data.coder_workspace.me.access_url + "/icons/vscode.svg"
target = "http://localhost:13337"
}

resource "coder_app" "vim" {
agent_id = coder_agent.dev.id
name = "Vim"
icon = data.coder_workspace.me.access_url + "/icons/vim.svg"
command = "vim"
}

resource "coder_app" "intellij" {
agent_id = coder_agent.dev.id
icon = data.coder_workspace.me.access_url + "/icons/intellij.svg"
name = "JetBrains IntelliJ"
command = "projector run"
}
69 changes: 69 additions & 0 deletionsinternal/provider/provider.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -89,9 +89,19 @@ func New() *schema.Provider {
id = uuid.NewString()
}
rd.SetId(id)
config, valid := i.(config)
if !valid {
return diag.Errorf("config was unexpected type %q", reflect.TypeOf(i).String())
}
rd.Set("access_url", config.URL.String())
return nil
},
Schema: map[string]*schema.Schema{
"access_url": {
Type: schema.TypeString,
Computed: true,
Description: "The access URL of the Coder deployment provisioning this workspace.",
},
"start_count": {
Type: schema.TypeInt,
Computed: true,
Expand DownExpand Up@@ -227,6 +237,65 @@ func New() *schema.Provider {
},
},
},
"coder_app": {
Description: "Use this resource to define shortcuts to access applications in a workspace.",
CreateContext: func(c context.Context, resourceData *schema.ResourceData, i interface{}) diag.Diagnostics {
resourceData.SetId(uuid.NewString())
return nil
},
ReadContext: func(c context.Context, resourceData *schema.ResourceData, i interface{}) diag.Diagnostics {
return nil
},
DeleteContext: func(ctx context.Context, rd *schema.ResourceData, i interface{}) diag.Diagnostics {
return nil
},
Schema: map[string]*schema.Schema{
"agent_id": {
Type: schema.TypeString,
Description: `The "id" property of a "coder_agent" resource to associate with.`,
ForceNew: true,
Required: true,
},
"command": {
Type: schema.TypeString,
Description: "A command to run in a terminal opening this app. In the web, " +
"this will open in a new tab. In the CLI, this will SSH and execute the command. " +
"Either \"command\" or \"target\" may be specified, but not both.",
ConflictsWith: []string{"target"},
Optional: true,
ForceNew: true,
},
"icon": {
Type: schema.TypeString,
Description: "A URL to an icon that will display in the dashboard. View built-in " +
"icons here: https://github.com/coder/coder/tree/main/site/static/icons. Use a " +
"built-in icon with `data.coder_workspace.me.access_url + \"/icons/<path>\"`.",
ForceNew: true,
Optional: true,
ValidateFunc: func(i interface{}, s string) ([]string, []error) {
_, err := url.Parse(s)
if err != nil {
return nil, []error{err}
}
return nil, nil
},
},
"name": {
Type: schema.TypeString,
Description: "A display name to identify the app.",
ForceNew: true,
Optional: true,
},
"target": {
Type: schema.TypeString,
Description: "A URL to be proxied to from inside the workspace. " +
"Either \"command\" or \"target\" may be specified, but not both.",
ForceNew: true,
Optional: true,
ConflictsWith: []string{"command"},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

We don't seem to document theConflictsWith requirements at all.

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

True. I shall fix!

},
},
},
},
}
}
Expand Down
44 changes: 44 additions & 0 deletionsinternal/provider/provider_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -134,3 +134,47 @@ func TestAgentInstance(t *testing.T) {
}},
})
}

func TestApp(t *testing.T) {
t.Parallel()
resource.Test(t, resource.TestCase{
Providers: map[string]*schema.Provider{
"coder": provider.New(),
},
IsUnitTest: true,
Steps: []resource.TestStep{{
Config: `
provider "coder" {
}
resource "coder_agent" "dev" {
os = "linux"
arch = "amd64"
}
resource "coder_app" "code-server" {
agent_id = coder_agent.dev.id
name = "code-server"
icon = "builtin:vim"
target = "http://localhost:13337"
}
`,
Check: func(state *terraform.State) error {
require.Len(t, state.Modules, 1)
require.Len(t, state.Modules[0].Resources, 2)
resource := state.Modules[0].Resources["coder_app.code-server"]
require.NotNil(t, resource)
for _, key := range []string{
"agent_id",
"name",
"icon",
"target",
} {
value := resource.Primary.Attributes[key]
t.Logf("%q = %q", key, value)
require.NotNil(t, value)
require.Greater(t, len(value), 0)
}
return nil
},
}},
})
}

[8]ページ先頭

©2009-2025 Movatter.jp