An argument or block definition is required here

Hi All,
I am seeing the following error when i run terraform apply. Any ideas how to fix it?

Terraform version= Terraform v0.12.2 provider.aws v2.47.0

Error: An argument or block definition is required here. To set an argument, use the equals sign “=” to introduce the argument value. This is giving the error for the line below(password_policy.temporary_password_validity_days = 7):

resource “aws_cognito_user_pool” “admin_cognito_pool” {
name = “dummy-pool”
username_attributes = [“email”]
auto_verified_attributes = [“email”]
admin_create_user_config {
allow_admin_create_user_only = true
#unused_account_validity_days = 7
password_policy.temporary_password_validity_days = 7
}

This works for me (using terraform fmt)

resource "aws_cognito_user_pool" "admin_cognito_pool" {
  name                     = "dummy-pool"
  username_attributes      = ["email"]
  auto_verified_attributes = ["email"]
  admin_create_user_config = {
    allow_admin_create_user_only = true
    #unused_account_validity_days = 7
    password_policy.temporary_password_validity_days = 7
  }
}

Dunno if it’s functional.

Hi,
I tried using the same block which you pasted and now it fails with the below error when running Terraform plan. Any ideas how to fix it?

Error: Unsupported argument

on CreateUserPool.tf line 25, in resource “aws_cognito_user_pool” “admin_cognito_pool”:
25: admin_create_user_config = {

An argument named “admin_create_user_config” is not expected here. Did you
mean to define a block of type “admin_create_user_config”?

Ok, so fmt was checking for syntax only. My fault.

Yeah i ran fmt and it fixed the syntax of my file. On some research looks like you have to declare variables in variables.tf so i am doing that now to check if it fixes the issue.

Try this one:

resource "aws_cognito_user_pool" "admin_cognito_pool" {
  name                     = "dummy-pool"
  username_attributes      = ["email"]
  auto_verified_attributes = ["email"]
  admin_create_user_config {
    allow_admin_create_user_only = true
    #unused_account_validity_days = 7
  }
  password_policy {
    temporary_password_validity_days = 7
  }
}

Hi,
Thanks for helping me out on this. Appreciate it. I ran terraform plan again and now its complaining about this here: You can copy the below script as is and it should work for you:
Error:
on main.tf line 40, in resource “aws_cognito_user_pool” “admin_cognito_pool”:
40: schema = [
An argument named “schema” is not expected here. Did you mean to define a
block of type “schema”?

resource “aws_cognito_user_pool” “admin_cognito_pool” {
name = “test-pool”
alias_attributes = [“email”]
auto_verified_attributes = [“email”]
admin_create_user_config {
allow_admin_create_user_only = true
#unused_account_validity_days = 7
}
password_policy {
temporary_password_validity_days = 7
}
schema = [
{
attribute_data_type = “String”,
name = “institute”,
developer_only_attribute = false,
required = false,
mutable = false,
string_attribute_constraints = {
min_length = 1
max_length = 256
}
},
{
attribute_data_type = “String”,
name = “email”,
developer_only_attribute = false,
required = true,
mutable = true,
string_attribute_constraints = {
min_length = 0
max_length = 2048
}
},
{
attribute_data_type = “String”,
name = “name”,
developer_only_attribute = false,
required = true,
mutable = true,
string_attribute_constraints = {
min_length = 0
max_length = 2048
}
},
{
attribute_data_type = “String”,
name = “privacy”,
developer_only_attribute = false,
required = false,
mutable = true,
string_attribute_constraints = {
min_length = 1
max_length = 256
}
},
{
attribute_data_type = “String”,
name = “email”,
developer_only_attribute = false,
required = true,
mutable = true,
string_attribute_constraints = {
min_length = 0
max_length = 2048
}
},
{
attribute_data_type = “String”,
name = “tc”,
developer_only_attribute = false,
required = false,
mutable = true,
string_attribute_constraints = {
min_length = 1
max_length = 256
}
},
]
}

Hi,
so i was able to fix the issue. Terraform version was causing the issue. Downgraded to 11.13 and it worked.

1 Like

In case you have copy pasted the code online, try to rewrite the code as there may be some invisible characters. Got the same error, fixed it by rewriting.

1 Like

That was it , I replaced every special character by typing them and it worked - Thank you