@@ -23,14 +23,14 @@ func ResourceInstance() *schema.Resource {
23
23
"region" : {
24
24
Type : schema .TypeString ,
25
25
Optional : true ,
26
+ ForceNew : true ,
26
27
Description : "The region for the instance, if not declare we use the region in declared in the provider" ,
27
28
},
28
29
"hostname" : {
29
30
Type : schema .TypeString ,
30
31
Optional : true ,
31
32
Computed : true ,
32
33
Description : "A fully qualified domain name that should be set as the instance's hostname" ,
33
- ForceNew : true ,
34
34
ValidateFunc : utils .ValidateNameSize ,
35
35
},
36
36
"reverse_dns" : {
@@ -55,6 +55,7 @@ func ResourceInstance() *schema.Resource {
55
55
Type : schema .TypeString ,
56
56
Optional : true ,
57
57
Computed : true ,
58
+ ForceNew : true ,
58
59
Description : "This must be the ID of the network from the network listing (optional; default network used when not specified)" ,
59
60
},
60
61
"template" : {
@@ -363,7 +364,7 @@ func resourceInstanceRead(_ context.Context, d *schema.ResourceData, m interface
363
364
d .Set ("initial_password" , resp .InitialPassword )
364
365
d .Set ("source_type" , resp .SourceType )
365
366
d .Set ("source_id" , resp .SourceID )
366
- d .Set ("sshkey_id" , resp .SSHKey )
367
+ d .Set ("sshkey_id" , resp .SSHKeyID )
367
368
d .Set ("tags" , resp .Tags )
368
369
d .Set ("private_ip" , resp .PrivateIP )
369
370
d .Set ("public_ip" , resp .PublicIP )
@@ -429,25 +430,32 @@ func resourceInstanceUpdate(ctx context.Context, d *schema.ResourceData, m inter
429
430
}
430
431
}
431
432
432
- // if has note we add to the instance
433
- if d .HasChange ("notes" ) {
433
+ // if notes or hostname have changed, add them to the instance
434
+ if d .HasChange ("notes" ) || d . HasChange ( "hostname" ) {
434
435
notes := d .Get ("notes" ).(string )
436
+ hostname := d .Get ("hostname" ).(string )
437
+
435
438
instance , err := apiClient .GetInstance (d .Id ())
436
439
if err != nil {
437
440
// check if the instance no longer exists.
438
441
return diag .Errorf ("[ERR] instance %s not found" , d .Id ())
439
442
}
440
443
441
- instance .Notes = notes
444
+ if d .HasChange ("notes" ) {
445
+ instance .Notes = notes
446
+ }
447
+ if d .HasChange ("hostname" ) {
448
+ instance .Hostname = hostname
449
+ }
442
450
443
- log .Printf ("[INFO] adding notes to the instance %s" , d .Id ())
451
+ log .Printf ("[INFO] updating instance %s" , d .Id ())
444
452
_ , err = apiClient .UpdateInstance (instance )
445
453
if err != nil {
446
- return diag .Errorf ("[ERR] an error occurred while adding a note to the instance %s" , d .Id ())
454
+ return diag .Errorf ("[ERR] an error occurred while updating notes or hostname of the instance %s" , d .Id ())
447
455
}
448
456
}
449
457
450
- // if a firewall is declare we update the instance
458
+ // if a firewall is declared we update the instance
451
459
if d .HasChange ("firewall_id" ) {
452
460
firewallID := d .Get ("firewall_id" ).(string )
453
461
@@ -459,6 +467,14 @@ func resourceInstanceUpdate(ctx context.Context, d *schema.ResourceData, m inter
459
467
}
460
468
}
461
469
470
+ if d .HasChange ("initial_user" ) {
471
+ return diag .Errorf ("[ERR] updating initial_user is not supported" )
472
+ }
473
+
474
+ if d .HasChange ("sshkey_id" ) {
475
+ return diag .Errorf ("[ERR] updating sshkey_id is not supported" )
476
+ }
477
+
462
478
// if tags is declare we update the instance with the tags
463
479
if d .HasChange ("tags" ) {
464
480
tfTags := d .Get ("tags" ).(* schema.Set ).List ()
0 commit comments