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

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

Labels
@aws-cdk/aws-ec2 Related to Amazon Elastic Compute Cloud bug This issue is a bug. effort/medium Medium work item – several days of effort p1

Comments

@fidothe
Copy link

fidothe commented Jul 4, 2023

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

@fidothe fidothe added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jul 4, 2023
@github-actions github-actions bot added the @aws-cdk/aws-ec2 Related to Amazon Elastic Compute Cloud label Jul 4, 2023
fidothe added a commit to fidothe/cdk-ec2-construct-bug-repro that referenced this issue Jul 4, 2023
@fidothe fidothe changed the title (aws-cdk/aws_ec2): (ec2.InitCommand.argvCommand dedupes its args, causing the wrong command to be generated) (aws-cdk-lib/aws-ec2): (ec2.InitCommand.argvCommand dedupes its args, causing the wrong command to be generated) Jul 4, 2023
@pahud pahud changed the title (aws-cdk-lib/aws-ec2): (ec2.InitCommand.argvCommand dedupes its args, causing the wrong command to be generated) ec2: (ec2.InitCommand.argvCommand dedupes its args, causing the wrong command to be generated) Jul 5, 2023
@pahud pahud changed the title ec2: (ec2.InitCommand.argvCommand dedupes its args, causing the wrong command to be generated) ec2: InitCommand.argvCommand dedupes its args, causing the wrong command to be generated) Jul 5, 2023
@pahud pahud self-assigned this Jul 5, 2023
@pahud
Copy link
Contributor

pahud commented Jul 5, 2023

Yes I can reproduce this in my account

With this configuration:

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

I got incorrect template definition(001 and 002) as below:

      AWS::CloudFormation::Init:
        configSets:
          default:
            - config
        config:
          commands:
            "000":
              command:
                - useradd
                - -a
                - -u
                - "1001"
                - -g
                - "1001"
                - eguser
            "001":
              command:
                - useradd
                - -a
                - -u
                - "1001"
                - -g
                - eguser
            "002":
              command:
                - useradd
                - -u
                - "1001"
                - -g
                - eguser

@pahud pahud added p1 effort/medium Medium work item – several days of effort labels Jul 5, 2023
@pahud pahud removed their assignment Jul 5, 2023
@pahud pahud removed the needs-triage This issue or PR still needs to be triaged. label Jul 5, 2023
@mergify mergify bot closed this as completed in #30821 Aug 8, 2024
@mergify mergify bot closed this as completed in 1e7c690 Aug 8, 2024
Copy link

github-actions bot commented Aug 8, 2024

Comments on closed issues and PRs are hard for our team to see.
If you need help, please open a new issue that references this one.

1 similar comment
Copy link

github-actions bot commented Aug 8, 2024

Comments on closed issues and PRs are hard for our team to see.
If you need help, please open a new issue that references this one.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 8, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.