Skip to content

Commit 8b2932c

Browse files
authored
resource_tailscale_tailnet_key: prevent recreate when expiry is undefined (#521)
Fixes #520 Signed-off-by: mcoulombe <[email protected]>
1 parent 06f8f32 commit 8b2932c

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

tailscale/resource_tailnet_key.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ func resourceTailnetKey() *schema.Resource {
6363
"expiry": {
6464
Type: schema.TypeInt,
6565
Optional: true,
66+
Computed: true,
6667
Description: "The expiry of the key in seconds. Defaults to `7776000` (90 days).",
6768
ForceNew: true,
6869
},

tailscale/resource_tailnet_key_test.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,6 @@ func TestAccTailscaleTailnetKey(t *testing.T) {
182182
ephemeral = true
183183
preauthorized = true
184184
tags = ["tag:a"]
185-
expiry = 3600
186185
description = "Test key"
187186
}`
188187

@@ -231,7 +230,7 @@ func TestAccTailscaleTailnetKey(t *testing.T) {
231230
var expectedKey tailscale.Key
232231
expectedKey.KeyType = "auth"
233232
expectedKey.Description = "Test key"
234-
expectedKey.ExpirySeconds = toPtr(time.Duration(3600))
233+
expectedKey.ExpirySeconds = toPtr(time.Duration(7776000))
235234
expectedKey.Capabilities.Devices.Create.Reusable = true
236235
expectedKey.Capabilities.Devices.Create.Ephemeral = true
237236
expectedKey.Capabilities.Devices.Create.Preauthorized = true
@@ -268,16 +267,21 @@ func TestAccTailscaleTailnetKey(t *testing.T) {
268267
Config: testTailnetKeyCreate,
269268
Check: resource.ComposeTestCheckFunc(
270269
checkResourceRemoteProperties(resourceName,
271-
checkProperties(&expectedKey, 3600),
270+
checkProperties(&expectedKey, 7776000),
272271
),
273272
resource.TestCheckResourceAttr(resourceName, "reusable", "true"),
274273
resource.TestCheckResourceAttr(resourceName, "ephemeral", "true"),
275274
resource.TestCheckResourceAttr(resourceName, "preauthorized", "true"),
276275
resource.TestCheckTypeSetElemAttr(resourceName, "tags.*", "tag:a"),
277-
resource.TestCheckResourceAttr(resourceName, "expiry", "3600"),
276+
resource.TestCheckResourceAttr(resourceName, "expiry", "7776000"),
278277
resource.TestCheckResourceAttr(resourceName, "description", "Test key"),
279278
),
280279
},
280+
{
281+
Config: testTailnetKeyCreate,
282+
PlanOnly: true,
283+
ExpectNonEmptyPlan: false,
284+
},
281285
{
282286
Config: testTailnetKeyUpdate,
283287
Check: resource.ComposeTestCheckFunc(

0 commit comments

Comments
 (0)