Skip to content

Commit

Permalink
Add tailscale tailnet key Description and update docs (#277)
Browse files Browse the repository at this point in the history
* Add tailscale tailnet key Description and update docs

Signed-off-by: Julian Orchard <[email protected]>
  • Loading branch information
julianorchard authored Aug 30, 2023
1 parent 5bab75b commit be95b7a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/resources/tailnet_key.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ resource "tailscale_tailnet_key" "sample_key" {
ephemeral = false
preauthorized = true
expiry = 3600
description = "Sample key"
}
```

Expand All @@ -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.
Expand Down
1 change: 1 addition & 0 deletions examples/resources/tailscale_tailnet_key/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Up @@ -66,6 +66,12 @@ func resourceTailnetKey() *schema.Resource {
Description: "The expiry timestamp of the key in RFC3339 format",
Computed: true,
},
"description": {
Type: schema.TypeString,
Optional: true,
Description: "A description of the key consisting of alphanumeric characters.",
ForceNew: true,
},
},
}
}
Expand All @@ -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))
Expand All @@ -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")
Expand Down Expand Up @@ -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
Expand Up @@ -16,6 +16,7 @@ const testTailnetKey = `
preauthorized = true
tags = ["tag:server"]
expiry = 3600
description = "Example key"
}
`

Expand Down

0 comments on commit be95b7a

Please sign in to comment.