개발하자

terraform plan이 Error를 반환합니다: 지원되지 않는 인수

Cuire 2023. 10. 7. 14:22
반응형

terraform plan이 Error를 반환합니다: 지원되지 않는 인수

나는 main.tf , variables.tf 그리고 dev.auto.tfvars 라는 세가지 파일을 가지고 있다

스니펫 출처

module "sql_vms" {
  source                  = "git::git@github.com:xxxxxxxxxxxx/terraform-modules//azure/"
  rg_name                 = var.resource_group_name
  location                = module.resource_group.external_rg_location
  vnet_name               = var.virtual_network_name
  subnet_name             = var.sql_subnet_name
  app_nsg                 = var.application_nsg
  vm_count                = var.count_vm
  base_hostname           = var.sql_host_basename
  sto_acc_suffix          = var.storage_account_suffix
  vm_size                 = var.virtual_machine_size
  vm_publisher            = var.virtual_machine_image_publisher
  vm_offer                = var.virtual_machine_image_offer
  vm_sku                  = var.virtual_machine_image_sku
  vm_img_version          = var.virtual_machine_image_version
  username                = var.username
  password                = var.password
}

스니펫 출처

variable "app_subnet_name" {
  type    = string
}

variable "sql_subnet_name" {
  type    = string
}

스니펫 출처

app_subnet_name = "subnet_1"

sql_subnet_name = "subnet_2"

application_nsg = "test_nsg"

하지만 아래와 같은 오류가 발생하고 있습니다

Error: Unsupported argument

  on main.tf line 7, in module "sql_vms":
   7:   subnet_name    = var.sql_subnet_name

An argument named "subnet_name" is not expected here.


Error: Unsupported argument

  on main.tf line 8, in module "sql_vms":
   8:   app_nsg        = var.application_nsg

An argument named "app_nsg" is not expected here.

내 모듈 디렉토리 구조는 아래와 같다

$ ls -R terraform-modules/
terraform-modules/:
aws  azure  gcp

terraform-modules/aws:
alb  ec2-instance-rhel

terraform-modules/aws/alb:

terraform-modules/aws/ec2-instance-rhel:
main.tf

terraform-modules/azure:
compute  resourcegroup  sqlserver

terraform-modules/azure/compute:
main.tf  README.md  variable.tf

terraform-modules/azure/resourcegroup:
data.tf  outputs.tf  variables.tf

terraform-modules/azure/sqlserver:
main.tf  README.md  variables.tf

terraform-modules/gcp:
compute

terraform-modules/gcp/compute:
main.tf

여기서 뭐가 잘못되고 있는지 아세요?




와 의 작업을 할 때도 비슷한 문제가 있었습니다.

실행하면 다음과 같은 오류가 나타납니다:

Error: Unsupported argument
│ 
│   on ../../modules/aws/eventbridge/main.tf line 37, in resource "aws_cloudwatch_event_target" "ecs_cloudwatch_event_target":
│   37:     maximum_age_in_seconds = var.maximum_age_in_seconds
│ 
│ An argument named "maximum_age_in_seconds" is not expected here.

:

AWS Eventbridge 리소스 블록에 올바른 속성을 사용하지 않는 것이 문제였습니다.

속성은 그대로여야 하고 그렇지 않아야 합니다.

이 문제는 테라폼 스크립트에서 모듈에 이미 정의된 변수를 정의하지 않는 것입니다.

그뿐이다




제 경우에 이런 오류가 생겼을 때, 제가 그 이름을 가지고 있었다는 것이 답이었습니다.

그러니 항상 잘못된 파일 이름을 확인하세요.




그것은 많은 이유들 때문에 일어날 수도 있다. 검증을 제안합니다:


  1. 올바른 소스 URL, 경로 또는 리비전 분기/태그를 사용하고 있는지 확인합니다.

구현 방법에 대해서는 잘 모르겠지만, 참조 중인 수정판에 이러한 변수 선언이 포함되어 있는지 다시 확인하고 싶을 것입니다.

GitHub Modules addressing은 인수를 허용합니다.

참조 및

  1. 루트 모듈을 포함한 모든 모듈에 필요한 모든 변수가 선언되어 있는지 확인합니다.

루트 디렉터리의 파일과 모듈 컨텍스트/경로 모두에 이러한 변수를 선언했습니까?

소모적이고 반복적이라는 것을 알지만, 모든 모듈은 ""."로 설계되어야 한다.tf**는 해당 모듈에 대한 입력으로 작동하며, 이들 마지막 것은 필요하지 않지만 자체적으로 매핑된 outputs.tf, provider.tf, backend.tf 등을 갖는 것이 바람직하다.


이렇게 하면 확장성, 재사용성 및 신뢰성을 보장할 뿐만 아니라 각 모듈마다 다른 파일과 심지어 다른 저장소로 작업할 수 있어 원자성과 최소 권한을 보장하므로 원치 않는 코드 변경으로 인해 인프라가 파괴되는 것을 방지할 수 있습니다.

나는 독립적인 모듈화 설계의 중요성을 이해할 것을 강력히 권고한다.

또한 Terragrunt, Terratest와 같은 도구는 이 일을 덜 고통스럽게 만들 수 있다.

  1. 관련 변수가 일치합니다.**

만약 그렇지 않다면, (근에서) 인수로 사용되는 변수의 모든 선언과 (모듈 수준에서) 입력 사이에 유형 제약 조건이 일치하는지 확인해 보십시오.




모듈에 대한 세부 정보를 알지 못하면 일반적으로 오류의 이유가 무엇인지 말하기가 어렵지만, 이 특정한 경우에는 가져오는 모듈에서 두 개의 인수(및 및)를 사용하는 데 필요한 요구 사항이 없거나 오히려 존재할 필요가 없는 를 사용하는 것처럼 보입니다. 이러한 유형의 오류에 도움이 되는 것은 그러한 요구사항이 있는 모듈 버전이 있는지 확인하는 것입니다. Github의 특정 모듈 버전을 사용하는 구문은 문서의 섹션에 설명되어 있다:

module "vpc" {
  source = "git::https://example.com/vpc.git?ref=v1.2.0"
}

SSH를 사용하여 모듈을 가져올 수 있으므로 다음과 같습니다:

When using Git over SSH, we recommend using the ssh://-prefixed URL form for consistency with all of the other URL-like git address forms.

예를 들어, 다음과 같은 뜻이 있습니다:

module "sql_vms" {
  source = "git::ssh://git@github.com/org/terraform-modules-repo.git//azure/module-name?ref=v1.2.0"

여기서 는 조직(또는 개인) Github 계정이며, 모듈이 상주하는 repo이며, 사용 중인 모듈이며 모듈 수정 번호를 나타냅니다.

이 오류는 모듈이 해당 이름의 입력 인수를 볼 것으로 예상하지 않음을 의미합니다. 테라폼 모듈을 프로그래밍 언어의 함수로 생각해 보자. 함수가 결과를 제공하도록 하려면 필요한 인수 집합을 함수에 전달해야 한다. 함수 호출에서 요구하는 것보다 더 많은(또는 더 적은) 입력 인수를 제공하면 오류가 발생합니다. (특수한 경우가 있지만 이 질문의 범위를 벗어납니다.)


Another similarity between modules and functions is that Terraform modules can also provide output values, besides creating resources that are specified. That can be handy in cases where output can be used as input in other modules or resources. The line module.resource_group.external_rg_location is doing exactly that: getting the output value from another module and using it to assign a value to an argument location.




I think the issue is that you do not refer to the exact module with the source. I see you have three modules in the source:

source = "git::git@github.com:xxxxxxxxxxxx/terraform-modules//azure/"

They are compute, resourcegroup and sqlserver. But you want to load them in one module. So it cannot find the related variables for the modules. I also don't think it's the right way to load all the modules like that. I would recommend you load the modules one by one like below:

module "compute" {
  source = "git::git@github.com:xxxxxxxxxxxx/terraform-modules//azure/compute"
  ...
}

module "resourcegroup" {
  source = "git::git@github.com:xxxxxxxxxxxx/terraform-modules//azure/resourcegroup"
  ...
}

module "sqlserver" {
  source = "git::git@github.com:xxxxxxxxxxxx/terraform-modules//azure/sqlserver"
  ...
}



I'll share my pain as well.

Writing block configuration like this

  vpc_config = {
    subnet_ids = [aws_subnet.example1.id, aws_subnet.example2.id]
  }

Instead of (Notice the = Equal Sign):

  vpc_config {
    subnet_ids = [aws_subnet.example1.id, aws_subnet.example2.id]
  }

Will give an error of An argument named "vpc_config" is not expected here and will waste you a few good hours.




If you are starting out with Terraform, you will get that error message ("An argument named "example" is not expected here") if your module arguments refer to the resource properties and not to variable names, see below for an example:

Example of a Terraform module "example_mod.tf" you want to call from your module:

variable "sg_name" { }   # Usually in a separate file
variable "sg_desc" { }   # called variables.tf

resource "example_resource" "example_name" {
  name        = var.sg_name
  description = var.sg_desc
...
}

CORRECT WAY:

module "my_module" {
  source = "./modules/example_mod.tf"

  sg_name = "whatever"  # NOTE the left hand side "sg_name" is the variable name
  sg_desc = "whatever"    
...
}

INCORRECT WAY: (Gives the error "An argument named "name" is not expected here" )

module "my_module" {
  source = "./modules/example_mod.tf"

  name   = "whatever" # WRONG because the left hand side "name" is a resource property
  description = "whatever" # WRONG for the same reason   
...
}

반응형