@@ -45,7 +45,7 @@ func TestAccAWSInstance_basic(t *testing.T) {
45
45
CheckDestroy : testAccCheckInstanceDestroy ,
46
46
Steps : []resource.TestStep {
47
47
// Create a volume to cover #1249
48
- resource. TestStep {
48
+ {
49
49
// Need a resource in this config so the provisioner will be available
50
50
Config : testAccInstanceConfig_pre ,
51
51
Check : func (* terraform.State ) error {
@@ -59,7 +59,7 @@ func TestAccAWSInstance_basic(t *testing.T) {
59
59
},
60
60
},
61
61
62
- resource. TestStep {
62
+ {
63
63
Config : testAccInstanceConfig ,
64
64
Check : resource .ComposeTestCheckFunc (
65
65
testAccCheckInstanceExists (
@@ -77,7 +77,7 @@ func TestAccAWSInstance_basic(t *testing.T) {
77
77
// We repeat the exact same test so that we can be sure
78
78
// that the user data hash stuff is working without generating
79
79
// an incorrect diff.
80
- resource. TestStep {
80
+ {
81
81
Config : testAccInstanceConfig ,
82
82
Check : resource .ComposeTestCheckFunc (
83
83
testAccCheckInstanceExists (
@@ -93,7 +93,7 @@ func TestAccAWSInstance_basic(t *testing.T) {
93
93
},
94
94
95
95
// Clean up volume created above
96
- resource. TestStep {
96
+ {
97
97
Config : testAccInstanceConfig ,
98
98
Check : func (* terraform.State ) error {
99
99
conn := testAccProvider .Meta ().(* AWSClient ).ec2conn
@@ -134,7 +134,7 @@ func TestAccAWSInstance_GP2IopsDevice(t *testing.T) {
134
134
Providers : testAccProviders ,
135
135
CheckDestroy : testAccCheckInstanceDestroy ,
136
136
Steps : []resource.TestStep {
137
- resource. TestStep {
137
+ {
138
138
Config : testAccInstanceGP2IopsDevice ,
139
139
//Config: testAccInstanceConfigBlockDevices,
140
140
Check : resource .ComposeTestCheckFunc (
@@ -199,7 +199,7 @@ func TestAccAWSInstance_blockDevices(t *testing.T) {
199
199
Providers : testAccProviders ,
200
200
CheckDestroy : testAccCheckInstanceDestroy ,
201
201
Steps : []resource.TestStep {
202
- resource. TestStep {
202
+ {
203
203
Config : testAccInstanceConfigBlockDevices ,
204
204
Check : resource .ComposeTestCheckFunc (
205
205
testAccCheckInstanceExists (
@@ -254,7 +254,7 @@ func TestAccAWSInstance_rootInstanceStore(t *testing.T) {
254
254
Providers : testAccProviders ,
255
255
CheckDestroy : testAccCheckInstanceDestroy ,
256
256
Steps : []resource.TestStep {
257
- resource. TestStep {
257
+ {
258
258
Config : `
259
259
resource "aws_instance" "foo" {
260
260
# us-west-2
@@ -323,7 +323,7 @@ func TestAcctABSInstance_noAMIEphemeralDevices(t *testing.T) {
323
323
Providers : testAccProviders ,
324
324
CheckDestroy : testAccCheckInstanceDestroy ,
325
325
Steps : []resource.TestStep {
326
- resource. TestStep {
326
+ {
327
327
Config : `
328
328
resource "aws_instance" "foo" {
329
329
# us-west-2
@@ -400,23 +400,23 @@ func TestAccAWSInstance_sourceDestCheck(t *testing.T) {
400
400
Providers : testAccProviders ,
401
401
CheckDestroy : testAccCheckInstanceDestroy ,
402
402
Steps : []resource.TestStep {
403
- resource. TestStep {
403
+ {
404
404
Config : testAccInstanceConfigSourceDestDisable ,
405
405
Check : resource .ComposeTestCheckFunc (
406
406
testAccCheckInstanceExists ("aws_instance.foo" , & v ),
407
407
testCheck (false ),
408
408
),
409
409
},
410
410
411
- resource. TestStep {
411
+ {
412
412
Config : testAccInstanceConfigSourceDestEnable ,
413
413
Check : resource .ComposeTestCheckFunc (
414
414
testAccCheckInstanceExists ("aws_instance.foo" , & v ),
415
415
testCheck (true ),
416
416
),
417
417
},
418
418
419
- resource. TestStep {
419
+ {
420
420
Config : testAccInstanceConfigSourceDestDisable ,
421
421
Check : resource .ComposeTestCheckFunc (
422
422
testAccCheckInstanceExists ("aws_instance.foo" , & v ),
@@ -454,15 +454,15 @@ func TestAccAWSInstance_disableApiTermination(t *testing.T) {
454
454
Providers : testAccProviders ,
455
455
CheckDestroy : testAccCheckInstanceDestroy ,
456
456
Steps : []resource.TestStep {
457
- resource. TestStep {
457
+ {
458
458
Config : testAccInstanceConfigDisableAPITermination (true ),
459
459
Check : resource .ComposeTestCheckFunc (
460
460
testAccCheckInstanceExists ("aws_instance.foo" , & v ),
461
461
checkDisableApiTermination (true ),
462
462
),
463
463
},
464
464
465
- resource. TestStep {
465
+ {
466
466
Config : testAccInstanceConfigDisableAPITermination (false ),
467
467
Check : resource .ComposeTestCheckFunc (
468
468
testAccCheckInstanceExists ("aws_instance.foo" , & v ),
@@ -483,7 +483,7 @@ func TestAccAWSInstance_vpc(t *testing.T) {
483
483
Providers : testAccProviders ,
484
484
CheckDestroy : testAccCheckInstanceDestroy ,
485
485
Steps : []resource.TestStep {
486
- resource. TestStep {
486
+ {
487
487
Config : testAccInstanceConfigVPC ,
488
488
Check : resource .ComposeTestCheckFunc (
489
489
testAccCheckInstanceExists (
@@ -517,7 +517,7 @@ func TestAccAWSInstance_multipleRegions(t *testing.T) {
517
517
ProviderFactories : providerFactories ,
518
518
CheckDestroy : testAccCheckInstanceDestroyWithProviders (& providers ),
519
519
Steps : []resource.TestStep {
520
- resource. TestStep {
520
+ {
521
521
Config : testAccInstanceConfigMultipleRegions ,
522
522
Check : resource .ComposeTestCheckFunc (
523
523
testAccCheckInstanceExistsWithProviders (
@@ -540,7 +540,7 @@ func TestAccAWSInstance_NetworkInstanceSecurityGroups(t *testing.T) {
540
540
Providers : testAccProviders ,
541
541
CheckDestroy : testAccCheckInstanceDestroy ,
542
542
Steps : []resource.TestStep {
543
- resource. TestStep {
543
+ {
544
544
Config : testAccInstanceNetworkInstanceSecurityGroups ,
545
545
Check : resource .ComposeTestCheckFunc (
546
546
testAccCheckInstanceExists (
@@ -560,7 +560,7 @@ func TestAccAWSInstance_NetworkInstanceVPCSecurityGroupIDs(t *testing.T) {
560
560
Providers : testAccProviders ,
561
561
CheckDestroy : testAccCheckInstanceDestroy ,
562
562
Steps : []resource.TestStep {
563
- resource. TestStep {
563
+ {
564
564
Config : testAccInstanceNetworkInstanceVPCSecurityGroupIDs ,
565
565
Check : resource .ComposeTestCheckFunc (
566
566
testAccCheckInstanceExists (
@@ -583,7 +583,7 @@ func TestAccAWSInstance_tags(t *testing.T) {
583
583
Providers : testAccProviders ,
584
584
CheckDestroy : testAccCheckInstanceDestroy ,
585
585
Steps : []resource.TestStep {
586
- resource. TestStep {
586
+ {
587
587
Config : testAccCheckInstanceConfigTags ,
588
588
Check : resource .ComposeTestCheckFunc (
589
589
testAccCheckInstanceExists ("aws_instance.foo" , & v ),
@@ -593,7 +593,7 @@ func TestAccAWSInstance_tags(t *testing.T) {
593
593
),
594
594
},
595
595
596
- resource. TestStep {
596
+ {
597
597
Config : testAccCheckInstanceConfigTagsUpdate ,
598
598
Check : resource .ComposeTestCheckFunc (
599
599
testAccCheckInstanceExists ("aws_instance.foo" , & v ),
@@ -624,7 +624,7 @@ func TestAccAWSInstance_privateIP(t *testing.T) {
624
624
Providers : testAccProviders ,
625
625
CheckDestroy : testAccCheckInstanceDestroy ,
626
626
Steps : []resource.TestStep {
627
- resource. TestStep {
627
+ {
628
628
Config : testAccInstanceConfigPrivateIP ,
629
629
Check : resource .ComposeTestCheckFunc (
630
630
testAccCheckInstanceExists ("aws_instance.foo" , & v ),
@@ -655,7 +655,7 @@ func TestAccAWSInstance_associatePublicIPAndPrivateIP(t *testing.T) {
655
655
Providers : testAccProviders ,
656
656
CheckDestroy : testAccCheckInstanceDestroy ,
657
657
Steps : []resource.TestStep {
658
- resource. TestStep {
658
+ {
659
659
Config : testAccInstanceConfigAssociatePublicIPAndPrivateIP ,
660
660
Check : resource .ComposeTestCheckFunc (
661
661
testAccCheckInstanceExists ("aws_instance.foo" , & v ),
@@ -691,7 +691,7 @@ func TestAccAWSInstance_keyPairCheck(t *testing.T) {
691
691
Providers : testAccProviders ,
692
692
CheckDestroy : testAccCheckInstanceDestroy ,
693
693
Steps : []resource.TestStep {
694
- resource. TestStep {
694
+ {
695
695
Config : testAccInstanceConfigKeyPair ,
696
696
Check : resource .ComposeTestCheckFunc (
697
697
testAccCheckInstanceExists ("aws_instance.foo" , & v ),
@@ -710,7 +710,7 @@ func TestAccAWSInstance_rootBlockDeviceMismatch(t *testing.T) {
710
710
Providers : testAccProviders ,
711
711
CheckDestroy : testAccCheckInstanceDestroy ,
712
712
Steps : []resource.TestStep {
713
- resource. TestStep {
713
+ {
714
714
Config : testAccInstanceConfigRootBlockDeviceMismatch ,
715
715
Check : resource .ComposeTestCheckFunc (
716
716
testAccCheckInstanceExists ("aws_instance.foo" , & v ),
@@ -740,15 +740,15 @@ func TestAccAWSInstance_forceNewAndTagsDrift(t *testing.T) {
740
740
Providers : testAccProviders ,
741
741
CheckDestroy : testAccCheckInstanceDestroy ,
742
742
Steps : []resource.TestStep {
743
- resource. TestStep {
743
+ {
744
744
Config : testAccInstanceConfigForceNewAndTagsDrift ,
745
745
Check : resource .ComposeTestCheckFunc (
746
746
testAccCheckInstanceExists ("aws_instance.foo" , & v ),
747
747
driftTags (& v ),
748
748
),
749
749
ExpectNonEmptyPlan : true ,
750
750
},
751
- resource. TestStep {
751
+ {
752
752
Config : testAccInstanceConfigForceNewAndTagsDrift_Update ,
753
753
Check : resource .ComposeTestCheckFunc (
754
754
testAccCheckInstanceExists ("aws_instance.foo" , & v ),
@@ -758,6 +758,43 @@ func TestAccAWSInstance_forceNewAndTagsDrift(t *testing.T) {
758
758
})
759
759
}
760
760
761
+ func TestAccAWSInstance_changeInstanceType (t * testing.T ) {
762
+ var before ec2.Instance
763
+ var after ec2.Instance
764
+
765
+ resource .Test (t , resource.TestCase {
766
+ PreCheck : func () { testAccPreCheck (t ) },
767
+ Providers : testAccProviders ,
768
+ CheckDestroy : testAccCheckInstanceDestroy ,
769
+ Steps : []resource.TestStep {
770
+ {
771
+ Config : testAccInstanceConfigWithSmallInstanceType ,
772
+ Check : resource .ComposeTestCheckFunc (
773
+ testAccCheckInstanceExists ("aws_instance.foo" , & before ),
774
+ ),
775
+ },
776
+ {
777
+ Config : testAccInstanceConfigUpdateInstanceType ,
778
+ Check : resource .ComposeTestCheckFunc (
779
+ testAccCheckInstanceExists ("aws_instance.foo" , & after ),
780
+ testAccCheckInstanceNotRecreated (
781
+ t , & before , & after ),
782
+ ),
783
+ },
784
+ },
785
+ })
786
+ }
787
+
788
+ func testAccCheckInstanceNotRecreated (t * testing.T ,
789
+ before , after * ec2.Instance ) resource.TestCheckFunc {
790
+ return func (s * terraform.State ) error {
791
+ if * before .InstanceId != * after .InstanceId {
792
+ t .Fatalf ("AWS Instance IDs have changed. Before %s. After %s" , * before .InstanceId , * after .InstanceId )
793
+ }
794
+ return nil
795
+ }
796
+ }
797
+
761
798
func testAccCheckInstanceDestroy (s * terraform.State ) error {
762
799
return testAccCheckInstanceDestroyWithProvider (s , testAccProvider )
763
800
}
@@ -873,7 +910,7 @@ func driftTags(instance *ec2.Instance) resource.TestCheckFunc {
873
910
_ , err := conn .CreateTags (& ec2.CreateTagsInput {
874
911
Resources : []* string {instance .InstanceId },
875
912
Tags : []* ec2.Tag {
876
- & ec2. Tag {
913
+ {
877
914
Key : aws .String ("Drift" ),
878
915
Value : aws .String ("Happens" ),
879
916
},
@@ -921,6 +958,34 @@ resource "aws_instance" "foo" {
921
958
}
922
959
`
923
960
961
+ const testAccInstanceConfigWithSmallInstanceType = `
962
+ resource "aws_instance" "foo" {
963
+ # us-west-2
964
+ ami = "ami-55a7ea65"
965
+ availability_zone = "us-west-2a"
966
+
967
+ instance_type = "m3.medium"
968
+
969
+ tags {
970
+ Name = "tf-acctest"
971
+ }
972
+ }
973
+ `
974
+
975
+ const testAccInstanceConfigUpdateInstanceType = `
976
+ resource "aws_instance" "foo" {
977
+ # us-west-2
978
+ ami = "ami-55a7ea65"
979
+ availability_zone = "us-west-2a"
980
+
981
+ instance_type = "m3.large"
982
+
983
+ tags {
984
+ Name = "tf-acctest"
985
+ }
986
+ }
987
+ `
988
+
924
989
const testAccInstanceGP2IopsDevice = `
925
990
resource "aws_instance" "foo" {
926
991
# us-west-2
0 commit comments