Unknown token IDENT aws_region

杀马特。学长 韩版系。学妹 提交于 2021-01-03 06:54:38

问题


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.


回答1:


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


来源:https://stackoverflow.com/questions/59471513/unknown-token-ident-aws-region

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!