@@ -63,7 +63,6 @@ func resourceAwsInstance() *schema.Resource {
63
63
"instance_type" : {
64
64
Type : schema .TypeString ,
65
65
Required : true ,
66
- ForceNew : true ,
67
66
},
68
67
69
68
"key_name" : {
@@ -606,6 +605,60 @@ func resourceAwsInstanceUpdate(d *schema.ResourceData, meta interface{}) error {
606
605
}
607
606
}
608
607
608
+ if d .HasChange ("instance_type" ) && ! d .IsNewResource () {
609
+ log .Printf ("[INFO] Stopping Instance %q for instance_type change" , d .Id ())
610
+ _ , err := conn .StopInstances (& ec2.StopInstancesInput {
611
+ InstanceIds : []* string {aws .String (d .Id ())},
612
+ })
613
+
614
+ stateConf := & resource.StateChangeConf {
615
+ Pending : []string {"pending" , "running" , "shutting-down" , "stopped" , "stopping" },
616
+ Target : []string {"stopped" },
617
+ Refresh : InstanceStateRefreshFunc (conn , d .Id ()),
618
+ Timeout : 10 * time .Minute ,
619
+ Delay : 10 * time .Second ,
620
+ MinTimeout : 3 * time .Second ,
621
+ }
622
+
623
+ _ , err = stateConf .WaitForState ()
624
+ if err != nil {
625
+ return fmt .Errorf (
626
+ "Error waiting for instance (%s) to stop: %s" , d .Id (), err )
627
+ }
628
+
629
+ log .Printf ("[INFO] Modifying instance type %s" , d .Id ())
630
+ _ , err = conn .ModifyInstanceAttribute (& ec2.ModifyInstanceAttributeInput {
631
+ InstanceId : aws .String (d .Id ()),
632
+ InstanceType : & ec2.AttributeValue {
633
+ Value : aws .String (d .Get ("instance_type" ).(string )),
634
+ },
635
+ })
636
+ if err != nil {
637
+ return err
638
+ }
639
+
640
+ log .Printf ("[INFO] Starting Instance %q after instance_type change" , d .Id ())
641
+ _ , err = conn .StartInstances (& ec2.StartInstancesInput {
642
+ InstanceIds : []* string {aws .String (d .Id ())},
643
+ })
644
+
645
+ stateConf = & resource.StateChangeConf {
646
+ Pending : []string {"pending" , "stopped" },
647
+ Target : []string {"running" },
648
+ Refresh : InstanceStateRefreshFunc (conn , d .Id ()),
649
+ Timeout : 10 * time .Minute ,
650
+ Delay : 10 * time .Second ,
651
+ MinTimeout : 3 * time .Second ,
652
+ }
653
+
654
+ _ , err = stateConf .WaitForState ()
655
+ if err != nil {
656
+ return fmt .Errorf (
657
+ "Error waiting for instance (%s) to become ready: %s" ,
658
+ d .Id (), err )
659
+ }
660
+ }
661
+
609
662
if d .HasChange ("disable_api_termination" ) {
610
663
_ , err := conn .ModifyInstanceAttribute (& ec2.ModifyInstanceAttributeInput {
611
664
InstanceId : aws .String (d .Id ()),
0 commit comments