Skip to content

IAM: addCondition overwrites previous conditions #20158

@llgerard

Description

@llgerard

Describe the bug

Looking at #19114 the code will The following code will forget conditions when the only difference is in the value tested, example:

const p = new PolicyStatement;
p.addCondition("StringEquals", {'sts:ExternalId': '12345678901'});
p.addCondition("StringEquals", {'sts:ExternalId': '01234567890'});
console.log(p.toStatementJson());

will forget the first condition, generating:

Condition: { StringEquals: { 'sts:ExternalId': '01234567890' } },
Effect: 'Allow'

instead of

Condition: { StringEquals: { 'sts:ExternalId': ['12345678901', '01234567890'] } },
Effect: 'Allow'

Expected Behavior

Not forget conditions

Current Behavior

Forget conditions

Reproduction Steps

import {
    PolicyStatement,
} from "monocdk/aws-iam";
const p = new PolicyStatement;
p.addCondition("StringEquals", {'sts:ExternalId': '12345678901'});
p.addCondition("StringEquals", {'sts:ExternalId': '01234567890'});
console.log(p.toStatementJson());

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

1.124

Framework Version

No response

Node.js Version

17.4

OS

macos

Language

Typescript

Language Version

No response

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    @aws-cdk/aws-iamRelated to AWS Identity and Access ManagementbugThis issue is a bug.cause/not-a-bugNot a bug (might still be a documentation issue, might still need work)effort/smallSmall work item – less than a day of effortp2

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions