Search code examples
terraformterraform-template-fileterraform-provider

Terraform TF file error: An argument named "XYZ" is not expected here. Did you mean to define a block of type "XYZ"?


I am trying to create Provider in Terraform. I have requirement to store array of structure.

TF File Detail (sample detail):

resource "sample_ldu" "myldu" {
  // multiple variables ...
   ldus = [
        {
          ld = 11
          lu = 12
        },
      ]
}

Here i need array of ld-lu, so i can add multiple ld, lu.

My Provider Schema (for sample):

"ldus": &schema.Schema{
        Type:     schema.TypeList,
        Optional: true,
        Elem: &schema.Resource{
            Schema: map[string]*schema.Schema{
                "ld": {
                    Optional: true,
                    Type:     schema.TypeInt,
                },
                "lu": {
                    Optional: true,
                    Type:     schema.TypeInt,
                },
            },
        },
    },

Terraform Version: Terraform v1.3.9

Terraform Init - OK

Terraform Plan - Giving Error

Error: Unsupported argument
│ 
│   on ldu_create.tf line 30, in resource "sample_ldu" "myldu":
│   30:   ldus = [
│ 
│ An argument named " ldus" is not expected here. Did you mean to define a
│ block of type " ldus"?

Simple int_value = 10, array_value =[ 10, 20] etc are working fine. But if I am adding array of integer structure then it is giving error.

Can you please help me how I can achieve this scenario in Terraform TF file for my provider?

Is it possible to add this type of structure in TF files?

ldus = [
        {
          ld = 11
          lu = 12
        },
     ]

Solution

  • I did not found solution for this structure.

    But adding multiple in List is solve my problem for now.

        lud{
            ld = 11
            lu = 12
        }
        lud{
            ld = 13
            lu = 14
        }