hashicorp / terraform-provider-aws

The AWS Provider enables Terraform to manage AWS resources.
https://registry.terraform.io/providers/hashicorp/aws
Mozilla Public License 2.0
9.84k stars 9.19k forks source link

[Bug]: Cognito User Pool: cannot modify or remove schema items #38224

Open leventyalcin opened 4 months ago

leventyalcin commented 4 months ago

Terraform Core Version

1.8.3

AWS Provider Version

5.54.1

Affected Resource(s)

aws_cognito_user_pool

Expected Behavior

According to this issue and the this PR, the expected behaviour of Terraform plan/apply output after the first time, updates on schema should be ignored if string_attribute_constraints is present.

Actual Behavior

I am still seeing those triggers updates on aws_cognito_user_pool and it fails with the following output error message.

Plan Output

      - schema {
          - attribute_data_type      = "String" -> null
          - developer_only_attribute = false -> null
          - mutable                  = true -> null
          - name                     = "name" -> null
          - required                 = true -> null

          - string_attribute_constraints {
              - max_length = "512" -> null
              - min_length = "1" -> null
            }
        }
      + schema {
          + attribute_data_type = "String"
          + mutable             = true
          + name                = "name"
          + required            = true

          + string_attribute_constraints {
              + max_length = "512"
              + min_length = "1"
            }
        }

Apply result

Error: updating Cognito User Pool (REGION_xxxxxxxxx): cannot modify or remove schema items

Relevant Error/Panic Output Snippet

No response

Terraform Configuration Files

resource "aws_cognito_user_pool" "pool" {
  name                = "test"
  mfa_configuration   = "OFF"
  username_attributes = ["email"]

  user_pool_add_ons {
    advanced_security_mode = "AUDIT"
  }

  schema {
    name                = "email"
    attribute_data_type = "String"
    mutable             = true
    required            = true
    string_attribute_constraints {
      min_length = 1
      max_length = 512
    }
  }

  schema {
    name                = "name"
    attribute_data_type = "String"
    mutable             = true
    required            = true
    string_attribute_constraints {
      min_length = 1
      max_length = 512
    }
  }
}

Steps to Reproduce

Terraform apply for a template contains schemas like above twice. The second apply always fail.

Debug Output

No response

Panic Output

No response

Important Factoids

No response

References

No response

Would you like to implement a fix?

None

github-actions[bot] commented 4 months ago

Community Note

Voting for Prioritization

Volunteering to Work on This Issue

bannarisoftwares commented 2 months ago

Hi @leventyalcin

Add

string_attribute_constraints { max_length = "2048" min_length = "0" } on each schema to avoid this issue

Example:

schema { name = "scope" attribute_data_type = "String" mutable = true required = false string_attribute_constraints { max_length = "2048" min_length = "0" } }

When defining an attribute_data_type of String or Number, the respective attribute constraints configuration block (e.g string_attribute_constraints or number_attribute_constraints) is required to prevent recreation of the Terraform resource. This requirement is true for both standard (e.g., name, email) and custom schema attributes.

registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cognito_user_pool#schema

ewbankkit commented 3 weeks ago

Relates https://github.com/hashicorp/terraform-provider-aws/issues/38096.