-
Notifications
You must be signed in to change notification settings - Fork 9.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support Nitro Enclaves in aws_instance and aws_launch_template #16361
Changes from 5 commits
fb95a2a
1ce695b
c1024cf
4005ea7
33ec1e9
5bed2a6
3dc3967
cc2beb6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -316,6 +316,21 @@ func dataSourceAwsInstance() *schema.Resource { | |||
Type: schema.TypeBool, | ||||
Computed: true, | ||||
}, | ||||
"enclave_options": { | ||||
Type: schema.TypeList, | ||||
Optional: true, | ||||
Computed: true, | ||||
MaxItems: 1, | ||||
Elem: &schema.Resource{ | ||||
Schema: map[string]*schema.Schema{ | ||||
"enabled": { | ||||
Type: schema.TypeBool, | ||||
Optional: true, | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similarly:
Suggested change
|
||||
Computed: true, | ||||
}, | ||||
}, | ||||
}, | ||||
}, | ||||
}, | ||||
} | ||||
} | ||||
|
@@ -535,5 +550,9 @@ func instanceDescriptionAttributes(d *schema.ResourceData, instance *ec2.Instanc | |||
return fmt.Errorf("error setting metadata_options: %s", err) | ||||
} | ||||
|
||||
if err := d.Set("enclave_options", flattenEc2EnclaveOptions(instance.EnclaveOptions)); err != nil { | ||||
return fmt.Errorf("error setting enclave_options: %s", err) | ||||
} | ||||
|
||||
return nil | ||||
} |
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -576,6 +576,22 @@ func resourceAwsInstance() *schema.Resource { | |||||||
}, | ||||||||
}, | ||||||||
}, | ||||||||
|
||||||||
"enclave_options": { | ||||||||
Type: schema.TypeList, | ||||||||
Optional: true, | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To be safe and prevent unexpected differences for operators should the EC2 API return this information with existing configurations not having it, let's add
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I also switched the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The top level |
||||||||
MaxItems: 1, | ||||||||
Elem: &schema.Resource{ | ||||||||
Schema: map[string]*schema.Schema{ | ||||||||
"enabled": { | ||||||||
Type: schema.TypeBool, | ||||||||
Default: false, | ||||||||
Optional: true, | ||||||||
ForceNew: true, | ||||||||
}, | ||||||||
}, | ||||||||
}, | ||||||||
}, | ||||||||
}, | ||||||||
} | ||||||||
} | ||||||||
|
@@ -625,6 +641,7 @@ func resourceAwsInstanceCreate(d *schema.ResourceData, meta interface{}) error { | |||||||
CpuOptions: instanceOpts.CpuOptions, | ||||||||
HibernationOptions: instanceOpts.HibernationOptions, | ||||||||
MetadataOptions: instanceOpts.MetadataOptions, | ||||||||
EnclaveOptions: instanceOpts.EnclaveOptions, | ||||||||
TagSpecifications: tagSpecifications, | ||||||||
} | ||||||||
|
||||||||
|
@@ -780,6 +797,10 @@ func resourceAwsInstanceRead(d *schema.ResourceData, meta interface{}) error { | |||||||
return fmt.Errorf("error setting metadata_options: %s", err) | ||||||||
} | ||||||||
|
||||||||
if err := d.Set("enclave_options", flattenEc2EnclaveOptions(instance.EnclaveOptions)); err != nil { | ||||||||
return fmt.Errorf("error setting enclave_options: %s", err) | ||||||||
} | ||||||||
|
||||||||
d.Set("ami", instance.ImageId) | ||||||||
d.Set("instance_type", instance.InstanceType) | ||||||||
d.Set("key_name", instance.KeyName) | ||||||||
|
@@ -2150,6 +2171,7 @@ type awsInstanceOpts struct { | |||||||
CpuOptions *ec2.CpuOptionsRequest | ||||||||
HibernationOptions *ec2.HibernationOptionsRequest | ||||||||
MetadataOptions *ec2.InstanceMetadataOptionsRequest | ||||||||
EnclaveOptions *ec2.EnclaveOptionsRequest | ||||||||
} | ||||||||
|
||||||||
func buildAwsInstanceOpts(d *schema.ResourceData, meta interface{}) (*awsInstanceOpts, error) { | ||||||||
|
@@ -2162,6 +2184,7 @@ func buildAwsInstanceOpts(d *schema.ResourceData, meta interface{}) (*awsInstanc | |||||||
ImageID: aws.String(d.Get("ami").(string)), | ||||||||
InstanceType: aws.String(instanceType), | ||||||||
MetadataOptions: expandEc2InstanceMetadataOptions(d.Get("metadata_options").([]interface{})), | ||||||||
EnclaveOptions: expandEc2EnclaveOptions(d.Get("enclave_options").([]interface{})), | ||||||||
} | ||||||||
|
||||||||
// Set default cpu_credits as Unlimited for T3 instance type | ||||||||
|
@@ -2465,6 +2488,20 @@ func expandEc2InstanceMetadataOptions(l []interface{}) *ec2.InstanceMetadataOpti | |||||||
return opts | ||||||||
} | ||||||||
|
||||||||
func expandEc2EnclaveOptions(l []interface{}) *ec2.EnclaveOptionsRequest { | ||||||||
if len(l) == 0 || l[0] == nil { | ||||||||
return nil | ||||||||
} | ||||||||
|
||||||||
m := l[0].(map[string]interface{}) | ||||||||
|
||||||||
opts := &ec2.EnclaveOptionsRequest{ | ||||||||
Enabled: aws.Bool(m["enabled"].(bool)), | ||||||||
} | ||||||||
|
||||||||
return opts | ||||||||
} | ||||||||
|
||||||||
//Expands an array of secondary Private IPs into a ec2 Private IP Address Spec | ||||||||
func expandSecondaryPrivateIPAddresses(ips []interface{}) []*ec2.PrivateIpAddressSpecification { | ||||||||
specs := make([]*ec2.PrivateIpAddressSpecification, 0, len(ips)) | ||||||||
|
@@ -2492,6 +2529,18 @@ func flattenEc2InstanceMetadataOptions(opts *ec2.InstanceMetadataOptionsResponse | |||||||
return []interface{}{m} | ||||||||
} | ||||||||
|
||||||||
func flattenEc2EnclaveOptions(opts *ec2.EnclaveOptions) []interface{} { | ||||||||
if opts == nil { | ||||||||
return nil | ||||||||
} | ||||||||
|
||||||||
m := map[string]interface{}{ | ||||||||
"enabled": aws.BoolValue(opts.Enabled), | ||||||||
} | ||||||||
|
||||||||
return []interface{}{m} | ||||||||
} | ||||||||
|
||||||||
// resourceAwsInstanceFindByID returns the EC2 instance by ID | ||||||||
// * If the instance is found, returns the instance and nil | ||||||||
// * If no instance is found, returns nil and nil | ||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -3110,6 +3110,41 @@ func TestAccAWSInstance_metadataOptions(t *testing.T) { | |||||||||
}) | ||||||||||
} | ||||||||||
|
||||||||||
func TestAccAWSInstance_enclaveOptions(t *testing.T) { | ||||||||||
var instance1, instance2 ec2.Instance | ||||||||||
resourceName := "aws_instance.test" | ||||||||||
|
||||||||||
resource.ParallelTest(t, resource.TestCase{ | ||||||||||
PreCheck: func() { testAccPreCheck(t) }, | ||||||||||
Providers: testAccProviders, | ||||||||||
CheckDestroy: testAccCheckInstanceDestroy, | ||||||||||
Steps: []resource.TestStep{ | ||||||||||
{ | ||||||||||
Config: testAccInstanceConfigEnclaveOptions(true), | ||||||||||
Check: resource.ComposeTestCheckFunc( | ||||||||||
testAccCheckInstanceExists(resourceName, &instance1), | ||||||||||
resource.TestCheckResourceAttr(resourceName, "enclave_options.#", "1"), | ||||||||||
resource.TestCheckResourceAttr(resourceName, "enclave_options.0.enabled", "true"), | ||||||||||
), | ||||||||||
}, | ||||||||||
{ | ||||||||||
ResourceName: resourceName, | ||||||||||
ImportState: true, | ||||||||||
ImportStateVerify: true, | ||||||||||
}, | ||||||||||
{ | ||||||||||
Config: testAccInstanceConfigEnclaveOptions(false), | ||||||||||
Check: resource.ComposeTestCheckFunc( | ||||||||||
testAccCheckInstanceExists(resourceName, &instance2), | ||||||||||
testAccCheckInstanceRecreated(&instance1, &instance2), | ||||||||||
resource.TestCheckResourceAttr(resourceName, "enclave_options.#", "1"), | ||||||||||
resource.TestCheckResourceAttr(resourceName, "enclave_options.0.enabled", "false"), | ||||||||||
), | ||||||||||
}, | ||||||||||
}, | ||||||||||
}) | ||||||||||
} | ||||||||||
|
||||||||||
func testAccCheckInstanceNotRecreated(t *testing.T, | ||||||||||
before, after *ec2.Instance) resource.TestCheckFunc { | ||||||||||
return func(s *terraform.State) error { | ||||||||||
|
@@ -5102,6 +5137,33 @@ resource "aws_instance" "test" { | |||||||||
`, rName)) | ||||||||||
} | ||||||||||
|
||||||||||
func testAccInstanceConfigEnclaveOptions(enabled bool) string { | ||||||||||
name := "tf-acc-instance-enclaves" | ||||||||||
return composeConfig( | ||||||||||
testAccLatestAmazonLinuxHvmEbsAmiConfig(), | ||||||||||
testAccAwsInstanceVpcConfig(name, false), | ||||||||||
testAccAvailableEc2InstanceTypeForRegion("c5a.xlarge", "c5.xlarge"), | ||||||||||
fmt.Sprintf(` | ||||||||||
resource "aws_instance" "test" { | ||||||||||
ami = data.aws_ami.amzn-ami-minimal-hvm-ebs.id | ||||||||||
instance_type = data.aws_ec2_instance_type_offering.available.instance_type | ||||||||||
subnet_id = aws_subnet.test.id | ||||||||||
|
||||||||||
enclave_options { | ||||||||||
enabled = %[2]t | ||||||||||
} | ||||||||||
|
||||||||||
tags = { | ||||||||||
Name = %[1]q | ||||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
data "aws_instance" "test" { | ||||||||||
instance_id = aws_instance.test.id | ||||||||||
} | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Resource testing should omit data source 👍
Suggested change
|
||||||||||
`, name, enabled)) | ||||||||||
} | ||||||||||
|
||||||||||
func testAccAwsEc2InstanceConfigDynamicEBSBlockDevices() string { | ||||||||||
return composeConfig(testAccLatestAmazonLinuxPvEbsAmiConfig(), ` | ||||||||||
resource "aws_instance" "test" { | ||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this schema attribute cannot be used to filter the lookup as an argument,
Optional
should be removed. 👍