Terraform-provider-aws: aws_instance - root_block_device is not expected here.

Created on 4 Jun 2019  ·  5Comments  ·  Source: hashicorp/terraform-provider-aws

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Terraform Version

$ terraform --version
Terraform v0.12.0
+ provider.aws v2.13.0
+ provider.template v2.1.2

Affected Resource(s)

  • aws_instance

Terraform Configuration Files

Bastion

resource "aws_instance" "bastion" {
  ami           = "${var.AMI_ID}"
  instance_type = "${var.EC2_INSTANCE_SIZE}"

  root_block_device = [{
    volume_size           = "${var.EC2_ROOT_VOLUME_SIZE}"
    volume_type           = "${var.EC2_ROOT_VOLUME_TYPE}"
    delete_on_termination = "${var.EC2_ROOT_VOLUME_DELETE_ON_TERMINATION}"
  }]

}
variable "AMI_ID" {
  type    = "string"
  description = "AMI ID for the instance"
}
variable "EC2_INSTANCE_SIZE" {
  type    = "string"
  default = "t2.micro"
  description = "The EC2 instance size"
}
variable "EC2_ROOT_VOLUME_SIZE" {
  type    = "string"
  default = "30"
  description = "The volume size for the root volume in GiB"
}
variable "EC2_ROOT_VOLUME_TYPE" {
  type    = "string"
  default = "gp2"
  description = "The type of data storage: standard, gp2, io1"
}
variable "EC2_ROOT_VOLUME_DELETE_ON_TERMINATION" {
  default = true
  description = "Delete the root volume on instance termination."
}

Debug Output

https://gist.github.com/jpSimkins/23eb0cd578e53903e5fd6fca113f3c57

Expected Behavior

I expected this to create a bastion instance with a root device that I specified

Actual Behavior

Received an error:

An argument named "root_block_device" is not expected here. Did you mean to
define a block of type "root_block_device"?

Pretty much telling me that root_block_device is not expected. I doubt the docs are wrong so this seems to be a bug.

Steps to Reproduce

With a simple aws_instance resource using root_block_device run:

  1. terraform plan
  2. Read error
  3. Cry

NOTE: when omitting root_block_device works as expected

Most helpful comment

@jpSimkins I believe you have the root_block_device defined as a map attribute as opposed to a nested configuration block. I believe changing your syntax to the following should solve the issue in Terraform v0.12.0

resource "aws_instance" "bastion" {
  ami           = "${var.AMI_ID}"
  instance_type = "${var.EC2_INSTANCE_SIZE}"

  root_block_device {
    volume_size           = "${var.EC2_ROOT_VOLUME_SIZE}"
    volume_type           = "${var.EC2_ROOT_VOLUME_TYPE}"
    delete_on_termination = "${var.EC2_ROOT_VOLUME_DELETE_ON_TERMINATION}"
  }
}

All 5 comments

This also affects terraform-aws-modules/autoscaling/aws. I assume due to using aws_instance internally.

Error: Unsupported argument

  on .terraform/modules/webserver_asg/terraform-aws-modules-terraform-aws-autoscaling-c5355e1/main.tf line 21, in resource "aws_launch_configuration" "this":
  21:   root_block_device           = "${var.root_block_device}"

An argument named "root_block_device" is not expected here. Did you mean to
define a block of type "root_block_device"?

This is actually a critical issue IMHO, I am now having to bypass Terraform to complete a project. This is breaking. If I had time to look into why this was happening I would but unfortunately, I have to pass this to the community

`Error: Unsupported argument

on .terraform/modules/instance/main.tf line 13, in resource "aws_instance" "this":
13: root_block_device = "${var.root_block}"

An argument named "root_block_device" is not expected here. Did you mean to
define a block of type "root_block_device"?

Error: Unsupported argument

on .terraform/modules/instance/main.tf line 14, in resource "aws_instance" "this":
14: ebs_block_device = "${var.ebs_block}"

An argument named "ebs_block_device" is not expected here. Did you mean to
define a block of type "ebs_block_device"?

Releasing state lock. This may take a few moments...
make: * [apply] Error 1
`
**ebs_block_device
and root_block_device error :(

@jpSimkins I believe you have the root_block_device defined as a map attribute as opposed to a nested configuration block. I believe changing your syntax to the following should solve the issue in Terraform v0.12.0

resource "aws_instance" "bastion" {
  ami           = "${var.AMI_ID}"
  instance_type = "${var.EC2_INSTANCE_SIZE}"

  root_block_device {
    volume_size           = "${var.EC2_ROOT_VOLUME_SIZE}"
    volume_type           = "${var.EC2_ROOT_VOLUME_TYPE}"
    delete_on_termination = "${var.EC2_ROOT_VOLUME_DELETE_ON_TERMINATION}"
  }
}

@jmgreg31 Thank you! Yes, that was my issue. I am still having a similar issue with https://github.com/terraform-aws-modules/terraform-aws-autoscaling/issues/67 but I will close this ticket out and follow that ticket.

I thought I already tried that but I clearly didn't...

Thank you!

I'm going to lock this issue because it has been closed for _30 days_ ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

Was this page helpful?
0 / 5 - 0 ratings