terraform,

Terraform and 'the object type constructor requires one argument...'

Apr 05, 2023 · 1 min read · Post a comment

Upgrading Terraform version (at least before version 1.0) to another major release, always comes with certain errors along the way, mostly for those being lazy to read any release notes. So, here’s yet another issue that I’ve faced: The object type constructor requires one argument specifying the attribute types and values as a map.

Prerequisites

  • Terraform

Solution

It’s obvious that it’s a syntax or format issue in the TF code. First, check for any typos in the code.

But in most cases, it comes down to writing “invalid” map or object variables. Mostly, you’ll find them as key-value pairs e.g. defining instance tags. Example code block:

variable "tags" {
  description = "A map of tags to assign to the bucket."
  type        = map(string)
  default     = {
    type = "s3"
    org  = "devcoops"
  }
}

resource "aws_s3_bucket" "this" {
  bucket = var.bucket
  tags   = var.tags
}

Conclusion

When nothing works, feel free to leave a comment below and if you find this tutorial useful, follow our official channel on Telegram.