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] ConfigSets not being generated correctly in c# #11021

Closed
hansterwal opened this issue Oct 21, 2020 · 2 comments
Closed

[EC2] ConfigSets not being generated correctly in c# #11021

hansterwal opened this issue Oct 21, 2020 · 2 comments
Assignees
Labels
@aws-cdk/aws-ec2 Related to Amazon Elastic Compute Cloud bug This issue is a bug. needs-triage This issue or PR still needs to be triaged.

Comments

@hansterwal
Copy link

Reproduction Steps

using cdk synth with the following code snippet

var synccmd = InitCommand.ShellCommand("start /wait powershell.exe -ExecutionPolicy RemoteSigned -Command \"& { set-TimeZone 'W. Europe Standard Time' }\"",
                new InitCommandOptions() { 
                 WaitAfterCompletion = InitCommandWaitDuration.Of(Duration.Seconds(0))
                ,Key = "1-sync-time"
                 });            
            var file = Amazon.CDK.AWS.EC2.InitFile.FromString($"c:\\cfn\\cfn-hup.conf","blablalba");
            var configs = new Dictionary<string,InitConfig>();
            
            configs.Add("configurecfn", new InitConfig(new InitFile[]{file}));           
            configs.Add("synctime", new InitConfig(new InitCommand[]{ synccmd }));
            
            var sets = new Dictionary<string,string[]>();
            sets.Add("EC2Win1", new []{ "timezone", "synctime" });
            var configProps = new ConfigSetProps(){
                ConfigSets = sets,
                Configs = configs
            };
              var configsets = Amazon.CDK.AWS.EC2.CloudFormationInit.FromConfigSets(configProps);
            template.AddMetadata("AWS::CloudFormation::Init", configsets);

What did you expect to happen?

      aws:cdk:path: DemoStack-dev/LaunchTemplatehigh
        _configSets:
          EC2Win1:
            - timezone
            - synctime
        _configs:
            configurecfn:
              - files: c:\cfn\cfn-hup.conf
                content:
                     blablalba                
             synctime:
               1-sync-time:
                   - command: start /wait powershell.exe -ExecutionPolicy RemoteSigned -Command "& { set-TimeZone 'W. Europe Standard Time' }"            
                waitAfterCompletion: 0

What actually happened?

it generates the following:Metadata:

      aws:cdk:path: DemoStack-dev/LaunchTemplatehigh
        _configSets:
          EC2Win1:
            - timezone
            - synctime
        _configs:
          configurecfn:
            elements:
              - fileName: c:\cfn\cfn-hup.conf
                options: {}
                elementType: FILE
          synctime:
            elements:
              - command: start /wait powershell.exe -ExecutionPolicy RemoteSigned -Command "& { set-TimeZone 'W. Europe Standard Time' }"
                options:
                  key: 1-sync-time
                  waitAfterCompletion: {}
                elementType: COMMAND

Environment

  • CLI Version :2.0.55
  • Framework Version :1.69.0
  • Node.js Version: v12.18.3
  • OS : Windows 10 Pro:
  • Language (Version): donet 3.1.101

Other

I don't understand the element and elementType key being emitted AWS Docs don't mention them.


This is 🐛 Bug Report

@hansterwal hansterwal added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Oct 21, 2020
@hansterwal hansterwal changed the title ConfigSets not being generated correctly in c# [EC2] ConfigSets not being generated correctly in c# Oct 22, 2020
@github-actions github-actions bot added the @aws-cdk/aws-ec2 Related to Amazon Elastic Compute Cloud label Oct 22, 2020
@rix0rrr
Copy link
Contributor

rix0rrr commented Oct 26, 2020

            template.AddMetadata("AWS::CloudFormation::Init", configsets);

Is not how you're supposed to attach this. You're not writing CloudFormation templates.

Read this for EC2 instances: https://docs.aws.amazon.com/cdk/api/latest/docs/aws-ec2-readme.html#configuring-instances-using-cloudformation-init-cfn-init

For ASGs we still need to merge this PR: #9674

@rix0rrr rix0rrr closed this as completed Oct 26, 2020
@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-ec2 Related to Amazon Elastic Compute Cloud bug This issue is a bug. needs-triage This issue or PR still needs to be triaged.
Projects
None yet
Development

No branches or pull requests

2 participants