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

aws-cdk-lib/aws-secretsmanager: Secret already exists in another stack #24657

Closed
lhincapie0 opened this issue Mar 16, 2023 · 5 comments
Closed
Labels
@aws-cdk/aws-secretsmanager Related to AWS Secrets Manager bug This issue is a bug. closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. p2 response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.

Comments

@lhincapie0
Copy link

lhincapie0 commented Mar 16, 2023

Describe the bug

We are trying to deploy new stacks with aws-cdk referencing a secret to attach credentials to an RDS instance and we are getting the following error (only happens with new stacks):

❌ Error: The stack named new_stack_name failed creation, it may need to be manually deleted from the AWS console: ROLLBACK_COMPLETE: arn:aws:secretsmanager:us-east-2:<*****accountd_id*****>:secret:<*****secret_arn*****> already exists in stack arn:aws:cloudformation:us-east-2:<*****accountd_id*****>:stack/<*****existing_stack_name*****>/<*****existing_stack_id*****>

This error started happening one month ago without any changes from our side, before this we were able to deploy the same infrastructure for existing and new stacks.

The following code is getting the secret from secrets manager and attaching this secret to the RDS instance:

const dbCredentials = secretsmanager.Secret.fromSecretNameV2(stack, 'DBSecret', 'secret-name');

 const database = new rds.DatabaseInstance(stack, 'database-name', {
        credentials: rds.Credentials.fromSecret(dbCredentials),
        removalPolicy: RemovalPolicy.RETAIN,
        engine: rds.DatabaseInstanceEngine.postgres({ version: postgresVersion })
        ... 
    }
});

Expected Behavior

The database and secret attachment is created successfully

Current Behavior

The deployment of a new stack fails when it tries to create the Secret Attachment for the RDS instance

stack-name | 41/44 | 10:56:06 PM | CREATE_FAILED        | AWS::SecretsManager::SecretTargetAttachment | project-name/DBSecret/Attachment (DBSecretAttachmentC565A14F) arn:aws:secretsmanager:us-east-2:<*****accountd_id*****>:secret:<*****secret_arn*****> already exists in stack arn:aws:cloudformation:us-east-2:<*****accountd_id*****>:stack/<*****existing_stack_name*****>/<*****existing_stack_id*****>

Reproduction Steps

Described above.

Possible Solution

I tried to follow the steps described in #24383 but its still happening

Additional Information/Context

No response

CDK CLI Version

2.67.0

Framework Version

No response

Node.js Version

16.0

OS

Ubuntu

Language

Typescript

Language Version

No response

Other information

No response

@lhincapie0 lhincapie0 added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Mar 16, 2023
@github-actions github-actions bot added the @aws-cdk/aws-secretsmanager Related to AWS Secrets Manager label Mar 16, 2023
@pahud
Copy link
Contributor

pahud commented Mar 17, 2023

Hi

Where is the credentials defined in rds.Credentials.fromSecret(credentials), ?

Can you share more details?

const dbCredentials = secretsmanager.Secret.fromSecretNameV2(stack, 'DBSecret', 'secret-name');

 const database = new rds.DatabaseInstance(stack, 'database-name', {
        credentials: rds.Credentials.fromSecret(credentials),
        removalPolicy: RemovalPolicy.RETAIN,
        engine: rds.DatabaseInstanceEngine.postgres({ version: postgresVersion })
        ... 
    }
});

@pahud pahud added p2 response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. and removed needs-triage This issue or PR still needs to be triaged. labels Mar 17, 2023
@lhincapie0
Copy link
Author

@pahud sorry, I just modified the description, its the one being retrieved from secrets manager:

const dbCredentials = secretsmanager.Secret.fromSecretNameV2(stack, 'DBSecret', 'secret-name');

 const database = new rds.DatabaseInstance(stack, 'database-name', {
        credentials: rds.Credentials.fromSecret(dbCredentials),
        removalPolicy: RemovalPolicy.RETAIN,
        engine: rds.DatabaseInstanceEngine.postgres({ version: postgresVersion })
        ... 
    }
});

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Mar 17, 2023
@lhincapie0
Copy link
Author

Any updates?

@pahud
Copy link
Contributor

pahud commented Mar 27, 2023

Secret.fromSecretNameV2() returns the ISecret that contains an ambiguous Secret ARN with -?????? suffix and is not designed to be used with services that require full ARN. In your case, if you need to import existing secret I am afraid you will need to use fromSecretAttributes() instead as it contains full ARN. We have some discussion around this at #18555 (comment)

Let me know if it works with you.

@pahud pahud added the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Mar 27, 2023
@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Mar 28, 2023
@pahud pahud added the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Apr 4, 2023
@github-actions
Copy link

github-actions bot commented Apr 4, 2023

This issue has not received a response in a while. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.

@github-actions github-actions bot added closing-soon This issue will automatically close in 4 days unless further comments are made. closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. and removed closing-soon This issue will automatically close in 4 days unless further comments are made. labels Apr 4, 2023
@github-actions github-actions bot closed this as completed Apr 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-secretsmanager Related to AWS Secrets Manager bug This issue is a bug. closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. p2 response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.
Projects
None yet
Development

No branches or pull requests

2 participants