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 auth property to coder_agent_script#5

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 intomainfromauthtype
Mar 25, 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
1 change: 1 addition & 0 deletionsdocs/data-sources/agent_script.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -37,6 +37,7 @@ resource "kubernetes_pod" "dev" {

### Optional

- **auth** (String) The authentication type the agent will use. Must be one of: "token", "google-instance-identity", "aws-instance-identity", "azure-instance-identity".
- **id** (String) The ID of this resource.

### Read-Only
Expand Down
2 changes: 2 additions & 0 deletionsdocs/data-sources/workspace.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -30,6 +30,8 @@ resource "kubernetes_pod" "dev" {

### Read-Only

- **name** (String) Name of the workspace.
- **transition** (String) Either "start" or "stop". Use this to start/stop resources with "count".
- **username** (String) Username of the workspace owner.


10 changes: 1 addition & 9 deletionsdocs/resources/agent.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -40,21 +40,13 @@ resource "google_compute_instance" "dev" {

### Optional

- **auth** (Block List, Max: 1) Authenticate an instance with zero-trust by using cloud metadata APIs. (see [below for nested schema](#nestedblock--auth))
- **env** (Map of String) A mapping of environment variables to set inside the workspace.
- **id** (String) The ID of this resource.
- **instance_id** (String) An instance ID from a provisioned instance to enable zero-trust agent authentication.
- **startup_script** (String) A script to run after the agent starts.

### Read-Only

- **token** (String) Set the environment variable "CODER_TOKEN" with this token to authenticate an agent.

<a id="nestedblock--auth"></a>
### Nested Schema for `auth`

Optional:

- **instance_id** (String) A unique ID from the created compute resource to identify with cloud metadata APIs.
- **type** (String) The authentication type to use. Must be one of: "google-instance-identity".


48 changes: 27 additions & 21 deletionsinternal/provider/provider.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -65,6 +65,8 @@ func New() *schema.Provider {
transition = "start"
}
rd.Set("transition", transition)
rd.Set("username", os.Getenv("CODER_WORKSPACE_USERNAME"))
Copy link
Member

@bpmctbpmctMar 25, 2022
edited
Loading

Choose a reason for hiding this comment

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

thoughts onowner andCODER_WORKSPACE_OWNER instead? to me, username sounds like a property unique to the workspace.

rd.Set("name", os.Getenv("CODER_WORKSPACE_NAME"))
return nil
},
Schema: map[string]*schema.Schema{
Expand All@@ -73,6 +75,16 @@ func New() *schema.Provider {
Computed: true,
Description: `Either "start" or "stop". Use this to start/stop resources with "count".`,
},
"username": {
Type: schema.TypeString,
Computed: true,
Description: "Username of the workspace owner.",
},
"name": {
Type: schema.TypeString,
Computed: true,
Description: "Name of the workspace.",
},
},
},
"coder_agent_script": {
Expand All@@ -82,6 +94,10 @@ func New() *schema.Provider {
if !valid {
return diag.Errorf("config was unexpected type %q", reflect.TypeOf(i).String())
}
auth, valid := resourceData.Get("auth").(string)
if !valid {
return diag.Errorf("auth was unexpected type %q", reflect.TypeOf(resourceData.Get("auth")))
}
operatingSystem, valid := resourceData.Get("os").(string)
if !valid {
return diag.Errorf("os was unexpected type %q", reflect.TypeOf(resourceData.Get("os")))
Expand All@@ -97,6 +113,7 @@ func New() *schema.Provider {
script := os.Getenv(fmt.Sprintf("CODER_AGENT_SCRIPT_%s_%s", operatingSystem, arch))
if script != "" {
script = strings.ReplaceAll(script, "${ACCESS_URL}", accessURL.String())
script = strings.ReplaceAll(script, "${AUTH_TYPE}", auth)
}
err = resourceData.Set("value", script)
if err != nil {
Expand All@@ -106,6 +123,13 @@ func New() *schema.Provider {
return nil
},
Schema: map[string]*schema.Schema{
"auth": {
Type: schema.TypeString,
Default: "token",
Optional: true,
Description: `The authentication type the agent will use. Must be one of: "token", "google-instance-identity", "aws-instance-identity", "azure-instance-identity".`,
ValidateFunc: validation.StringInSlice([]string{"token", "google-instance-identity", "aws-instance-identity", "azure-instance-identity"}, false),
},
"os": {
Type: schema.TypeString,
Required: true,
Expand DownExpand Up@@ -144,29 +168,11 @@ func New() *schema.Provider {
return nil
},
Schema: map[string]*schema.Schema{
"auth": {
"instance_id": {
ForceNew: true,
Description: "Authenticate an instance with zero-trust by using cloud metadata APIs.",
Type: schema.TypeList,
Description: "An instance ID from a provisioned instance to enable zero-trust agent authentication.",
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"type": {
ForceNew: true,
Description: `The authentication type to use. Must be one of: "google-instance-identity".`,
Optional: true,
Type: schema.TypeString,
ValidateFunc: validation.StringInSlice([]string{"google-instance-identity"}, false),
},
"instance_id": {
ForceNew: true,
Description: "A unique ID from the created compute resource to identify with cloud metadata APIs.",
Optional: true,
Type: schema.TypeString,
},
},
},
Type: schema.TypeString,
},
"env": {
ForceNew: true,
Expand Down
8 changes: 2 additions & 6 deletionsinternal/provider/provider_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -117,10 +117,7 @@ func TestAgent(t *testing.T) {
url = "https://example.com"
}
resource "coder_agent" "new" {
auth {
type = "google-instance-identity"
instance_id = "instance"
}
instance_id = "instance"
env = {
hi = "test"
}
Expand All@@ -133,8 +130,7 @@ func TestAgent(t *testing.T) {
require.NotNil(t, resource)
for _, key := range []string{
"token",
"auth.0.type",
"auth.0.instance_id",
"instance_id",
"env.hi",
"startup_script",
} {
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp