Skip to content
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

Add tailscale tailnet key Description and update docs #277

Merged
merged 3 commits into from
Aug 30, 2023
Merged
Changes from all 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
2 changes: 2 additions & 0 deletions docs/resources/tailnet_key.md
Original file line number Diff line number Diff line change
@@ -18,6 +18,7 @@ resource "tailscale_tailnet_key" "sample_key" {
ephemeral = false
preauthorized = true
expiry = 3600
description = "Sample key"
}
```

@@ -26,6 +27,7 @@ resource "tailscale_tailnet_key" "sample_key" {

### Optional

- `description` (String) A description of the key consisting of alphanumeric characters.
- `ephemeral` (Boolean) Indicates if the key is ephemeral.
- `expiry` (Number) The expiry of the key in seconds
- `preauthorized` (Boolean) Determines whether or not the machines authenticated by the key will be authorized for the tailnet by default.
1 change: 1 addition & 0 deletions examples/resources/tailscale_tailnet_key/resource.tf
Original file line number Diff line number Diff line change
@@ -3,4 +3,5 @@ resource "tailscale_tailnet_key" "sample_key" {
ephemeral = false
preauthorized = true
expiry = 3600
description = "Sample key"
}
15 changes: 15 additions & 0 deletions tailscale/resource_tailnet_key.go
Original file line number Diff line number Diff line change
@@ -66,6 +66,12 @@ func resourceTailnetKey() *schema.Resource {
Description: "The expiry timestamp of the key in RFC3339 format",
Computed: true,
},
"description": {
julianorchard marked this conversation as resolved.
Show resolved Hide resolved
Type: schema.TypeString,
Optional: true,
Description: "A description of the key consisting of alphanumeric characters.",
ForceNew: true,
},
},
}
}
@@ -76,6 +82,7 @@ func resourceTailnetKeyCreate(ctx context.Context, d *schema.ResourceData, m int
ephemeral := d.Get("ephemeral").(bool)
preauthorized := d.Get("preauthorized").(bool)
expiry, hasExpiry := d.GetOk("expiry")
description, hasDescription := d.GetOk("description")
var tags []string
for _, tag := range d.Get("tags").(*schema.Set).List() {
tags = append(tags, tag.(string))
@@ -92,6 +99,10 @@ func resourceTailnetKeyCreate(ctx context.Context, d *schema.ResourceData, m int
opts = append(opts, tailscale.WithKeyExpiry(time.Duration(expiry.(int))*time.Second))
}

if hasDescription {
opts = append(opts, tailscale.WithKeyDescription(description.(string)))
}

key, err := client.CreateKey(ctx, capabilities, opts...)
if err != nil {
return diagnosticsError(err, "Failed to create key")
@@ -160,5 +171,9 @@ func resourceTailnetKeyRead(ctx context.Context, d *schema.ResourceData, m inter
return diagnosticsError(err, "Failed to set expires_at")
}

if err = d.Set("description", key.Description); err != nil {
return diagnosticsError(err, "Failed to set description")
}

return nil
}
1 change: 1 addition & 0 deletions tailscale/resource_tailnet_key_test.go
Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@ const testTailnetKey = `
preauthorized = true
tags = ["tag:server"]
expiry = 3600
description = "Example key"
}
`