Skip to content

Commit 25fa2f0

Browse files
committed
Ensure sides for die is at least 1
1 parent 4e53b7c commit 25fa2f0

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ HOSTNAME=hashicorp.com
33
NAMESPACE=briancain
44
NAME=diceroll
55
BINARY=terraform-provider-${NAME}
6-
VERSION=0.1.1
6+
VERSION=0.1.2
77
OS_ARCH=darwin_amd64
88

99
default: install

example/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ terraform {
22
required_providers {
33
diceroll = {
44
source = "briancain/diceroll"
5-
version = "0.1.1"
5+
version = "0.1.2"
66
}
77
}
88
}

internal/provider/resource_diceroll.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55

66
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
7+
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
78
)
89

910
func resourceDiceRoll() *schema.Resource {
@@ -24,10 +25,11 @@ func resourceDiceRoll() *schema.Resource {
2425
Default: 1,
2526
},
2627
"sides": {
27-
Type: schema.TypeInt,
28-
Optional: true,
29-
Default: 20,
30-
ForceNew: true,
28+
Type: schema.TypeInt,
29+
Optional: true,
30+
Default: 6,
31+
ValidateFunc: validation.IntAtLeast(1),
32+
ForceNew: true,
3133
},
3234
"result": {
3335
Type: schema.TypeList,
@@ -48,7 +50,7 @@ func resourceDiceRollCreate(d *schema.ResourceData, m interface{}) error {
4850
result := make([]int, quantity)
4951

5052
for i := 0; i < quantity; i++ {
51-
r := rand.Intn(sides - 1) + 1 // Dice don't have a 0
53+
r := rand.Intn(sides-1) + 1 // Dice don't have a 0
5254
result[i] = r
5355
}
5456

0 commit comments

Comments
 (0)