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 key expiration to tailscale_tailnet_key #175

Merged
merged 4 commits into from
Nov 3, 2022
Merged
Show file tree
Hide file tree
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
Expand Up @@ -17,6 +17,7 @@ resource "tailscale_tailnet_key" "sample_key" {
reusable = true
ephemeral = false
preauthorized = true
expiry = 3600
}
```

Expand All @@ -26,6 +27,7 @@ resource "tailscale_tailnet_key" "sample_key" {
### Optional

- `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.
- `reusable` (Boolean) Indicates if the key is reusable or single-use.
- `tags` (Set of String) List of tags to apply to the machines authenticated by the key.
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 @@ -2,4 +2,5 @@ resource "tailscale_tailnet_key" "sample_key" {
reusable = true
ephemeral = false
preauthorized = true
expiry = 3600
}
8 changes: 8 additions & 0 deletions tailscale/resource_tailnet_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ func resourceTailnetKey() *schema.Resource {
Computed: true,
Sensitive: true,
},
"expiry": {
Type: schema.TypeInt,
Optional: true,
Description: "The expiry of the key in seconds",
ForceNew: true,
},
},
}
}
Expand All @@ -58,6 +64,7 @@ func resourceTailnetKeyCreate(ctx context.Context, d *schema.ResourceData, m int
reusable := d.Get("reusable").(bool)
ephemeral := d.Get("ephemeral").(bool)
preauthorized := d.Get("preauthorized").(bool)
expiry := d.Get("expiry").(int)
var tags []string
for _, tag := range d.Get("tags").(*schema.Set).List() {
tags = append(tags, tag.(string))
Expand All @@ -68,6 +75,7 @@ func resourceTailnetKeyCreate(ctx context.Context, d *schema.ResourceData, m int
capabilities.Devices.Create.Ephemeral = ephemeral
capabilities.Devices.Create.Tags = tags
capabilities.Devices.Create.Preauthorized = preauthorized
capabilities.Devices.Create.Expiry = expiry

key, err := client.CreateKey(ctx, capabilities)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions tailscale/resource_tailnet_key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const testTailnetKey = `
ephemeral = true
preauthorized = true
tags = ["tag:server"]
expiry = 3600
}
`

Expand Down