-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
New Resource: aws_cognito_identity_provider #3601
New Resource: aws_cognito_identity_provider #3601
Conversation
@bflad maybe you know how to handle perpetual diffs for TypeMap variable? |
Any idea on when this PR will get merged? At the moment as soon as you change/add/remove a Provider through the console terraform, for some unexpected reason, tries to recreate the user pool. |
@leonfs thanks for your feedback. I will check this :-) |
@pawelsocha No worries, thanks for making this PR. Though the bug I mentioned earlier does not have anything to do with your code but with the current implementation of the I suspect that after adding an identity provider (let's say Google) to the user pool through AWS console, the api call to AWS from Terraform returns an array with For some reason Terraform tries to recreate the whole resource (it shouldn't as it's a value that can change after creation). I'm wondering if with this PR the problem will actually be solved. Or it's a different problem. |
@leonfs yeap, something is wrong. My example:
So, debugging in progress :-) |
@leonfs Terraform recreate aws_cognito_user_pool_client resource every apply/plan because it's affected by TypeSet implementation in TF: hashicorp/terraform#15420 (comment) And also in resource source attribute have ForceNew set to true:
|
@pawelsocha That's interesting. What I don't understand this is when a change in the schema attributes happen. What triggered for me the change was adding/changing and identity provider (Google). What link could exist between those 2 things? |
@leonfs change is forced by resource definition in code. |
@pawelsocha - Not really sure if I get what you are saying. I can see that there is a field But when I change/add the identity provider I don't change the schema attribute. So why would that force the recreation? |
@leonfs when tf recreating |
@pawelsocha Not really sure about what you are saying. Does not really make sense. TF should not recreate the It looks like AWS adds a custom attribute called The problem is fixed by adding the following schema attribute.
Notice the empty See issues:
In any case - thanks for the feedback and looking forward to your PR getting merged. |
@leonfs :-) Today I had only a few hours to investigate this problem. But, in my case terraform recreate the whole resource and create new ID (exactly like in #3891) Now I know. Aws add some extra attributes to the resource. One question: in your plan - terraform shows change in the schema with identity? |
@pawelsocha
|
@skoop22 Thanks for your research. But, I'm not a terraform developer. |
log.Print("[DEBUG] Updating Cognito Identity Provider") | ||
|
||
params := &cognitoidentityprovider.UpdateIdentityProviderInput{ | ||
UserPoolId: aws.String(d.Get("UserPoolId").(string)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just wondering... is "d.Get("UserPoolId") correct? Or should it be: d.Get("user_pool_id")?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I will change it.
|
||
"user_pool_id": { | ||
Type: schema.TypeString, | ||
Required: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should user_pool_id be ForceNew? If the pool id changes, wouldn't a new provider need to be created?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
…rceNew to user_pool_id
Any news on this one I want to remove my workaround :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @pawelsocha! 👋 Thanks for submitting this! I left some feedback below which I'll try to address myself right now. If I can get this fixed up tonight, I'll get this in for the v1.21.0 release.
"provider_details": { | ||
Type: schema.TypeMap, | ||
Optional: true, | ||
Computed: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if this was intentional, but it does not seem like we should be ignoring this from the API if its not in the Terraform configuration. I'll double check from the acceptance testing. Also, the API/SDK documentation seems to imply this should be Required: true
.
return fmt.Errorf("Error creating Cognito Identity Provider: %s", err) | ||
} | ||
|
||
d.SetId(*name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In order to easily support import, let's prepend the resource ID with the user pool ID:
d.SetId(fmt.Sprintf("%s:%s", userPoolID, providerName))
Then with configuring the passthrough Importer
in the resource, we can support import via terraform import aws_cognito_identity_provider.example xxx_yyyyyy:example
}) | ||
|
||
if err != nil { | ||
if awsErr, ok := err.(awserr.Error); ok && awsErr.Code() == "ResourceNotFoundException" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor nitpick: we have a helper function to simplify this logic: isAWSErr(err, cognitoidentity.ErrCodeResourceNotFoundException, "")
|
||
if err != nil { | ||
if awsErr, ok := err.(awserr.Error); ok && awsErr.Code() == "ResourceNotFoundException" { | ||
d.SetId("") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When removing a resource from the state, we prefer to provide a warning log, e.g.
log.Printf("[WARN] Cognito Identity Provider %q not found, removing from state", d.Id())
return err | ||
} | ||
|
||
ip := ret.IdentityProvider |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should perform a nil
check here in the unlikely scenario that the API does not error and also omits this attribute.
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccAWSCognitoIdentityProviderConfig_basic(), | ||
Check: resource.ComposeAggregateTestCheckFunc( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is missing an testAccCheckAWSCognitoIdentityProviderExists()
function, which we usually call first in a set of checks to help determine if the physical resource exists in the API as well as pass back the API response object back as a variable we can later reference in other checks.
return nil | ||
} | ||
|
||
func testAccAWSCognitoIdentityProviderConfig_basic() string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor nitpick: the formatting is fairly inconsistent throughout this test configuration which makes it harder to read
return m | ||
} | ||
|
||
func flattenCognitoIdentityProviderMap(config map[string]*string) map[string]string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The AWS SDK already provides a helper function to perform this: aws.StringValueMap()
@@ -3035,6 +3035,23 @@ func flattenCognitoIdentityPoolRoles(config map[string]*string) map[string]strin | |||
return m | |||
} | |||
|
|||
func expandCognitoIdentityProviderMap(config map[string]interface{}) map[string]*string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We already have a (admittedly hard to find) helper function to perform this already: stringMapToPointers()
|
||
```hcl | ||
resource "aws_cognito_user_pool" "example" { | ||
name = "example-pool" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor nitpick: the formatting is slightly off in the example configuration here and below with email
After implementing the above feedback, I was able to get the acceptance testing working by ignoring the
|
This has been released in version 1.21.0 of the AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. |
@bflad thanks for your review. it's lots of knowledge for me. |
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 feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks! |
Overview
New resource to create identity provider for Cognito user pool.
This PR solves #3279
Tests