Skip to content
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

Added support for the encryption flag on ebs_block_devices in launch configurations #4481

Merged
merged 2 commits into from
Jan 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions builtin/providers/aws/resource_aws_launch_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,13 @@ func resourceAwsLaunchConfiguration() *schema.Resource {
Computed: true,
ForceNew: true,
},

"encrypted": &schema.Schema{
Type: schema.TypeBool,
Optional: true,
Computed: true,
ForceNew: true,
},
},
},
Set: func(v interface{}) int {
Expand Down Expand Up @@ -326,6 +333,7 @@ func resourceAwsLaunchConfigurationCreate(d *schema.ResourceData, meta interface
bd := v.(map[string]interface{})
ebs := &autoscaling.Ebs{
DeleteOnTermination: aws.Bool(bd["delete_on_termination"].(bool)),
Encrypted: aws.Bool(bd["encrypted"].(bool)),
}

if v, ok := bd["snapshot_id"].(string); ok && v != "" {
Expand Down Expand Up @@ -570,6 +578,9 @@ func readBlockDevicesFromLaunchConfiguration(d *schema.ResourceData, lc *autosca
if bdm.Ebs != nil && bdm.Ebs.Iops != nil {
bd["iops"] = *bdm.Ebs.Iops
}
if bdm.Ebs != nil && bdm.Ebs.Encrypted != nil {
bd["encrypted"] = *bdm.Ebs.Encrypted
}
if bdm.DeviceName != nil && *bdm.DeviceName == *rootDeviceName {
blockDevices["root"] = bd
} else {
Expand Down
64 changes: 64 additions & 0 deletions builtin/providers/aws/resource_aws_launch_configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,52 @@ func TestAccAWSLaunchConfiguration_withSpotPrice(t *testing.T) {
})
}

func testAccCheckAWSLaunchConfigurationWithEncryption(conf *autoscaling.LaunchConfiguration) resource.TestCheckFunc {
return func(s *terraform.State) error {
// Map out the block devices by name, which should be unique.
blockDevices := make(map[string]*autoscaling.BlockDeviceMapping)
for _, blockDevice := range conf.BlockDeviceMappings {
blockDevices[*blockDevice.DeviceName] = blockDevice
}

// Check if the root block device exists.
if _, ok := blockDevices["/dev/sda1"]; !ok {
return fmt.Errorf("block device doesn't exist: /dev/sda1")
} else if blockDevices["/dev/sda1"].Ebs.Encrypted != nil {
return fmt.Errorf("root device should not include value for Encrypted")
}

// Check if the secondary block device exists.
if _, ok := blockDevices["/dev/sdb"]; !ok {
return fmt.Errorf("block device doesn't exist: /dev/sdb")
} else if !*blockDevices["/dev/sdb"].Ebs.Encrypted {
return fmt.Errorf("block device isn't encrypted as expected: /dev/sdb")
}

return nil
}
}

func TestAccAWSLaunchConfiguration_withEncryption(t *testing.T) {
var conf autoscaling.LaunchConfiguration

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSLaunchConfigurationDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccAWSLaunchConfigurationWithEncryption,
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSLaunchConfigurationExists("aws_launch_configuration.baz", &conf),

testAccCheckAWSLaunchConfigurationWithEncryption(&conf),
),
},
},
})
}

func testAccCheckAWSLaunchConfigurationGeneratedNamePrefix(
resource, prefix string) resource.TestCheckFunc {
return func(s *terraform.State) error {
Expand Down Expand Up @@ -273,3 +319,21 @@ resource "aws_launch_configuration" "baz" {
associate_public_ip_address = false
}
`

const testAccAWSLaunchConfigurationWithEncryption = `
resource "aws_launch_configuration" "baz" {
image_id = "ami-5189a661"
instance_type = "t2.micro"
associate_public_ip_address = false

root_block_device {
volume_type = "gp2"
volume_size = 11
}
ebs_block_device {
device_name = "/dev/sdb"
volume_size = 9
encrypted = true
}
}
`
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ Each `ebs_block_device` supports the following:
This must be set with a `volume_type` of `"io1"`.
* `delete_on_termination` - (Optional) Whether the volume should be destroyed
on instance termination (Default: `true`).
* `encryption` - (Optional) Whether the volume should be encrypted or not. Do not use this option if you are using `snapshot_id` as the encryption flag will be determined by the snapshot. (Default: `false`).

Modifying any `ebs_block_device` currently requires resource replacement.

Expand Down