@@ -3,7 +3,6 @@ package iterative
3
3
import (
4
4
"context"
5
5
"fmt"
6
- "strconv"
7
6
8
7
"terraform-provider-iterative/iterative/aws"
9
8
"terraform-provider-iterative/iterative/azure"
@@ -19,13 +18,18 @@ func resourceMachine() *schema.Resource {
19
18
CreateContext : resourceMachineCreate ,
20
19
DeleteContext : resourceMachineDelete ,
21
20
ReadContext : resourceMachineRead ,
22
- UpdateContext : resourceMachineUpdate ,
23
21
Schema : * machineSchema (),
24
22
}
25
23
}
26
24
27
25
func machineSchema () * map [string ]* schema.Schema {
28
26
return & map [string ]* schema.Schema {
27
+ "name" : & schema.Schema {
28
+ Type : schema .TypeString ,
29
+ ForceNew : true ,
30
+ Optional : true ,
31
+ Default : "" ,
32
+ },
29
33
"cloud" : & schema.Schema {
30
34
Type : schema .TypeString ,
31
35
ForceNew : true ,
@@ -34,81 +38,74 @@ func machineSchema() *map[string]*schema.Schema {
34
38
},
35
39
"region" : & schema.Schema {
36
40
Type : schema .TypeString ,
37
- Optional : true ,
38
41
ForceNew : true ,
42
+ Optional : true ,
39
43
Default : "us-west" ,
40
44
},
41
45
"image" : & schema.Schema {
42
46
Type : schema .TypeString ,
43
- Optional : true ,
44
47
ForceNew : true ,
45
- Default : "" ,
46
- },
47
- "instance_name" : & schema.Schema {
48
- Type : schema .TypeString ,
49
48
Optional : true ,
50
- ForceNew : true ,
51
49
Default : "" ,
52
50
},
53
51
"instance_type" : & schema.Schema {
54
52
Type : schema .TypeString ,
55
- Optional : true ,
56
53
ForceNew : true ,
54
+ Optional : true ,
57
55
Default : "m" ,
58
56
},
59
57
"instance_hdd_size" : & schema.Schema {
60
58
Type : schema .TypeInt ,
61
- Optional : true ,
62
59
ForceNew : true ,
60
+ Optional : true ,
63
61
Default : 35 ,
64
62
},
65
63
"instance_gpu" : & schema.Schema {
66
64
Type : schema .TypeString ,
67
- Optional : true ,
68
65
ForceNew : true ,
66
+ Optional : true ,
69
67
Default : "" ,
70
68
},
71
69
"instance_id" : & schema.Schema {
72
70
Type : schema .TypeString ,
73
- Optional : true ,
74
71
Computed : true ,
75
72
},
76
73
"instance_ip" : & schema.Schema {
77
74
Type : schema .TypeString ,
78
- Optional : true ,
79
75
Computed : true ,
80
76
},
81
77
"instance_launch_time" : & schema.Schema {
82
78
Type : schema .TypeString ,
83
- Optional : true ,
84
79
Computed : true ,
85
80
},
86
81
"ssh_public" : & schema.Schema {
87
82
Type : schema .TypeString ,
88
- Optional : true ,
89
83
ForceNew : true ,
84
+ Optional : true ,
90
85
Default : "" ,
91
86
},
92
87
"ssh_private" : & schema.Schema {
93
88
Type : schema .TypeString ,
89
+ ForceNew : true ,
94
90
Optional : true ,
95
- Computed : true ,
91
+ Default : "" ,
96
92
},
97
93
"ssh_name" : & schema.Schema {
98
94
Type : schema .TypeString ,
99
- Optional : true ,
100
95
ForceNew : true ,
96
+ Optional : true ,
101
97
Default : "ubuntu" ,
102
98
},
103
99
"custom_data" : & schema.Schema {
104
100
Type : schema .TypeString ,
105
101
ForceNew : true ,
106
- Computed : true ,
102
+ Optional : true ,
103
+ Default : "#!/bin/bash" ,
107
104
},
108
105
"aws_security_group" : & schema.Schema {
109
106
Type : schema .TypeString ,
110
- Optional : true ,
111
107
ForceNew : true ,
108
+ Optional : true ,
112
109
Default : "" ,
113
110
},
114
111
}
@@ -117,50 +114,22 @@ func machineSchema() *map[string]*schema.Schema {
117
114
func resourceMachineCreate (ctx context.Context , d * schema.ResourceData , m interface {}) diag.Diagnostics {
118
115
var diags diag.Diagnostics
119
116
120
- maprefix := utils .MachinePrefix (d )
121
- hasMachine := len (maprefix ) > 0
122
-
123
- keyPublic := d .Get (maprefix + "ssh_public" ).(string )
117
+ keyPublic := d .Get ("ssh_public" ).(string )
124
118
if len (keyPublic ) == 0 {
125
119
public , private , _ := utils .SSHKeyPair ()
126
120
127
- d .Set (maprefix + "ssh_public" , public )
128
- d .Set (maprefix + "ssh_private" , private )
121
+ d .Set ("ssh_public" , public )
122
+ d .Set ("ssh_private" , private )
129
123
}
130
124
131
- sid , _ := shortid .New (1 , shortid .DefaultABC , 2342 )
132
- id , _ := sid .Generate ()
133
- name := "iterative-" + id
134
- if hasMachine {
135
-
136
- d .Set ("name" , name )
137
- d .Set (maprefix + "instance_name" , name )
138
-
139
- } else {
140
- instanceName := d .Get ("instance_name" ).(string )
141
- if len (instanceName ) == 0 {
142
- d .Set ("instance_name" , name )
143
- }
125
+ name := d .Get ("name" ).(string )
126
+ if len (name ) == 0 {
127
+ sid , _ := shortid .New (1 , shortid .DefaultABC , 2342 )
128
+ id , _ := sid .Generate ()
129
+ d .Set ("name" , "iterative-" + id )
144
130
}
145
131
146
- diags = append (diags , diag.Diagnostic {
147
- Severity : diag .Error ,
148
- Summary : fmt .Sprintf ("mapfrefix: %v" , maprefix ),
149
- })
150
-
151
- diags = append (diags , diag.Diagnostic {
152
- Severity : diag .Error ,
153
- Summary : strconv .FormatBool (hasMachine ),
154
- })
155
-
156
- diags = append (diags , diag.Diagnostic {
157
- Severity : diag .Error ,
158
- Summary : d .Get (maprefix + "custom_data" ).(string ),
159
- })
160
-
161
- return diags
162
-
163
- cloud := d .Get (maprefix + "cloud" ).(string )
132
+ cloud := d .Get ("cloud" ).(string )
164
133
if cloud == "aws" {
165
134
err := aws .ResourceMachineCreate (ctx , d , m )
166
135
if err != nil {
@@ -191,9 +160,7 @@ func resourceMachineCreate(ctx context.Context, d *schema.ResourceData, m interf
191
160
func resourceMachineDelete (ctx context.Context , d * schema.ResourceData , m interface {}) diag.Diagnostics {
192
161
var diags diag.Diagnostics
193
162
194
- maprefix := utils .MachinePrefix (d )
195
-
196
- cloud := d .Get (maprefix + "cloud" ).(string )
163
+ cloud := d .Get ("cloud" ).(string )
197
164
if cloud == "aws" {
198
165
err := aws .ResourceMachineDelete (ctx , d , m )
199
166
if err != nil {
@@ -218,7 +185,3 @@ func resourceMachineDelete(ctx context.Context, d *schema.ResourceData, m interf
218
185
func resourceMachineRead (ctx context.Context , d * schema.ResourceData , m interface {}) diag.Diagnostics {
219
186
return nil
220
187
}
221
-
222
- func resourceMachineUpdate (ctx context.Context , d * schema.ResourceData , m interface {}) diag.Diagnostics {
223
- return nil
224
- }
0 commit comments