terraform,

'Argument or block definition required' error in Terraform

Jun 15, 2022 · 1 min read · Post a comment

Continuing on my Terraform issues journey, I’m going to try to help you with resolving yet another common TF error:

╷
│ Error: Argument or block definition required
│
│   on providers.tf line 1:
│    1: ��provider "azuread" {
│
│ An argument or block definition is required here.
╵

Prerequisites

  • Terraform

Error causes

Despite the vague error explanation and hard to pinpoint the issue, these are mostly syntax-based errors, including:

  • non-ASCII, strange and invisible characters in the code.
  • Misspelled arguments and incorrectly assigning argument values.
  • Having extra or missing closed block brackets {}.
  • Including or missing double quotes where required.
  • Missing and incorrect variable definitions.
  • Adding data blocks as data.aws_vpc.devcoops-vpc { .. } instead of data "aws_vpc" "devcoops_vpc" { .. }
  • hardcoding credentials.
  • Recently upgraded to a new TF version with a breaking changes.

Solution(s)

Though it’s hard to pinpoint the issues, what you could try is:

  1. Try to run terraform fmt in Terraform working directory. Basically, it’ll rewrite all TF configuration files to a standard format and style.
  2. Rewrite any special, strange or invisible characters.
  3. Comment out any potential error-causing blocks.
  4. Lastly, try to upgrade/downgrade the Terraform version.

Conclusion

If you have any related unresolved issues, feel free to share them in the comment section below. On a side note, follow our official channel on Telegram.