Skip to content

ec2: InitCommand.argvCommand dedupes its args, causing the wrong command to be generated) #26221

@fidothe

Description

@fidothe

Describe the bug

using ec2.InitCommand.argvCommand() can, in some circumstances, remove duplicate strings from the input array, causing unexpected output.

Expected Behavior

Expected the following

ec2.InitCommand.argvCommand([
  'useradd', '-u', '1001', '-g', '1001', 'eguser',
]),
ec2.InitCommand.argvCommand([
  'useradd', '-a', '-u', '1001', '-g', '1001', 'eguser',
]),

To generate the following YAML:

          commands:
            "000":
              command:
                - useradd
                - -u
                - "1001"
                - -g
                - "1001"
                - eguser
            "001":
              command:
                - useradd
                - -a
                - -u
                - "1001"
                - -g
                - "1001"
                - eguser

Current Behavior

The following YAML was generated. Note the omission of the second occurrence of '1001' in the second command:

          commands:
            "000":
              command:
                - useradd
                - -u
                - "1001"
                - -g
                - "1001"
                - eguser
            "001":
              command:
                - useradd
                - -a
                - -u
                - "1001"
                - -g
                - eguser

Reproduction Steps

The CDK App in the provided repo contains the minimal resources needed to demonstrate the bug when running cdk synth:

https://github.com/fidothe/cdk-ec2-construct-bug-repro

git clone https://github.com/fidothe/cdk-ec2-construct-bug-repro && cd cdk-ec2-construct-bug-repro && cdk synth

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.85.0 (build 4e0d726)

Framework Version

No response

Node.js Version

v18.16.1

OS

macOS 13.4.1

Language

Typescript

Language Version

Typescript (5.1.5)

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    @aws-cdk/aws-ec2Related to Amazon Elastic Compute CloudbugThis issue is a bug.effort/mediumMedium work item – several days of effortp1

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions