Skip to content

Commit

Permalink
Add key expiration to tailscale_tailnet_key (#175)
Browse files Browse the repository at this point in the history
* add key expiration parameter

* remove doc edits

* generate docs; terraform fmt
  • Loading branch information
dizzzan authored Nov 3, 2022
1 parent 5e5246c commit a14869b
Show file tree
Hide file tree
Showing 4 changed files with 12 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 @@ -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

0 comments on commit a14869b

Please sign in to comment.