mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
Merge pull request #877 from hashicorp/i-859-ignore-ec2-root-volume
providers/aws: ignore ec2 root devices
This commit is contained in:
commit
36b7f08850
@ -377,11 +377,19 @@ func resourceAwsInstanceRead(d *schema.ResourceData, meta interface{}) error {
|
|||||||
}
|
}
|
||||||
d.Set("security_groups", sgs)
|
d.Set("security_groups", sgs)
|
||||||
|
|
||||||
volIDs := make([]string, len(instance.BlockDevices))
|
blockDevices := make(map[string]ec2.BlockDevice)
|
||||||
bdByVolID := make(map[string]ec2.BlockDevice)
|
for _, bd := range instance.BlockDevices {
|
||||||
for i, bd := range instance.BlockDevices {
|
// Skip root device; AWS attaches it automatically and terraform does not
|
||||||
volIDs[i] = bd.VolumeId
|
// manage it
|
||||||
bdByVolID[bd.VolumeId] = bd
|
if bd.DeviceName == instance.RootDeviceName {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
blockDevices[bd.VolumeId] = bd
|
||||||
|
}
|
||||||
|
|
||||||
|
volIDs := make([]string, 0, len(blockDevices))
|
||||||
|
for volID := range blockDevices {
|
||||||
|
volIDs = append(volIDs, volID)
|
||||||
}
|
}
|
||||||
|
|
||||||
volResp, err := ec2conn.Volumes(volIDs, ec2.NewFilter())
|
volResp, err := ec2conn.Volumes(volIDs, ec2.NewFilter())
|
||||||
@ -396,11 +404,11 @@ func resourceAwsInstanceRead(d *schema.ResourceData, meta interface{}) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
bds[i] = make(map[string]interface{})
|
bds[i] = make(map[string]interface{})
|
||||||
bds[i]["device_name"] = bdByVolID[vol.VolumeId].DeviceName
|
bds[i]["device_name"] = blockDevices[vol.VolumeId].DeviceName
|
||||||
bds[i]["snapshot_id"] = vol.SnapshotId
|
bds[i]["snapshot_id"] = vol.SnapshotId
|
||||||
bds[i]["volume_type"] = vol.VolumeType
|
bds[i]["volume_type"] = vol.VolumeType
|
||||||
bds[i]["volume_size"] = volSize
|
bds[i]["volume_size"] = volSize
|
||||||
bds[i]["delete_on_termination"] = bdByVolID[vol.VolumeId].DeleteOnTermination
|
bds[i]["delete_on_termination"] = blockDevices[vol.VolumeId].DeleteOnTermination
|
||||||
bds[i]["encrypted"] = vol.Encrypted
|
bds[i]["encrypted"] = vol.Encrypted
|
||||||
}
|
}
|
||||||
d.Set("block_device", bds)
|
d.Set("block_device", bds)
|
||||||
|
@ -97,6 +97,11 @@ func TestAccAWSInstance_blockDevicesCheck(t *testing.T) {
|
|||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckInstanceExists(
|
testAccCheckInstanceExists(
|
||||||
"aws_instance.foo", &v),
|
"aws_instance.foo", &v),
|
||||||
|
// though two block devices exist in EC2, terraform state should only
|
||||||
|
// have the one block device we created, as terraform does not manage
|
||||||
|
// the root device
|
||||||
|
resource.TestCheckResourceAttr(
|
||||||
|
"aws_instance.foo", "block_device.#", "1"),
|
||||||
testCheck(),
|
testCheck(),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
@ -353,9 +358,9 @@ resource "aws_instance" "foo" {
|
|||||||
ami = "ami-55a7ea65"
|
ami = "ami-55a7ea65"
|
||||||
instance_type = "m1.small"
|
instance_type = "m1.small"
|
||||||
block_device {
|
block_device {
|
||||||
device_name = "/dev/sdb"
|
device_name = "/dev/sdb"
|
||||||
volume_type = "gp2"
|
volume_type = "gp2"
|
||||||
volume_size = 10
|
volume_size = 10
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
Loading…
Reference in New Issue
Block a user