Terraform Error : Can’t access attributes on a primitive-typed value (number)

I am getting Error in terraform execution with “Can’t access attributes on a primitive-typed value (number).”

Here are the details .

Getting Error on ebs_block_mapping variables , I have requirement to add the ebs volumes with different size & type so i have included with mappings .

However ebs_block_mapping variable doesn’t get substituted properly.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>main.tf
### EC2 Instance creation
resource "aws_instance" "instance" {
ami = var.ami_id
subnet_id = var.subnet_id
instance_type = var.instance_type
key_name = var.key_pair
iam_instance_profile = var.iam_instance_profile
vpc_security_group_ids = var.security_group_id
root_block_device {
volume_type = var.root_volume_type
volume_size = var.root_volume_size
delete_on_termination = var.delete_on_termination
encrypted = "true"
tags = {
"Name" = "${var.instance_name}-root"
}
}
dynamic "ebs_block_device" {
for_each = [for s in var.ebs_device_mappings != null ? [0] : [] : {
name = s.name
size = s.size
type = s.type
}]
content {
device_name = ebs_block_device.value["name"]
volume_size = ebs_block_device.value["size"]
volume_type = ebs_block_device.value["type"]
delete_on_termination = true
encrypted = true
tags = {
"Name" = "${var.instance_name}-ebs"
}
}
}
}
</code>
<code>main.tf ### EC2 Instance creation resource "aws_instance" "instance" { ami = var.ami_id subnet_id = var.subnet_id instance_type = var.instance_type key_name = var.key_pair iam_instance_profile = var.iam_instance_profile vpc_security_group_ids = var.security_group_id root_block_device { volume_type = var.root_volume_type volume_size = var.root_volume_size delete_on_termination = var.delete_on_termination encrypted = "true" tags = { "Name" = "${var.instance_name}-root" } } dynamic "ebs_block_device" { for_each = [for s in var.ebs_device_mappings != null ? [0] : [] : { name = s.name size = s.size type = s.type }] content { device_name = ebs_block_device.value["name"] volume_size = ebs_block_device.value["size"] volume_type = ebs_block_device.value["type"] delete_on_termination = true encrypted = true tags = { "Name" = "${var.instance_name}-ebs" } } } } </code>
main.tf

### EC2 Instance creation
resource "aws_instance" "instance" {
  ami                    = var.ami_id
  subnet_id              = var.subnet_id
  instance_type          = var.instance_type
  key_name               = var.key_pair
  iam_instance_profile   = var.iam_instance_profile
  vpc_security_group_ids = var.security_group_id
  root_block_device {
    volume_type           = var.root_volume_type
    volume_size           = var.root_volume_size
    delete_on_termination = var.delete_on_termination
    encrypted             = "true"
    tags = {
      "Name" = "${var.instance_name}-root"
    }
  }
  dynamic "ebs_block_device" {
    for_each = [for s in var.ebs_device_mappings != null ? [0] : [] : {
      name = s.name
      size = s.size
      type = s.type
    }]
    content {
      device_name           = ebs_block_device.value["name"]
      volume_size           = ebs_block_device.value["size"]
      volume_type           = ebs_block_device.value["type"]
      delete_on_termination = true
      encrypted             = true
      tags = {
        "Name" = "${var.instance_name}-ebs"
      }
    }
  }
}
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>test.tfvars
instance_type = "t2.xlarge"
ami_id = "ami-05de6de"
ebs_device_mappings = [{ name = "/dev/sdd", size = 50, type = "gp3" }]
security_group_id = ["sg-xxxxxxxxxxx"]
root_volume_type = "gp3"
root_volume_size = "60"
delete_on_termination = "true"
subnet_id = "subnet-xxxxxxxxxxxx"
iam_instance_profile = "test-role"
instance_name = "test"
</code>
<code>test.tfvars instance_type = "t2.xlarge" ami_id = "ami-05de6de" ebs_device_mappings = [{ name = "/dev/sdd", size = 50, type = "gp3" }] security_group_id = ["sg-xxxxxxxxxxx"] root_volume_type = "gp3" root_volume_size = "60" delete_on_termination = "true" subnet_id = "subnet-xxxxxxxxxxxx" iam_instance_profile = "test-role" instance_name = "test" </code>
test.tfvars

instance_type         = "t2.xlarge"
ami_id                = "ami-05de6de"
ebs_device_mappings   = [{ name = "/dev/sdd", size = 50, type = "gp3" }]
security_group_id     = ["sg-xxxxxxxxxxx"]
root_volume_type      = "gp3"
root_volume_size      = "60"
delete_on_termination = "true"
subnet_id             = "subnet-xxxxxxxxxxxx"
iam_instance_profile  = "test-role"
instance_name         = "test"
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>variables.tf
variable "instance_name" {
description = "Name tag for EC2 instance"
}
variable "ami_id" {
description = "AMI ID for EC2 instance"
}
variable "subnet_id" {
description = "Subnet ID for EC2 instance"
}
variable "instance_type" {
description = "Instance type for EC2 instance"
}
variable "key_pair" {
description = "Key pair name for EC2 instance"
default = null
}
variable "iam_instance_profile" {
description = "IAM Instance Profile to launch the instance with"
}
variable "security_group_id" {
description = "Security group ID for EC2"
}
variable "root_volume_type" {
description = "EBS root volume type"
}
variable "root_volume_size" {
description = "EBS root volume size"
}
variable "delete_on_termination" {
description = "EBS volume deletion on EC2 termination"
}
variable "ebs_device_mappings" {
default = null
description = "Need to provide the device name,volume size and volume type"
}
</code>
<code>variables.tf variable "instance_name" { description = "Name tag for EC2 instance" } variable "ami_id" { description = "AMI ID for EC2 instance" } variable "subnet_id" { description = "Subnet ID for EC2 instance" } variable "instance_type" { description = "Instance type for EC2 instance" } variable "key_pair" { description = "Key pair name for EC2 instance" default = null } variable "iam_instance_profile" { description = "IAM Instance Profile to launch the instance with" } variable "security_group_id" { description = "Security group ID for EC2" } variable "root_volume_type" { description = "EBS root volume type" } variable "root_volume_size" { description = "EBS root volume size" } variable "delete_on_termination" { description = "EBS volume deletion on EC2 termination" } variable "ebs_device_mappings" { default = null description = "Need to provide the device name,volume size and volume type" } </code>
variables.tf

variable "instance_name" {
  description = "Name tag for EC2 instance"
}
variable "ami_id" {
  description = "AMI ID for EC2 instance"
}
variable "subnet_id" {
  description = "Subnet ID for EC2 instance"
}
variable "instance_type" {
  description = "Instance type for EC2 instance"
}
variable "key_pair" {
  description = "Key pair name for EC2 instance"
  default     = null
}
variable "iam_instance_profile" {
  description = "IAM Instance Profile to launch the instance with"
}
variable "security_group_id" {
  description = "Security group ID for EC2"
}
variable "root_volume_type" {
  description = "EBS root volume type"
}
variable "root_volume_size" {
  description = "EBS root volume size"
}
variable "delete_on_termination" {
  description = "EBS volume deletion on EC2 termination"
}
variable "ebs_device_mappings" {
  default     = null
  description = "Need to provide the device name,volume size and volume type"
}

New contributor

Udhayashankar D is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật