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

Commitce5a2c6

Browse files
committed
docs: add examples for all resources & data sources
1 parentdfa7472 commitce5a2c6

File tree

10 files changed

+172
-6
lines changed

10 files changed

+172
-6
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Get a group on the provider default organization by `id`
2+
data"coderd_group""employees" {
3+
id="abcd-efg-hijk"
4+
}
5+
6+
// Get a group on the provider default organization by `name` + `organization_id`
7+
data"coderd_group""bosses" {
8+
name="bosses"
9+
}
10+
11+
// Use them to apply ACL to a template
12+
resource"coderd_template""example" {
13+
name="example-template"
14+
versions=[/* ...*/]
15+
acl={
16+
groups= [
17+
{
18+
id= data.coderd_group.employees.id
19+
role="use"
20+
},
21+
{
22+
id= data.coderd_group.bosses.id
23+
role="admin"
24+
}
25+
]
26+
users= []
27+
}
28+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Get the default (first) organization for the coder deployment
2+
data"coderd_organization""default" {
3+
is_default=true
4+
}
5+
6+
// Get another organization by `id`
7+
data"coderd_organization""example" {
8+
id="abcd-efg-hijk"
9+
}
10+
11+
data"coderd_organization""example2" {
12+
name="example-organization-2"
13+
}
14+
15+
// Create a group on a specific organization
16+
resource"coderd_group""example" {
17+
name="example-group"
18+
organization_id=data.coderd_organization.default.id
19+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Get a template on the provider's default organization by `id`
2+
data"coderd_template""example-template" {
3+
id="abcd-efg-hijk"
4+
}
5+
6+
// Get a template on the provider's default organization by `name`
7+
data"coderd_template""example-template2" {
8+
name="example-template-2"
9+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Get a user on the Coder deployment by `id`
2+
data"coderd_user""manager" {
3+
id="abcd-efg-hijk"
4+
}
5+
6+
// Get a user on the Coder deployment by `username`
7+
data"coderd_user""admin" {
8+
username="admin"
9+
}
10+
11+
12+
// Use them to create a group
13+
resource"coderd_group""bosses" {
14+
name="group"
15+
members=[
16+
data.coderd_user.admin.id,
17+
data.coderd_user.manager.id
18+
]
19+
}

‎examples/provider/provider.tf

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
terraform {
2+
required_providers {
3+
coderd={
4+
source="coder/coderd"
5+
}
6+
}
7+
}
8+
9+
provider"coderd" {
10+
# `token` and `url` can be populated from environment variables.
11+
# `default_organization_id` can be populated using
12+
# the first organization the session token has access to.
13+
}
14+
15+
16+
data"coderd_organization""default" {
17+
is_default=true
18+
}
19+
20+
data"coderd_user""admin" {
21+
username="admin"
22+
}
23+
24+
resource"coderd_user""manager" {
25+
username="Manager"
26+
email="manager@example.com"
27+
}
28+
29+
resource"coderd_group""bosses" {
30+
name="group"
31+
members=[
32+
data.coderd_user.admin.id,
33+
resource.coderd_user.manager.id
34+
]
35+
}
36+
37+
resource"coderd_template""example" {
38+
name="example-template"
39+
versions=[{
40+
directory="./example-template"
41+
active=true
42+
tf_vars= [{
43+
name="image_id"
44+
value="ami-12345678"
45+
}]
46+
# Version names can be randomly generated if null/omitted
47+
}]
48+
acl={
49+
groups= [{
50+
id= data.coderd_organization.default.id
51+
role="use"
52+
},
53+
{
54+
id= resource.coderd_group.bosses.id
55+
role="admin"
56+
}]
57+
users= []
58+
}
59+
allow_user_cancel_workspace_jobs=false
60+
}

‎examples/resources/coderd_user/resource.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,5 @@ resource "coderd_user" "audit" {
2424
resource"coderd_user""admin" {
2525
username="admin"
2626
suspended=true
27+
email="admin@example.com"
2728
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
resource"coderd_workspace_proxy""sydney-wsp" {
2+
name="sydney-wsp"
3+
display_name="Australia (Sydney)"
4+
icon="/emojis/1f1e6-1f1fa.png"
5+
}
6+
7+
resource"kubernetes_deployment""syd_wsproxy" {
8+
metadata {/* ...*/ }
9+
spec {
10+
template {
11+
metadata {/* ...*/ }
12+
spec {
13+
container {
14+
name="syd-wsp"
15+
image="ghcr.io/coder/coder:latest"
16+
args=["wsproxy"]
17+
env {
18+
name="CODER_PROXY_SESSION_TOKEN"
19+
value=coderd_workspace_proxy.sydney-wsp.session_token
20+
}
21+
/* ...*/
22+
}
23+
/* ...*/
24+
}
25+
}
26+
/* ...*/
27+
}
28+
}

‎internal/provider/group_resource.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func (r *GroupResource) Metadata(ctx context.Context, req resource.MetadataReque
6060

6161
func (r*GroupResource)Schema(ctx context.Context,req resource.SchemaRequest,resp*resource.SchemaResponse) {
6262
resp.Schema= schema.Schema{
63-
MarkdownDescription:"A group on the Coder deployment. If you want tohave a group resource with unmanaged members, butstill want to read the members in Terraform, use the `data.coderd_group` data source. Creating groups requires an Enterprise license.",
63+
MarkdownDescription:"A group on the Coder deployment.\n\nTohave a group resource with unmanaged members, butbe able to read the members in Terraform, use the `data.coderd_group` data source. Creating groups requires an Enterprise license.",
6464

6565
Attributes:map[string]schema.Attribute{
6666
"id": schema.StringAttribute{

‎internal/provider/provider.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,18 @@ func (p *CoderdProvider) Metadata(ctx context.Context, req provider.MetadataRequ
5353
func (p*CoderdProvider)Schema(ctx context.Context,req provider.SchemaRequest,resp*provider.SchemaResponse) {
5454
resp.Schema= schema.Schema{
5555
MarkdownDescription:`
56+
The coderd provider can be used to manage resources on a Coder deployment. The provider exposes resources and data sources for users, groups, templates, and workspace proxies.
57+
5658
~> **Warning**
5759
This provider is only compatible with Coder version [2.10.1](https://github.com/coder/coder/releases/tag/v2.10.1) and later.
5860
`,
5961
Attributes:map[string]schema.Attribute{
6062
"url": schema.StringAttribute{
61-
MarkdownDescription:"URL to the Coder deployment. Defaults to $CODER_URL.",
63+
MarkdownDescription:"URL to the Coder deployment. Defaults to`$CODER_URL`.",
6264
Optional:true,
6365
},
6466
"token": schema.StringAttribute{
65-
MarkdownDescription:"API token for communicating with the deployment. Most resource types require elevated permissions. Defaults to $CODER_SESSION_TOKEN.",
67+
MarkdownDescription:"API token for communicating with the deployment. Most resource types require elevated permissions. Defaults to`$CODER_SESSION_TOKEN`.",
6668
Optional:true,
6769
},
6870
"default_organization_id": schema.StringAttribute{

‎internal/provider/template_resource.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ func (r *TemplateResource) Schema(ctx context.Context, req resource.SchemaReques
343343
Default:int64default.StaticInt64(0),
344344
},
345345
"time_til_dormant_ms": schema.Int64Attribute{
346-
MarkdownDescription:"Enterprise) The max lifetime before Coder locks inactive workspaces created from this template, in milliseconds.",
346+
MarkdownDescription:"(Enterprise) The max lifetime before Coder locks inactive workspaces created from this template, in milliseconds.",
347347
Optional:true,
348348
Computed:true,
349349
Default:int64default.StaticInt64(0),
@@ -361,13 +361,13 @@ func (r *TemplateResource) Schema(ctx context.Context, req resource.SchemaReques
361361
Default:booldefault.StaticBool(false),
362362
},
363363
"deprecation_message": schema.StringAttribute{
364-
MarkdownDescription:"If set, the template will be marked as deprecated and users will be blocked from creating new workspaces from it.",
364+
MarkdownDescription:"If set, the template will be marked as deprecated and users will be blocked from creating new workspaces from it. The provided message will be displayed.",
365365
Optional:true,
366366
Computed:true,
367367
Default:stringdefault.StaticString(""),
368368
},
369369
"acl": schema.SingleNestedAttribute{
370-
MarkdownDescription:"(Enterprise) Access control list for the template. If null, ACL policies will not be addedorremoved by Terraform.",
370+
MarkdownDescription:"(Enterprise) Access control list for the template. If null, ACL policies will not be added, removed,orinspected by Terraform.",
371371
Optional:true,
372372
Attributes:map[string]schema.Attribute{
373373
"users":permissionAttribute,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp