@@ -3,7 +3,6 @@ package iterative
33import (
44 "context"
55 "fmt"
6- "strconv"
76
87 "terraform-provider-iterative/iterative/aws"
98 "terraform-provider-iterative/iterative/azure"
@@ -19,13 +18,18 @@ func resourceMachine() *schema.Resource {
1918 CreateContext : resourceMachineCreate ,
2019 DeleteContext : resourceMachineDelete ,
2120 ReadContext : resourceMachineRead ,
22- UpdateContext : resourceMachineUpdate ,
2321 Schema : * machineSchema (),
2422 }
2523}
2624
2725func machineSchema () * map [string ]* schema.Schema {
2826 return & map [string ]* schema.Schema {
27+ "name" : & schema.Schema {
28+ Type : schema .TypeString ,
29+ ForceNew : true ,
30+ Optional : true ,
31+ Default : "" ,
32+ },
2933 "cloud" : & schema.Schema {
3034 Type : schema .TypeString ,
3135 ForceNew : true ,
@@ -34,81 +38,74 @@ func machineSchema() *map[string]*schema.Schema {
3438 },
3539 "region" : & schema.Schema {
3640 Type : schema .TypeString ,
37- Optional : true ,
3841 ForceNew : true ,
42+ Optional : true ,
3943 Default : "us-west" ,
4044 },
4145 "image" : & schema.Schema {
4246 Type : schema .TypeString ,
43- Optional : true ,
4447 ForceNew : true ,
45- Default : "" ,
46- },
47- "instance_name" : & schema.Schema {
48- Type : schema .TypeString ,
4948 Optional : true ,
50- ForceNew : true ,
5149 Default : "" ,
5250 },
5351 "instance_type" : & schema.Schema {
5452 Type : schema .TypeString ,
55- Optional : true ,
5653 ForceNew : true ,
54+ Optional : true ,
5755 Default : "m" ,
5856 },
5957 "instance_hdd_size" : & schema.Schema {
6058 Type : schema .TypeInt ,
61- Optional : true ,
6259 ForceNew : true ,
60+ Optional : true ,
6361 Default : 35 ,
6462 },
6563 "instance_gpu" : & schema.Schema {
6664 Type : schema .TypeString ,
67- Optional : true ,
6865 ForceNew : true ,
66+ Optional : true ,
6967 Default : "" ,
7068 },
7169 "instance_id" : & schema.Schema {
7270 Type : schema .TypeString ,
73- Optional : true ,
7471 Computed : true ,
7572 },
7673 "instance_ip" : & schema.Schema {
7774 Type : schema .TypeString ,
78- Optional : true ,
7975 Computed : true ,
8076 },
8177 "instance_launch_time" : & schema.Schema {
8278 Type : schema .TypeString ,
83- Optional : true ,
8479 Computed : true ,
8580 },
8681 "ssh_public" : & schema.Schema {
8782 Type : schema .TypeString ,
88- Optional : true ,
8983 ForceNew : true ,
84+ Optional : true ,
9085 Default : "" ,
9186 },
9287 "ssh_private" : & schema.Schema {
9388 Type : schema .TypeString ,
89+ ForceNew : true ,
9490 Optional : true ,
95- Computed : true ,
91+ Default : "" ,
9692 },
9793 "ssh_name" : & schema.Schema {
9894 Type : schema .TypeString ,
99- Optional : true ,
10095 ForceNew : true ,
96+ Optional : true ,
10197 Default : "ubuntu" ,
10298 },
10399 "custom_data" : & schema.Schema {
104100 Type : schema .TypeString ,
105101 ForceNew : true ,
106- Computed : true ,
102+ Optional : true ,
103+ Default : "#!/bin/bash" ,
107104 },
108105 "aws_security_group" : & schema.Schema {
109106 Type : schema .TypeString ,
110- Optional : true ,
111107 ForceNew : true ,
108+ Optional : true ,
112109 Default : "" ,
113110 },
114111 }
@@ -117,50 +114,22 @@ func machineSchema() *map[string]*schema.Schema {
117114func resourceMachineCreate (ctx context.Context , d * schema.ResourceData , m interface {}) diag.Diagnostics {
118115 var diags diag.Diagnostics
119116
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 )
124118 if len (keyPublic ) == 0 {
125119 public , private , _ := utils .SSHKeyPair ()
126120
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 )
129123 }
130124
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 )
144130 }
145131
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 )
164133 if cloud == "aws" {
165134 err := aws .ResourceMachineCreate (ctx , d , m )
166135 if err != nil {
@@ -191,9 +160,7 @@ func resourceMachineCreate(ctx context.Context, d *schema.ResourceData, m interf
191160func resourceMachineDelete (ctx context.Context , d * schema.ResourceData , m interface {}) diag.Diagnostics {
192161 var diags diag.Diagnostics
193162
194- maprefix := utils .MachinePrefix (d )
195-
196- cloud := d .Get (maprefix + "cloud" ).(string )
163+ cloud := d .Get ("cloud" ).(string )
197164 if cloud == "aws" {
198165 err := aws .ResourceMachineDelete (ctx , d , m )
199166 if err != nil {
@@ -218,7 +185,3 @@ func resourceMachineDelete(ctx context.Context, d *schema.ResourceData, m interf
218185func resourceMachineRead (ctx context.Context , d * schema.ResourceData , m interface {}) diag.Diagnostics {
219186 return nil
220187}
221-
222- func resourceMachineUpdate (ctx context.Context , d * schema.ResourceData , m interface {}) diag.Diagnostics {
223- return nil
224- }
0 commit comments