@@ -2,7 +2,6 @@ package diceroll
2
2
3
3
import (
4
4
"fmt"
5
- "math/rand"
6
5
7
6
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
8
7
)
@@ -14,6 +13,10 @@ func resourceDiceRoll() *schema.Resource {
14
13
Update : schema .Noop ,
15
14
Delete : schema .RemoveFromState ,
16
15
Schema : map [string ]* schema.Schema {
16
+ "seed" : & schema.Schema {
17
+ Type : schema .TypeString ,
18
+ Optional : true ,
19
+ },
17
20
"dice" : & schema.Schema {
18
21
Type : schema .TypeList ,
19
22
Required : true ,
@@ -51,11 +54,6 @@ func resourceDiceRoll() *schema.Resource {
51
54
Type : schema .TypeString ,
52
55
},
53
56
},
54
- "seed" : {
55
- Type : schema .TypeString ,
56
- Optional : true ,
57
- ForceNew : true ,
58
- },
59
57
"quantity" : & schema.Schema {
60
58
Type : schema .TypeInt ,
61
59
Required : true ,
@@ -68,17 +66,20 @@ func resourceDiceRoll() *schema.Resource {
68
66
}
69
67
70
68
func resourceDiceRollCreate (d * schema.ResourceData , m interface {}) error {
71
- d .SetId (fmt .Sprintf ("%x" , rand .Int ()))
72
- return resourceDiceRollRead (d , m )
73
- }
74
-
75
- func resourceDiceRollRead (d * schema.ResourceData , m interface {}) error {
76
69
//dice := d.Get("dice").([]interface{})
70
+ quantity := d .Get ("quantity" ).(int )
71
+ seed := d .Get ("seed" ).(string )
72
+ rand := NewRand (seed )
73
+ result := make ([]interface {}, 0 , quantity )
77
74
78
75
//for _, die := range dice {
79
76
// dc := die.(map[string]interface{})
77
+ // dv := dc["die"].([]interface{})[0]
78
+
80
79
//}
81
- return nil
80
+ d .SetId (fmt .Sprintf ("%x" , rand .Int ()))
81
+ d .Set ("result" , result )
82
+ return resourceDiceRollRead (d , m )
82
83
}
83
84
84
85
func resourceDiceRollRead (d * schema.ResourceData , m interface {}) error {
0 commit comments