In the Terraform script to create an AWS EC2 instance, we can specify the volume sizes. Separate arguments describe the root and data volumes. This feature enables the script to create the volumes without specifying the connection attributes in another block.
The Terraform documentation does not show the syntax, and the Terraform example at the time of writing this in GitHub is NOT correct at https://github.com/terraform-aws-modules/terraform-aws-ec2-instance/blob/528613d4580f2c1266e87d8d24fc25bf5290fe2c/examples/complete/main.tf#L113
If the syntax is not correct get the error message:
An argument named “root_block_device” is not expected here. Did you mean to define a block of type “root_block_device”?
An argument named “ebs_block_device” is not expected here. Did you mean to define a block of type “ebs_block_device”?
The correct syntax is
resource "aws_instance" "default" {
ami = "ami-0da7a37366e7ee5f0"
instance_type = "t3.medium"
...
root_block_device {
volume_type = "gp2"
volume_size = 100
tags = {
Name = "my-root-block"
}
}
ebs_block_device {
device_name = "xvdf"
delete_on_termination = true
volume_type = "gp2"
volume_size = 500
}
...
}