Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unknown token IDENT aws_region

I have just run Terraform upgrade. My code was updated but now it shows some errors. The first was:

variable "s3_bucket_name" {
  type = list(string)
  default = [
    "some_bucket_name",
    "other_bucket_name",
    ...
  ]
}

It doesn't like list(string). I went back to square one and redid the entire Getting Started tutorial. It said that I could either explicitly state type = list or I could implicitly state it by leaving out type and just using the [square brackets].

I saw here: unknown token IDENT list error for IP address variable that I could use "list" (quotes) but I can't find any information on list(string).

So I commented out my list(string) which moved the error along to the next part.

provider "aws" {
  region = var.aws_region
}

The tutorial indicates that this is the correct way to create a region tag (there's actually part of the tutorial with that exact code).

Can anyone help me to understand what Unknown token IDENT means as it's throughout my code but it's not helping me to understand what I should do to fix it.

like image 222
Eoin Avatar asked Dec 24 '19 16:12

Eoin


1 Answers

This error appears when you execute terraform 0.12upgrade and your code syntax is already in Terraform 0.12x or obviously a mix of syntax versions <= 0.11x and 0.12x. Also the Unknown token IDENT error can happen when your installed version on your local machine (or in the remote CI/CD server) is 0.11x and your code syntax is on 0.12x and you run a terraform command such as terraform init

variable "var1" {
  type = "list"
  ...
} 

This a Terraform 0.11x syntax the alternative 12x is type = list(string)

To reproduce your error, I have a Terraform code 0.12x, I executed terraform 0.12upgrade then the unknown token: IDENT showed up!

In sum, I thought that your first code iteration is already in the correct syntax so there’s no need to upgrade. To avoid this kind of errors you can add a new version.tf file in your code with this content:

terraform {
  required_version = ">= 0.12"
}

Upgrading tips:

  1. Don’t mix the syntaxes in the same Terraform code, if so, downgrade manually your code to 0.11x
  2. Put all your Terraform code syntax in 0.11x
  3. Then run: terraform 0.12upgrade
like image 179
Aymen Segni Avatar answered Oct 20 '22 04:10

Aymen Segni