Skip to content

Commit ca78d53

Browse files
authored
Support Nitro Enclaves in aws_instance and aws_launch_template (#16361)
Output from acceptance testing in AWS Commercial (failure known and unrelated): ``` --- FAIL: TestAccAWSInstance_instanceProfileChange (131.45s) --- PASS: TestAccAWSInstance_addSecondaryInterface (168.25s) --- PASS: TestAccAWSInstance_addSecurityGroupNetworkInterface (145.34s) --- PASS: TestAccAWSInstance_associatePublic_defaultPrivate (93.37s) --- PASS: TestAccAWSInstance_associatePublic_defaultPublic (193.44s) --- PASS: TestAccAWSInstance_associatePublic_explicitPrivate (90.86s) --- PASS: TestAccAWSInstance_associatePublic_explicitPublic (89.46s) --- PASS: TestAccAWSInstance_associatePublic_overridePrivate (91.19s) --- PASS: TestAccAWSInstance_associatePublic_overridePublic (81.27s) --- PASS: TestAccAWSInstance_associatePublicIPAndPrivateIP (80.40s) --- PASS: TestAccAWSInstance_atLeastOneOtherEbsVolume (192.83s) --- PASS: TestAccAWSInstance_basic (89.76s) --- PASS: TestAccAWSInstance_blockDevices (78.09s) --- PASS: TestAccAWSInstance_changeInstanceType (149.50s) --- PASS: TestAccAWSInstance_CreditSpecification_Empty_NonBurstable (322.48s) --- PASS: TestAccAWSInstance_creditSpecification_isNotAppliedToNonBurstable (95.59s) --- PASS: TestAccAWSInstance_creditSpecification_standardCpuCredits (119.17s) --- PASS: TestAccAWSInstance_creditSpecification_standardCpuCredits_t2Tot3Taint (404.66s) --- PASS: TestAccAWSInstance_creditSpecification_unknownCpuCredits_t2 (91.53s) --- PASS: TestAccAWSInstance_creditSpecification_unknownCpuCredits_t3 (313.08s) --- PASS: TestAccAWSInstance_creditSpecification_unlimitedCpuCredits (118.40s) --- PASS: TestAccAWSInstance_creditSpecification_unlimitedCpuCredits_t2Tot3Taint (395.94s) --- PASS: TestAccAWSInstance_creditSpecification_unspecifiedDefaultsToStandard (78.13s) --- PASS: TestAccAWSInstance_CreditSpecification_UnspecifiedToEmpty_NonBurstable (108.23s) --- PASS: TestAccAWSInstance_creditSpecification_updateCpuCredits (134.94s) --- PASS: TestAccAWSInstance_creditSpecificationT3_standardCpuCredits (131.22s) --- PASS: TestAccAWSInstance_creditSpecificationT3_unlimitedCpuCredits (117.74s) --- PASS: TestAccAWSInstance_creditSpecificationT3_unspecifiedDefaultsToUnlimited (309.62s) --- PASS: TestAccAWSInstance_creditSpecificationT3_updateCpuCredits (146.03s) --- PASS: TestAccAWSInstance_dedicatedInstance (106.61s) --- PASS: TestAccAWSInstance_disableApiTermination (118.10s) --- PASS: TestAccAWSInstance_disappears (92.80s) --- PASS: TestAccAWSInstance_EbsBlockDevice_InvalidIopsForVolumeType (17.27s) --- PASS: TestAccAWSInstance_EbsBlockDevice_KmsKeyArn (142.27s) --- PASS: TestAccAWSInstance_EbsRootDevice_basic (132.83s) --- PASS: TestAccAWSInstance_EbsRootDevice_ModifyAll (164.65s) --- PASS: TestAccAWSInstance_EbsRootDevice_ModifyDeleteOnTermination (97.23s) --- PASS: TestAccAWSInstance_EbsRootDevice_ModifyIOPS_Io1 (121.82s) --- PASS: TestAccAWSInstance_EbsRootDevice_ModifyIOPS_Io2 (147.63s) --- PASS: TestAccAWSInstance_EbsRootDevice_ModifySize (236.63s) --- PASS: TestAccAWSInstance_EbsRootDevice_ModifyType (123.66s) --- PASS: TestAccAWSInstance_EbsRootDevice_MultipleBlockDevices_ModifyDeleteOnTermination (199.08s) --- PASS: TestAccAWSInstance_EbsRootDevice_MultipleBlockDevices_ModifySize (123.52s) --- PASS: TestAccAWSInstance_EbsRootDevice_MultipleDynamicEBSBlockDevices (207.68s) --- PASS: TestAccAWSInstance_Empty_PrivateIP (78.02s) --- PASS: TestAccAWSInstance_enclaveOptions (430.58s) --- PASS: TestAccAWSInstance_forceNewAndTagsDrift (270.39s) --- PASS: TestAccAWSInstance_getPasswordData_falseToTrue (208.61s) --- PASS: TestAccAWSInstance_getPasswordData_trueToFalse (269.53s) --- PASS: TestAccAWSInstance_GP2IopsDevice (80.89s) --- PASS: TestAccAWSInstance_GP2WithIopsValue (11.19s) --- PASS: TestAccAWSInstance_hibernation (204.56s) --- PASS: TestAccAWSInstance_inDefaultVpcBySgId (100.86s) --- PASS: TestAccAWSInstance_inDefaultVpcBySgName (99.23s) --- PASS: TestAccAWSInstance_ipv6_supportAddressCount (99.03s) --- PASS: TestAccAWSInstance_ipv6_supportAddressCountWithIpv4 (189.48s) --- PASS: TestAccAWSInstance_ipv6AddressCountAndSingleAddressCausesError (16.71s) --- PASS: TestAccAWSInstance_keyPairCheck (86.95s) --- PASS: TestAccAWSInstance_metadataOptions (154.98s) --- PASS: TestAccAWSInstance_NetworkInstanceRemovingAllSecurityGroups (112.12s) --- PASS: TestAccAWSInstance_NetworkInstanceSecurityGroups (103.81s) --- PASS: TestAccAWSInstance_NetworkInstanceVPCSecurityGroupIDs (136.45s) --- PASS: TestAccAWSInstance_NewNetworkInterface_EmptyPrivateIPAndSecondaryPrivateIPs (341.20s) --- PASS: TestAccAWSInstance_NewNetworkInterface_EmptyPrivateIPAndSecondaryPrivateIPsUpdate (161.33s) --- PASS: TestAccAWSInstance_NewNetworkInterface_PrivateIPAndSecondaryPrivateIPs (134.73s) --- PASS: TestAccAWSInstance_NewNetworkInterface_PrivateIPAndSecondaryPrivateIPsUpdate (121.24s) --- PASS: TestAccAWSInstance_NewNetworkInterface_PublicIPAndSecondaryPrivateIPs (410.27s) --- PASS: TestAccAWSInstance_noAMIEphemeralDevices (59.54s) --- PASS: TestAccAWSInstance_placementGroup (304.38s) --- PASS: TestAccAWSInstance_primaryNetworkInterface (112.14s) --- PASS: TestAccAWSInstance_primaryNetworkInterfaceSourceDestCheck (112.05s) --- PASS: TestAccAWSInstance_privateIP (75.33s) --- PASS: TestAccAWSInstance_RootBlockDevice_KmsKeyArn (99.55s) --- PASS: TestAccAWSInstance_rootBlockDeviceMismatch (121.64s) --- PASS: TestAccAWSInstance_rootInstanceStore (149.85s) --- PASS: TestAccAWSInstance_sourceDestCheck (159.49s) --- PASS: TestAccAWSInstance_tags (104.40s) --- PASS: TestAccAWSInstance_UserData_EmptyStringToUnspecified (113.94s) --- PASS: TestAccAWSInstance_UserData_UnspecifiedToEmptyString (105.43s) --- PASS: TestAccAWSInstance_userDataBase64 (105.42s) --- PASS: TestAccAWSInstance_volumeTags (166.33s) --- PASS: TestAccAWSInstance_volumeTagsComputed (118.47s) --- PASS: TestAccAWSInstance_withIamInstanceProfile (99.55s) --- SKIP: TestAccAWSInstance_inEc2Classic (2.60s) --- SKIP: TestAccAWSInstance_outpost (1.99s) --- PASS: TestAccAWSInstanceDataSource_AzUserData (109.31s) --- PASS: TestAccAWSInstanceDataSource_basic (125.30s) --- PASS: TestAccAWSInstanceDataSource_blockDevices (97.25s) --- PASS: TestAccAWSInstanceDataSource_creditSpecification (84.91s) --- PASS: TestAccAWSInstanceDataSource_EbsBlockDevice_KmsKeyId (110.17s) --- PASS: TestAccAWSInstanceDataSource_enclaveOptions (68.12s) --- PASS: TestAccAWSInstanceDataSource_getPasswordData_falseToTrue (247.32s) --- PASS: TestAccAWSInstanceDataSource_getPasswordData_trueToFalse (255.13s) --- PASS: TestAccAWSInstanceDataSource_GetUserData (152.33s) --- PASS: TestAccAWSInstanceDataSource_GetUserData_NoUserData (182.10s) --- PASS: TestAccAWSInstanceDataSource_gp2IopsDevice (108.60s) --- PASS: TestAccAWSInstanceDataSource_keyPair (122.63s) --- PASS: TestAccAWSInstanceDataSource_metadataOptions (305.70s) --- PASS: TestAccAWSInstanceDataSource_PlacementGroup (335.92s) --- PASS: TestAccAWSInstanceDataSource_privateIP (106.49s) --- PASS: TestAccAWSInstanceDataSource_RootBlockDevice_KmsKeyId (141.35s) --- PASS: TestAccAWSInstanceDataSource_rootInstanceStore (107.10s) --- PASS: TestAccAWSInstanceDataSource_secondaryPrivateIPs (101.78s) --- PASS: TestAccAWSInstanceDataSource_SecurityGroups (114.84s) --- PASS: TestAccAWSInstanceDataSource_tags (113.19s) --- PASS: TestAccAWSInstanceDataSource_VPC (118.35s) --- PASS: TestAccAWSInstanceDataSource_VPCSecurityGroups (128.09s) --- PASS: TestAccAWSInstancesDataSource_basic (345.58s) --- PASS: TestAccAWSInstancesDataSource_instanceStateNames (91.95s) --- PASS: TestAccAWSInstancesDataSource_tags (334.64s) --- PASS: TestAccAWSLaunchTemplate_associateCarrierIPAddress (95.60s) --- PASS: TestAccAWSLaunchTemplate_associatePublicIPAddress (96.67s) --- PASS: TestAccAWSLaunchTemplate_basic (15.00s) --- PASS: TestAccAWSLaunchTemplate_BlockDeviceMappings_EBS (66.34s) --- PASS: TestAccAWSLaunchTemplate_BlockDeviceMappings_EBS_DeleteOnTermination (86.09s) --- PASS: TestAccAWSLaunchTemplate_BlockDeviceMappings_EBS_Gp3 (65.39s) --- PASS: TestAccAWSLaunchTemplate_capacityReservation_preference (30.21s) --- PASS: TestAccAWSLaunchTemplate_capacityReservation_target (31.33s) --- PASS: TestAccAWSLaunchTemplate_cpuOptions (30.11s) --- PASS: TestAccAWSLaunchTemplate_creditSpecification_nonBurstable (34.89s) --- PASS: TestAccAWSLaunchTemplate_creditSpecification_t2 (35.68s) --- PASS: TestAccAWSLaunchTemplate_creditSpecification_t3 (32.18s) --- PASS: TestAccAWSLaunchTemplate_data (21.55s) --- PASS: TestAccAWSLaunchTemplate_defaultVersion (60.20s) --- PASS: TestAccAWSLaunchTemplate_description (53.26s) --- PASS: TestAccAWSLaunchTemplate_disappears (19.56s) --- PASS: TestAccAWSLaunchTemplate_EbsOptimized (106.63s) --- PASS: TestAccAWSLaunchTemplate_ElasticInferenceAccelerator (40.95s) --- PASS: TestAccAWSLaunchTemplate_enclaveOptions (64.33s) --- PASS: TestAccAWSLaunchTemplate_hibernation (63.36s) --- PASS: TestAccAWSLaunchTemplate_IamInstanceProfile_EmptyConfigurationBlock (28.60s) --- PASS: TestAccAWSLaunchTemplate_instanceMarketOptions (84.40s) --- PASS: TestAccAWSLaunchTemplate_licenseSpecification (30.35s) --- PASS: TestAccAWSLaunchTemplate_metadataOptions (30.84s) --- PASS: TestAccAWSLaunchTemplate_networkInterface (69.40s) --- PASS: TestAccAWSLaunchTemplate_networkInterface_ipv6AddressCount (25.96s) --- PASS: TestAccAWSLaunchTemplate_networkInterface_ipv6Addresses (27.09s) --- PASS: TestAccAWSLaunchTemplate_networkInterfaceAddresses (68.27s) --- PASS: TestAccAWSLaunchTemplate_NetworkInterfaces_DeleteOnTermination (85.02s) --- PASS: TestAccAWSLaunchTemplate_placement_partitionNum (51.60s) --- PASS: TestAccAWSLaunchTemplate_tags (52.39s) --- PASS: TestAccAWSLaunchTemplate_update (78.88s) --- PASS: TestAccAWSLaunchTemplate_updateDefaultVersion (69.42s) --- PASS: TestAccAWSLaunchTemplateDataSource_associateCarrierIPAddress (63.16s) --- PASS: TestAccAWSLaunchTemplateDataSource_associatePublicIPAddress (63.57s) --- PASS: TestAccAWSLaunchTemplateDataSource_basic (27.41s) --- PASS: TestAccAWSLaunchTemplateDataSource_enclaveOptions (33.37s) --- PASS: TestAccAWSLaunchTemplateDataSource_filter_basic (28.83s) --- PASS: TestAccAWSLaunchTemplateDataSource_filter_tags (33.26s) --- PASS: TestAccAWSLaunchTemplateDataSource_id_basic (26.74s) --- PASS: TestAccAWSLaunchTemplateDataSource_metadataOptions (32.68s) --- PASS: TestAccAWSLaunchTemplateDataSource_networkInterfaces_deleteOnTermination (62.31s) --- PASS: TestAccAWSLaunchTemplateDataSource_NonExistent (8.99s) ```
1 parent 66e0572 commit ca78d53

12 files changed

Lines changed: 342 additions & 0 deletions

aws/data_source_aws_instance.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,18 @@ func dataSourceAwsInstance() *schema.Resource {
316316
Type: schema.TypeBool,
317317
Computed: true,
318318
},
319+
"enclave_options": {
320+
Type: schema.TypeList,
321+
Computed: true,
322+
Elem: &schema.Resource{
323+
Schema: map[string]*schema.Schema{
324+
"enabled": {
325+
Type: schema.TypeBool,
326+
Computed: true,
327+
},
328+
},
329+
},
330+
},
319331
},
320332
}
321333
}
@@ -535,5 +547,9 @@ func instanceDescriptionAttributes(d *schema.ResourceData, instance *ec2.Instanc
535547
return fmt.Errorf("error setting metadata_options: %s", err)
536548
}
537549

550+
if err := d.Set("enclave_options", flattenEc2EnclaveOptions(instance.EnclaveOptions)); err != nil {
551+
return fmt.Errorf("error setting enclave_options: %s", err)
552+
}
553+
538554
return nil
539555
}

aws/data_source_aws_instance_test.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,26 @@ func TestAccAWSInstanceDataSource_metadataOptions(t *testing.T) {
489489
})
490490
}
491491

492+
func TestAccAWSInstanceDataSource_enclaveOptions(t *testing.T) {
493+
resourceName := "aws_instance.test"
494+
datasourceName := "data.aws_instance.test"
495+
rName := acctest.RandomWithPrefix("tf-acc-test")
496+
497+
resource.ParallelTest(t, resource.TestCase{
498+
PreCheck: func() { testAccPreCheck(t) },
499+
Providers: testAccProviders,
500+
Steps: []resource.TestStep{
501+
{
502+
Config: testAccInstanceDataSourceConfig_enclaveOptions(rName),
503+
Check: resource.ComposeTestCheckFunc(
504+
resource.TestCheckResourceAttrPair(datasourceName, "enclave_options.#", resourceName, "enclave_options.#"),
505+
resource.TestCheckResourceAttrPair(datasourceName, "enclave_options.0.enabled", resourceName, "enclave_options.0.enabled"),
506+
),
507+
},
508+
},
509+
})
510+
}
511+
492512
// Lookup based on InstanceID
493513
var testAccInstanceDataSourceConfig = testAccLatestAmazonLinuxHvmEbsAmiConfig() + `
494514
resource "aws_instance" "test" {
@@ -920,3 +940,29 @@ data "aws_instance" "test" {
920940
}
921941
`, rName))
922942
}
943+
944+
func testAccInstanceDataSourceConfig_enclaveOptions(rName string) string {
945+
return composeConfig(
946+
testAccLatestAmazonLinuxHvmEbsAmiConfig(),
947+
testAccAwsInstanceVpcConfig(rName, false),
948+
testAccAvailableEc2InstanceTypeForRegion("c5a.xlarge", "c5.xlarge"),
949+
fmt.Sprintf(`
950+
resource "aws_instance" "test" {
951+
ami = data.aws_ami.amzn-ami-minimal-hvm-ebs.id
952+
instance_type = data.aws_ec2_instance_type_offering.available.instance_type
953+
subnet_id = aws_subnet.test.id
954+
955+
tags = {
956+
Name = %[1]q
957+
}
958+
959+
enclave_options {
960+
enabled = true
961+
}
962+
}
963+
964+
data "aws_instance" "test" {
965+
instance_id = aws_instance.test.id
966+
}
967+
`, rName))
968+
}

aws/data_source_aws_launch_template.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,18 @@ func dataSourceAwsLaunchTemplate() *schema.Resource {
231231
},
232232
},
233233
},
234+
"enclave_options": {
235+
Type: schema.TypeList,
236+
Computed: true,
237+
Elem: &schema.Resource{
238+
Schema: map[string]*schema.Schema{
239+
"enabled": {
240+
Type: schema.TypeBool,
241+
Computed: true,
242+
},
243+
},
244+
},
245+
},
234246
"monitoring": {
235247
Type: schema.TypeList,
236248
Computed: true,
@@ -515,6 +527,10 @@ func dataSourceAwsLaunchTemplateRead(d *schema.ResourceData, meta interface{}) e
515527
return fmt.Errorf("error setting metadata_options: %w", err)
516528
}
517529

530+
if err := d.Set("enclave_options", getEnclaveOptions(ltData.EnclaveOptions)); err != nil {
531+
return fmt.Errorf("error setting enclave_options: %w", err)
532+
}
533+
518534
if err := d.Set("monitoring", getMonitoring(ltData.Monitoring)); err != nil {
519535
return fmt.Errorf("error setting monitoring: %w", err)
520536
}

aws/data_source_aws_launch_template_test.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,27 @@ func TestAccAWSLaunchTemplateDataSource_metadataOptions(t *testing.T) {
149149
})
150150
}
151151

152+
func TestAccAWSLaunchTemplateDataSource_enclaveOptions(t *testing.T) {
153+
rName := acctest.RandomWithPrefix("tf-acc-test")
154+
dataSourceName := "data.aws_launch_template.test"
155+
resourceName := "aws_launch_template.test"
156+
157+
resource.ParallelTest(t, resource.TestCase{
158+
PreCheck: func() { testAccPreCheck(t) },
159+
Providers: testAccProviders,
160+
CheckDestroy: testAccCheckAWSLaunchTemplateDestroy,
161+
Steps: []resource.TestStep{
162+
{
163+
Config: testAccAWSLaunchTemplateDataSourceConfig_enclaveOptions(rName),
164+
Check: resource.ComposeTestCheckFunc(
165+
resource.TestCheckResourceAttrPair(dataSourceName, "enclave_options.#", resourceName, "enclave_options.#"),
166+
resource.TestCheckResourceAttrPair(dataSourceName, "enclave_options.0.enabled", resourceName, "enclave_options.0.enabled"),
167+
),
168+
},
169+
},
170+
})
171+
}
172+
152173
func TestAccAWSLaunchTemplateDataSource_associatePublicIPAddress(t *testing.T) {
153174
rName := acctest.RandomWithPrefix("tf-acc-test")
154175
dataSourceName := "data.aws_launch_template.test"
@@ -345,6 +366,22 @@ data "aws_launch_template" "test" {
345366
`, rName)
346367
}
347368

369+
func testAccAWSLaunchTemplateDataSourceConfig_enclaveOptions(rName string) string {
370+
return fmt.Sprintf(`
371+
resource "aws_launch_template" "test" {
372+
name = %[1]q
373+
374+
enclave_options {
375+
enabled = true
376+
}
377+
}
378+
379+
data "aws_launch_template" "test" {
380+
name = aws_launch_template.test.name
381+
}
382+
`, rName)
383+
}
384+
348385
func testAccAWSLaunchTemplateDataSourceConfig_associatePublicIpAddress(rName, associatePublicIPAddress string) string {
349386
return fmt.Sprintf(`
350387
resource "aws_launch_template" "test" {

aws/resource_aws_instance.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,23 @@ func resourceAwsInstance() *schema.Resource {
580580
},
581581
},
582582
},
583+
584+
"enclave_options": {
585+
Type: schema.TypeList,
586+
Optional: true,
587+
Computed: true,
588+
MaxItems: 1,
589+
Elem: &schema.Resource{
590+
Schema: map[string]*schema.Schema{
591+
"enabled": {
592+
Type: schema.TypeBool,
593+
Optional: true,
594+
Computed: true,
595+
ForceNew: true,
596+
},
597+
},
598+
},
599+
},
583600
},
584601
}
585602
}
@@ -629,6 +646,7 @@ func resourceAwsInstanceCreate(d *schema.ResourceData, meta interface{}) error {
629646
CpuOptions: instanceOpts.CpuOptions,
630647
HibernationOptions: instanceOpts.HibernationOptions,
631648
MetadataOptions: instanceOpts.MetadataOptions,
649+
EnclaveOptions: instanceOpts.EnclaveOptions,
632650
TagSpecifications: tagSpecifications,
633651
}
634652

@@ -784,6 +802,10 @@ func resourceAwsInstanceRead(d *schema.ResourceData, meta interface{}) error {
784802
return fmt.Errorf("error setting metadata_options: %s", err)
785803
}
786804

805+
if err := d.Set("enclave_options", flattenEc2EnclaveOptions(instance.EnclaveOptions)); err != nil {
806+
return fmt.Errorf("error setting enclave_options: %s", err)
807+
}
808+
787809
d.Set("ami", instance.ImageId)
788810
d.Set("instance_type", instance.InstanceType)
789811
d.Set("key_name", instance.KeyName)
@@ -2175,6 +2197,7 @@ type awsInstanceOpts struct {
21752197
CpuOptions *ec2.CpuOptionsRequest
21762198
HibernationOptions *ec2.HibernationOptionsRequest
21772199
MetadataOptions *ec2.InstanceMetadataOptionsRequest
2200+
EnclaveOptions *ec2.EnclaveOptionsRequest
21782201
}
21792202

21802203
func buildAwsInstanceOpts(d *schema.ResourceData, meta interface{}) (*awsInstanceOpts, error) {
@@ -2187,6 +2210,7 @@ func buildAwsInstanceOpts(d *schema.ResourceData, meta interface{}) (*awsInstanc
21872210
ImageID: aws.String(d.Get("ami").(string)),
21882211
InstanceType: aws.String(instanceType),
21892212
MetadataOptions: expandEc2InstanceMetadataOptions(d.Get("metadata_options").([]interface{})),
2213+
EnclaveOptions: expandEc2EnclaveOptions(d.Get("enclave_options").([]interface{})),
21902214
}
21912215

21922216
// Set default cpu_credits as Unlimited for T3 instance type
@@ -2490,6 +2514,20 @@ func expandEc2InstanceMetadataOptions(l []interface{}) *ec2.InstanceMetadataOpti
24902514
return opts
24912515
}
24922516

2517+
func expandEc2EnclaveOptions(l []interface{}) *ec2.EnclaveOptionsRequest {
2518+
if len(l) == 0 || l[0] == nil {
2519+
return nil
2520+
}
2521+
2522+
m := l[0].(map[string]interface{})
2523+
2524+
opts := &ec2.EnclaveOptionsRequest{
2525+
Enabled: aws.Bool(m["enabled"].(bool)),
2526+
}
2527+
2528+
return opts
2529+
}
2530+
24932531
//Expands an array of secondary Private IPs into a ec2 Private IP Address Spec
24942532
func expandSecondaryPrivateIPAddresses(ips []interface{}) []*ec2.PrivateIpAddressSpecification {
24952533
specs := make([]*ec2.PrivateIpAddressSpecification, 0, len(ips))
@@ -2517,6 +2555,18 @@ func flattenEc2InstanceMetadataOptions(opts *ec2.InstanceMetadataOptionsResponse
25172555
return []interface{}{m}
25182556
}
25192557

2558+
func flattenEc2EnclaveOptions(opts *ec2.EnclaveOptions) []interface{} {
2559+
if opts == nil {
2560+
return nil
2561+
}
2562+
2563+
m := map[string]interface{}{
2564+
"enabled": aws.BoolValue(opts.Enabled),
2565+
}
2566+
2567+
return []interface{}{m}
2568+
}
2569+
25202570
// resourceAwsInstanceFindByID returns the EC2 instance by ID
25212571
// * If the instance is found, returns the instance and nil
25222572
// * If no instance is found, returns nil and nil

aws/resource_aws_instance_test.go

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3109,6 +3109,41 @@ func TestAccAWSInstance_metadataOptions(t *testing.T) {
31093109
})
31103110
}
31113111

3112+
func TestAccAWSInstance_enclaveOptions(t *testing.T) {
3113+
var instance1, instance2 ec2.Instance
3114+
resourceName := "aws_instance.test"
3115+
3116+
resource.ParallelTest(t, resource.TestCase{
3117+
PreCheck: func() { testAccPreCheck(t) },
3118+
Providers: testAccProviders,
3119+
CheckDestroy: testAccCheckInstanceDestroy,
3120+
Steps: []resource.TestStep{
3121+
{
3122+
Config: testAccInstanceConfigEnclaveOptions(true),
3123+
Check: resource.ComposeTestCheckFunc(
3124+
testAccCheckInstanceExists(resourceName, &instance1),
3125+
resource.TestCheckResourceAttr(resourceName, "enclave_options.#", "1"),
3126+
resource.TestCheckResourceAttr(resourceName, "enclave_options.0.enabled", "true"),
3127+
),
3128+
},
3129+
{
3130+
ResourceName: resourceName,
3131+
ImportState: true,
3132+
ImportStateVerify: true,
3133+
},
3134+
{
3135+
Config: testAccInstanceConfigEnclaveOptions(false),
3136+
Check: resource.ComposeTestCheckFunc(
3137+
testAccCheckInstanceExists(resourceName, &instance2),
3138+
testAccCheckInstanceRecreated(&instance1, &instance2),
3139+
resource.TestCheckResourceAttr(resourceName, "enclave_options.#", "1"),
3140+
resource.TestCheckResourceAttr(resourceName, "enclave_options.0.enabled", "false"),
3141+
),
3142+
},
3143+
},
3144+
})
3145+
}
3146+
31123147
func testAccCheckInstanceNotRecreated(t *testing.T,
31133148
before, after *ec2.Instance) resource.TestCheckFunc {
31143149
return func(s *terraform.State) error {
@@ -5125,6 +5160,29 @@ resource "aws_instance" "test" {
51255160
`, rName))
51265161
}
51275162

5163+
func testAccInstanceConfigEnclaveOptions(enabled bool) string {
5164+
name := "tf-acc-instance-enclaves"
5165+
return composeConfig(
5166+
testAccLatestAmazonLinuxHvmEbsAmiConfig(),
5167+
testAccAwsInstanceVpcConfig(name, false),
5168+
testAccAvailableEc2InstanceTypeForRegion("c5a.xlarge", "c5.xlarge"),
5169+
fmt.Sprintf(`
5170+
resource "aws_instance" "test" {
5171+
ami = data.aws_ami.amzn-ami-minimal-hvm-ebs.id
5172+
instance_type = data.aws_ec2_instance_type_offering.available.instance_type
5173+
subnet_id = aws_subnet.test.id
5174+
5175+
enclave_options {
5176+
enabled = %[2]t
5177+
}
5178+
5179+
tags = {
5180+
Name = %[1]q
5181+
}
5182+
}
5183+
`, name, enabled))
5184+
}
5185+
51285186
func testAccAwsEc2InstanceConfigDynamicEBSBlockDevices() string {
51295187
return composeConfig(testAccLatestAmazonLinuxPvEbsAmiConfig(), `
51305188
resource "aws_instance" "test" {

0 commit comments

Comments
 (0)