Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cognito User Pool standard attribute handling changed in 1.13 #4228

Closed
jyrkiput opened this issue Apr 17, 2018 · 12 comments
Closed

Cognito User Pool standard attribute handling changed in 1.13 #4228

jyrkiput opened this issue Apr 17, 2018 · 12 comments
Labels
bug Addresses a defect in current functionality. stale Old or inactive issues managed by automation, if no further action taken these will get closed.

Comments

@jyrkiput
Copy link

I want to set standard attribute as required, and 1.13 forward handling of this changed.

Terraform Version

Terraform v0.11.7

  • provider.aws v1.14.1

Affected Resource(s)

aws_cognito_user_pool

Terraform Configuration Files

provider "aws" {
  version = "1.14.1"
}

resource "aws_cognito_user_pool" "pool" {
  name = "cognito-terraform-bug"

  schema {
    attribute_data_type = "String"
    name                = "phone_number"
    required            = true
  }
}

Debug Output

https://gist.github.com/jyrkiput/4b92d037fcbbb327abb8ddbfeaa5f49c

Expected Behavior

With AWS provider 1.12, you can apply this configuration multiple times without destroying user pool.

Actual Behavior

Terraform things that schema has changed as the string_attribute_constraints is not present

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:

  1. terraform apply
  2. terraform apply

References

Are there any other GitHub issues (open or closed) or Pull Requests that should be linked here? For example:

Workaround

Define string_attribute_constraints exactly like it seems to be (values found from plan output).

provider "aws" {
  version = "1.14.1"
}

resource "aws_cognito_user_pool" "pool" {
  name = "cognito-terraform-bug"

  schema {
    attribute_data_type = "String"
    name                = "phone_number"
    required            = true

    string_attribute_constraints {
      min_length = 0
      max_length = 2048
    }
  }
}
@Puneeth-n
Copy link
Contributor

Puneeth-n commented Apr 17, 2018

@jyrkiput So if I understood you right, you want to set the phone_number as required and earlier it was not required?

At least from the aws console there is no way of switching an attribute's required attribute once the pool is created. So I am guessing this is the actual behavior. However, I am afraid that setting the string_attribute_constraints seems to be some other bug.

@bflad What do you think?

@jyrkiput
Copy link
Author

jyrkiput commented Apr 17, 2018

@Puneeth-n the phone_number has been required from the beginning. With 1.12 you can create this setup and apply it again, with 1.13+ terraform apply start to replace whole user pool.

What I did was:

  1. created a new user pool with that configuration with terraform apply
  2. ran terraform apply again and user pool got replaced

Actually minimal configuration is following

resource "aws_cognito_user_pool" "pool" {
  name = "cognito-terraform-bug"

  schema {
    attribute_data_type = "String"
    name                = "phone_number"
  }
}

This will cause the user pool to be recreated on every terraform apply, as the "phone_number" attribute changes.

I guess that this might really be as expected, as the schema does not really represent what that phone_number -attribute really is.

The reason for creating this issue was that this used to work with 1.12.

@Puneeth-n
Copy link
Contributor

Puneeth-n commented Apr 17, 2018

I could reproduce this bug with the following minimal configuration:

variable "region" {
  default = "us-east-1"
}

provider "aws" {
  version               = "1.14.1"
  region                = "${var.region}"
}

resource "aws_cognito_user_pool" "pool" {
  name = "cognito-terraform-bug"

  schema {
    attribute_data_type = "String"
    name                = "phone_number"

  }
}

My best guess is, it is coming from https://github.com/terraform-providers/terraform-provider-aws/blob/74a51650b29c53a389a9d034c2ece43d3fb279d5/aws/structure.go#L2750-L2756

@bflad bflad added bug Addresses a defect in current functionality. service/cognito labels Apr 17, 2018
@bflad
Copy link
Contributor

bflad commented Apr 17, 2018

In 1.13.0 (#3789 specifically), the aws_cognito_user_pool resource was updated to detect schema drift from the API. The initial implementation of this detection was able to wholesale detect changes with schema attributes, but not fully ignore Terraform configurations missing parts of a schema configuration like string_attribute_constraints.

The logic is here:

https://github.com/terraform-providers/terraform-provider-aws/blob/74a51650b29c53a389a9d034c2ece43d3fb279d5/aws/structure.go#L3005-L3018

The workaround is to fully specify all the standard schema attribute information.

@loivis
Copy link
Contributor

loivis commented Apr 18, 2018

Hit the same issue a few days ago. Just workaround it but didn't get time to look into it.

@smastrorocco
Copy link

Hitting the same issue Terraform v0.11.7 AWS provider v1.16.0

@haidaraM
Copy link
Contributor

Same issue with Terraform v0.11.8 and provider.aws v1.39.0. Terraform always tries to recreate the user pool even when nothing changed. Example (run terraform apply twice):

resource "aws_cognito_user_pool" "my_user_pool" {
  name                = "${var.prefix}-tuto-cognito"
  username_attributes = ["email"]

  schema {
    attribute_data_type = "String"
    name                = "name"
  }
}

@huihe
Copy link

huihe commented Dec 20, 2018

I got the same issue with Terraform v0.11.11 and provider.aws v1.52.0. New custom attribute results re-creating the user pool.

@codyseibert
Copy link

Same issue with Terraform v0.11.11 and provider.aws v1.58.0.

@sa-shukla
Copy link

I am also running into same issue with Terraform v0.11.8 and provider.aws v2.x . Is there a proper workaround or fix available in later versions?

@github-actions
Copy link

Marking this issue as stale due to inactivity. This helps our maintainers find and focus on the active issues. If this issue receives no comments in the next 30 days it will automatically be closed. Maintainers can also remove the stale label.

If this issue was automatically closed and you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thank you!

@github-actions github-actions bot added the stale Old or inactive issues managed by automation, if no further action taken these will get closed. label Jul 18, 2021
@github-actions github-actions bot closed this as completed Sep 4, 2021
@github-actions
Copy link

github-actions bot commented Jun 9, 2022

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 9, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Addresses a defect in current functionality. stale Old or inactive issues managed by automation, if no further action taken these will get closed.
Projects
None yet
Development

No branches or pull requests

9 participants