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

Commit0f02f9b

Browse files
committed
feat: Remove agent_script data source to simplify resources
This adds a new resource for associating instance IDs, which will onlyneed to be used in edge-cases. We'll auto-detect instance identifiersfor the most popular cases, and perform zero-trust authentication.It seemed weird to separate the agent script and agent itself. This alsoled to difficulties previewing the operating system prior to start.
1 parent549826b commit0f02f9b

File tree

12 files changed

+256
-253
lines changed

12 files changed

+256
-253
lines changed

‎Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
default: testacc
22

3+
fmt:
4+
terraform fmt -recursive
5+
6+
gen:
7+
# go install github.com/hashicorp/terraform-plugin-docs/cmd/tfplugindocs@latest
8+
tfplugindocs
9+
310
# Run acceptance tests
411
.PHONY: testacc
512
testacc:

‎docs/data-sources/agent_script.md

Lines changed: 0 additions & 47 deletions
This file was deleted.

‎docs/data-sources/workspace.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,13 @@ resource "kubernetes_pod" "dev" {
2626

2727
###Optional
2828

29-
-**id** (String) The ID of this resource.
29+
-`id` (String) The ID of this resource.
3030

3131
###Read-Only
3232

33-
-**name** (String) Name of the workspace.
34-
-**owner** (String) Username of the workspace owner.
35-
-**transition** (String) Either "start" or "stop". Use this to start/stop resources with "count".
33+
-`name` (String) Name of the workspace.
34+
-`owner` (String) Username of the workspace owner.
35+
-`start_count` (Number) A computed count based on "transition" state. If "start", count will equal 1.
36+
-`transition` (String) Either "start" or "stop". Use this to start/stop resources with "count".
3637

3738

‎docs/index.md

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@ description: |-
1313
##Example
1414

1515
```terraform
16-
variable "gcp_credentials" {
17-
sensitive = true
18-
}
19-
2016
terraform {
2117
required_providers {
2218
coder = {
@@ -26,26 +22,25 @@ terraform {
2622
}
2723
2824
provider "google" {
29-
region = "us-central1"
30-
credentials = var.gcp_credentials
25+
region = "us-central1"
3126
}
3227
3328
data "coder_workspace" "me" {}
34-
data "google_compute_default_service_account" "default" {}
35-
data "coder_agent_script" "dev" {
36-
arch = "amd64"
37-
os = "linux"
38-
}
39-
resource "random_string" "random" {
40-
count = data.coder_workspace.me.transition == "start" ? 1 : 0
41-
length = 8
42-
special = false
29+
30+
resource "coder_agent" "dev" {
31+
count = data.coder_workspace.me.transition == "start" ? 1 : 0
32+
auth {
33+
type = "google-instance-identity"
34+
instance_id = google_compute_instance.dev[0].instance_id
35+
}
4336
}
4437
38+
data "google_compute_default_service_account" "default" {}
39+
4540
resource "google_compute_instance" "dev" {
4641
zone = "us-central1-a"
47-
count =data.coder_workspace.me.transition == "start" ? 1 : 0
48-
name = "coder-${lower(random_string.random[0].result)}"
42+
count =length(coder_agent.dev)
43+
name = "coder-${data.coder_workspace.me.owner}-${data.coder_workspace.me.name}"
4944
machine_type = "e2-medium"
5045
network_interface {
5146
network = "default"
@@ -62,15 +57,7 @@ resource "google_compute_instance" "dev" {
6257
email = data.google_compute_default_service_account.default.email
6358
scopes = ["cloud-platform"]
6459
}
65-
metadata_startup_script = data.coder_agent_script.dev.value
66-
}
67-
68-
resource "coder_agent" "dev" {
69-
count = length(google_compute_instance.dev)
70-
auth {
71-
type = "google-instance-identity"
72-
instance_id = google_compute_instance.dev[0].instance_id
73-
}
60+
metadata_startup_script = coder_agent.dev.init_script
7461
}
7562
```
7663

@@ -79,4 +66,4 @@ resource "coder_agent" "dev" {
7966

8067
###Optional
8168

82-
-**url** (String) The URL to access Coder.
69+
-`url` (String) The URL to access Coder.

‎docs/resources/agent.md

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,15 @@ Use this resource to associate an agent.
1313
##Example Usage
1414

1515
```terraform
16-
data "coder_agent_script" "dev" {
16+
resource "coder_agent" "dev" {
1717
os = "linux"
1818
arch = "amd64"
1919
}
2020
21-
resource "coder_agent" "dev" {
22-
startup_script = "code-server"
23-
}
24-
25-
resource "google_compute_instance" "dev" {
21+
resource "kubernetes_pod" "dev" {
2622
spec {
2723
container {
28-
command = ["sh", "-c",data.coder_agent_script.dev.value]
24+
command = ["sh", "-c",coder_agent.dev.init_script]
2925
env {
3026
name = "CODER_TOKEN"
3127
value = coder_agent.dev.token
@@ -38,15 +34,21 @@ resource "google_compute_instance" "dev" {
3834
<!-- schema generated by tfplugindocs-->
3935
##Schema
4036

37+
###Required
38+
39+
-`arch` (String) The architecture the agent will run on. Must be one of: "amd64", "arm64".
40+
-`os` (String) The operating system the agent will run on. Must be one of: "linux", "darwin", or "windows".
41+
4142
###Optional
4243

43-
-**env** (Map ofString)A mapping of environment variables to set inside the workspace.
44-
-**id** (String)The ID ofthis resource.
45-
-**instance_id** (String)An instanceIDfrom a provisioned instance to enable zero-trust agent authentication.
46-
-**startup_script** (String) A script to run after the agent starts.
44+
-`auth` (String)The authentication type the agent will use. Must be one of: "token", "google-instance-identity", "aws-instance-identity", "azure-instance-identity".
45+
-`env` (Map ofString)A mapping ofenvironment variables to set inside the workspace.
46+
-`id` (String)TheIDof this resource.
47+
-`startup_script` (String) A script to run after the agent starts.
4748

4849
###Read-Only
4950

50-
-**token** (String) Set the environment variable "CODER_TOKEN" with this token to authenticate an agent.
51+
-`init_script` (String) Run this script on startup of an instance to initialize the agent.
52+
-`token` (String) Set the environment variable "CODER_TOKEN" with this token to authenticate an agent.
5153

5254

‎docs/resources/agent_instance.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title:"coder_agent_instance Resource - terraform-provider-coder"
4+
subcategory:""
5+
description:|-
6+
Use this resource to associate an instance ID with an agent for zero-trust authentication. This association is done automatically for "googlecomputeinstance", "awsinstance", "azurermlinuxvirtualmachine", and "azurermwindowsvirtual_machine" resources.
7+
---
8+
9+
#coder_agent_instance (Resource)
10+
11+
Use this resource to associate an instance ID with an agent for zero-trust authentication. This association is done automatically for "google_compute_instance", "aws_instance", "azurerm_linux_virtual_machine", and "azurerm_windows_virtual_machine" resources.
12+
13+
##Example Usage
14+
15+
```terraform
16+
resource "coder_agent" "dev" {
17+
os = "linux"
18+
arch = "amd64"
19+
auth = "google-instance-identity"
20+
}
21+
22+
resource "google_compute_instance" "dev" {
23+
zone = "us-central1-a"
24+
}
25+
26+
resource "coder_agent_instance" "dev" {
27+
agent_id = coder_agent.dev.id
28+
instance_id = google_compute_instance.dev.instance_id
29+
}
30+
```
31+
32+
<!-- schema generated by tfplugindocs-->
33+
##Schema
34+
35+
###Required
36+
37+
-`agent_id` (String) The "id" property of a "coder_agent" resource to associate with.
38+
-`instance_id` (String) The instance identifier of a provisioned resource.
39+
40+
###Optional
41+
42+
-`id` (String) The ID of this resource.
43+
44+

‎examples/data-sources/coder_agent_script/data-source.tf

Lines changed: 0 additions & 12 deletions
This file was deleted.

‎examples/provider/provider.tf

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
variable"gcp_credentials" {
2-
sensitive=true
3-
}
4-
51
terraform {
62
required_providers {
73
coder={
@@ -11,26 +7,25 @@ terraform {
117
}
128

139
provider"google" {
14-
region="us-central1"
15-
credentials=var.gcp_credentials
10+
region="us-central1"
1611
}
1712

1813
data"coder_workspace""me" {}
19-
data"google_compute_default_service_account""default" {}
20-
data"coder_agent_script""dev" {
21-
arch="amd64"
22-
os="linux"
23-
}
24-
resource"random_string""random" {
25-
count=data.coder_workspace.me.transition=="start"?1:0
26-
length=8
27-
special=false
14+
15+
resource"coder_agent""dev" {
16+
count=data.coder_workspace.me.transition=="start"?1:0
17+
auth {
18+
type="google-instance-identity"
19+
instance_id=google_compute_instance.dev[0].instance_id
20+
}
2821
}
2922

23+
data"google_compute_default_service_account""default" {}
24+
3025
resource"google_compute_instance""dev" {
3126
zone="us-central1-a"
32-
count=data.coder_workspace.me.transition=="start"?1:0
33-
name="coder-${lower(random_string.random[0].result)}"
27+
count=length(coder_agent.dev)
28+
name="coder-${data.coder_workspace.me.owner}-${data.coder_workspace.me.name}"
3429
machine_type="e2-medium"
3530
network_interface {
3631
network="default"
@@ -47,13 +42,5 @@ resource "google_compute_instance" "dev" {
4742
email=data.google_compute_default_service_account.default.email
4843
scopes=["cloud-platform"]
4944
}
50-
metadata_startup_script=data.coder_agent_script.dev.value
51-
}
52-
53-
resource"coder_agent""dev" {
54-
count=length(google_compute_instance.dev)
55-
auth {
56-
type="google-instance-identity"
57-
instance_id=google_compute_instance.dev[0].instance_id
58-
}
45+
metadata_startup_script=coder_agent.dev.init_script
5946
}

‎examples/resources/coder_agent/resource.tf

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
1-
data"coder_agent_script""dev" {
1+
resource"coder_agent""dev" {
22
os="linux"
33
arch="amd64"
44
}
55

6-
resource"coder_agent""dev" {
7-
startup_script="code-server"
8-
}
9-
10-
resource"google_compute_instance""dev" {
6+
resource"kubernetes_pod""dev" {
117
spec {
128
container {
13-
command=["sh","-c",data.coder_agent_script.dev.value]
9+
command=["sh","-c",coder_agent.dev.init_script]
1410
env {
1511
name="CODER_TOKEN"
1612
value=coder_agent.dev.token
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
resource"coder_agent""dev" {
2+
os="linux"
3+
arch="amd64"
4+
auth="google-instance-identity"
5+
}
6+
7+
resource"google_compute_instance""dev" {
8+
zone="us-central1-a"
9+
}
10+
11+
resource"coder_agent_instance""dev" {
12+
agent_id=coder_agent.dev.id
13+
instance_id=google_compute_instance.dev.instance_id
14+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp