aws-amplify / amplify-cli

The AWS Amplify CLI is a toolchain for simplifying serverless web and mobile development.
Apache License 2.0
2.82k stars 820 forks source link

amplify import auth generates mutiple resources of auth in teams provider info #11174

Open ykethan opened 2 years ago

ykethan commented 2 years ago

Before opening, please confirm:

How did you install the Amplify CLI?

No response

If applicable, what version of Node.js are you using?

No response

Amplify CLI Version

10.0.0

What operating system are you using?

Windows

Did you make any manual changes to the cloud resources managed by Amplify? Please describe the changes made.

No

Amplify Categories

auth

Amplify Commands

pull

Describe the bug

Creating a new application then importing a new Cogntio resource then pulling the amplify backend without pushing then re-importing the auth resource will leave redundant auth resource in team-provider-info.json.

Expected behavior

maintain only one resource oauth to prevent any unexpected issues in teams provider info

Reproduction steps

  1. amplify init
  2. amplify import auth
  3. amplify pull (do not push)
  4. amplify import auth check another auth resource in team provider info
  5. amplify push aws exports is correct but team provider has multiple blocks

GraphQL schema(s)

```graphql # Put schemas below this line ```

Project Identifier

No response

Log output

``` # Put your logs below this line ```

Additional information

No response

josefaidt commented 2 years ago

I was able to successfully reproduce this issue using the provided steps. Although I was not able to select the same auth resource from the import list, I was able to import another auth resource after running amplify pull, which resulted in multiple entries in my team-provider-info

{
  "dev": {
    "awscloudformation": {
      "AuthRoleName": "amplify-11174-dev-94216-authRole",
      "UnauthRoleArn": "arn:aws:iam::814763596509:role/amplify-11174-dev-94216-unauthRole",
      "AuthRoleArn": "arn:aws:iam::814763596509:role/amplify-11174-dev-94216-authRole",
      "Region": "us-east-1",
      "DeploymentBucketName": "amplify-11174-dev-94216-deployment",
      "UnauthRoleName": "amplify-11174-dev-94216-unauthRole",
      "StackName": "amplify-11174-dev-94216",
      "StackId": "arn:aws:cloudformation:us-east-1:814763596509:stack/amplify-11174-dev-94216/3ccf1f40-4b05-11ed-88c7-125d0fa00def",
      "AmplifyAppId": "d22pehuho9lavh"
    },
    "categories": {
      "auth": {
        "111747bf9ed77": {
          "userPoolId": "us-east-1_URv06JN56",
          "userPoolName": "1007014d5674a_userpool_14d5674a-next",
          "webClientId": "3lprqk08pd79nvm5p13ftpeaug",
          "nativeClientId": "n8t8fqjkojrvko0q6756lv9r8",
          "identityPoolId": "us-east-1:18e48aa8-33a3-4e27-9ada-ce053d3016e0",
          "identityPoolName": "1007014d5674a_identitypool_14d5674a__next",
          "allowUnauthenticatedIdentities": true,
          "authRoleArn": "arn:aws:iam::814763596509:role/amplify-10070-next-133842-authRole",
          "authRoleName": "amplify-10070-next-133842-authRole",
          "unauthRoleArn": "arn:aws:iam::814763596509:role/amplify-10070-next-133842-unauthRole",
          "unauthRoleName": "amplify-10070-next-133842-unauthRole"
        },
        "1117479f1db17": {
          "userPoolId": "us-east-1_URv06JN56",
          "userPoolName": "1007014d5674a_userpool_14d5674a-next",
          "webClientId": "n8t8fqjkojrvko0q6756lv9r8",
          "nativeClientId": "3lprqk08pd79nvm5p13ftpeaug",
          "identityPoolId": "us-east-1:18e48aa8-33a3-4e27-9ada-ce053d3016e0",
          "identityPoolName": "1007014d5674a_identitypool_14d5674a__next",
          "allowUnauthenticatedIdentities": true,
          "authRoleArn": "arn:aws:iam::814763596509:role/amplify-10070-next-133842-authRole",
          "authRoleName": "amplify-10070-next-133842-authRole",
          "unauthRoleArn": "arn:aws:iam::814763596509:role/amplify-10070-next-133842-unauthRole",
          "unauthRoleName": "amplify-10070-next-133842-unauthRole"
        }
      }
    }
  }
}

and the aws-exports.js file was created using the last entry

/* eslint-disable */
// WARNING: DO NOT EDIT. This file is automatically generated by AWS Amplify. It will be overwritten.

const awsmobile = {
    "aws_project_region": "us-east-1",
    "aws_cognito_identity_pool_id": "us-east-1:18e48aa8-33a3-4e27-9ada-ce053d3016e0",
    "aws_cognito_region": "us-east-1",
    "aws_user_pools_id": "us-east-1_URv06JN56",
    "aws_user_pools_web_client_id": "n8t8fqjkojrvko0q6756lv9r8",
    "oauth": {},
    "aws_cognito_username_attributes": [
        "EMAIL"
    ],
    "aws_cognito_social_providers": [],
    "aws_cognito_signup_attributes": [
        "EMAIL"
    ],
    "aws_cognito_mfa_configuration": "OFF",
    "aws_cognito_mfa_types": [],
    "aws_cognito_password_protection_settings": {
        "passwordPolicyMinLength": 8,
        "passwordPolicyCharacters": []
    },
    "aws_cognito_verification_mechanisms": [
        "EMAIL"
    ]
};

export default awsmobile;

typically if we try to import more than one auth resource we receive an appropriate warning:

⚠️ Auth has already been imported to this project and cannot be modified from the CLI. To modify, run "amplify remove auth" to unlink the imported auth resource. Then run "amplify import auth".