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

CfnInstance fails in C# with complex properties (Tags, SecurityGroupIds) set #3672

Closed
1 of 5 tasks
McDoit opened this issue Aug 15, 2019 · 2 comments · Fixed by aws/jsii#772
Closed
1 of 5 tasks

CfnInstance fails in C# with complex properties (Tags, SecurityGroupIds) set #3672

McDoit opened this issue Aug 15, 2019 · 2 comments · Fixed by aws/jsii#772
Labels
duplicate This issue is a duplicate.

Comments

@McDoit
Copy link
Contributor

McDoit commented Aug 15, 2019

Note: for support questions, please first reference our documentation, then use Stackoverflow. This repository's issues are intended for feature requests and bug reports.

  • I'm submitting a ...

    • 🪲 bug report
    • 🚀 feature request
    • 📚 construct library gap
    • ☎️ security issue or vulnerability => Please see policy
    • ❓ support request => Please see note at the top of this template.
  • What is the current behavior?
    If the current behavior is a 🪲bug🪲: Please provide the steps to reproduce

Trying to deploy/diff a stack with a CfnInstance with Tags or Security groups set, fails

  • What is the expected behavior (or behavior of feature suggested)?

To diff or deploy the CfnInstance

  • What is the motivation / use case for changing the behavior or adding this feature?

It worked in 0.28

  • Please tell us about your environment:

    • CDK CLI Version: 1.4
    • Module Version: 1.4
    • OS: Windows 10
    • Language: C#
  • Other information (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. associated pull-request, stackoverflow, gitter, etc)

An app like this:

class Program
    {
        static void Main(string[] args)
        {
            var app = new App(null);

            // A CDK app can contain multiple stacks. You can view a list of all the stacks in your
            // app by typing `cdk list`.
            //new OfficeInfrastructureStack(app, "emg-office-infrastructure", new StackProps());

            new AStack(app, "a-stack", new StackProps());

            app.Synth();
        }
    }

    public class AStack : Stack
    {
        public AStack(Construct scope, string name, IStackProps props) : base(scope, name, props)
        {
            var vpc = new Vpc(this, "vpc", new VpcProps
            {
                Cidr = "10.0.0.0/16",
                SubnetConfiguration = new ISubnetConfiguration[]
                {
                    new SubnetConfiguration { Name = "Public", CidrMask = 24, SubnetType = SubnetType.PUBLIC }
                },
            });

            var image = new WindowsImage(WindowsVersion.WINDOWS_SERVER_2019_ENGLISH_FULL_BASE, new WindowsImageProps());

            var imageId = image.GetImage(this).ImageId;
            var type = InstanceType.Of(InstanceClass.BURSTABLE3, InstanceSize.SMALL);

            var subnets = vpc.SelectSubnets(new SubnetSelection {SubnetType = SubnetType.PUBLIC, OnePerAz = true});

            var subnetId = subnets.SubnetIds.First();
            
            var instance = new CfnInstance(this, "instance", new CfnInstanceProps
            {
                Tags = new ICfnTag[] { new CfnTag { Key = "Name", Value = "instance" } },
                InstanceType = type.ToString(),
                ImageId = imageId,
                KeyName = "key",
                SubnetId = subnetId,
                //SecurityGroupIds = new[] { "sg-12345678" }
            });
        }
    }

Throws the following error:

Amazon.JSII.Runtime.JsiiException: Resolution error: System.ArgumentException: Could not infer JSII type for .NET type 'JArray'
Parameter name: type
   at Amazon.JSII.Runtime.Services.Converters.FrameworkToJsiiConverter.InferType(IReferenceMap referenceMap, Type type)
   at Amazon.JSII.Runtime.Services.Converters.ValueConverter.ConvertAny(IReferenceMap referenceMap, Object value)
   at Amazon.JSII.Runtime.Services.Converters.ValueConverter.TryConvertPrimitive(IReferenceMap referenceMap, Object value, Boolean isOptional, PrimitiveType primitiveType, Object& result)
   at Amazon.JSII.Runtime.Services.Converters.ValueConverter.TryConvert(IOptionalValue optionalValue, IReferenceMap referenceMap, Object value, Object& result)
   at Amazon.JSII.Runtime.Services.Converters.FrameworkToJsiiConverter.TryConvertMap(IReferenceMap referenceMap, TypeReference elementType, Object value, Object& result)
   at Amazon.JSII.Runtime.Services.Converters.ValueConverter.TryConvert(IOptionalValue optionalValue, IReferenceMap referenceMap, Object value, Object& result)
   at Amazon.JSII.Runtime.Deputy.DeputyBase.<>c__DisplayClass20_0.<ConvertArguments>b__0(Parameter parameter, Object frameworkArgument)
   at System.Linq.Enumerable.ZipIterator[TFirst,TSecond,TResult](IEnumerable`1 first, IEnumerable`1 second, Func`3 resultSelector)+MoveNext()
   at System.Collections.Generic.LargeArrayBuilder`1.AddRange(IEnumerable`1 items)
   at System.Collections.Generic.EnumerableHelpers.ToArray[T](IEnumerable`1 source)
   at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
   at Amazon.JSII.Runtime.Deputy.DeputyBase.<InvokeMethodCore>g__GetResult|18_0[T](<>c__DisplayClass18_0`1& )
   at Amazon.JSII.Runtime.Deputy.DeputyBase.InvokeMethodCore[T](JsiiMethodAttribute methodAttribute, Object[] arguments, Func`3 beginFunc, Func`3 invokeFunc)
   at Amazon.JSII.Runtime.Deputy.DeputyBase.InvokeInstanceMethod[T](Object[] arguments, String methodName).
Object creation stack:
  at new Intrinsic (C:\Users\username\AppData\Local\Temp\jsii-kernel-E0rbbc\node_modules\@aws-cdk\core\lib\private\intrinsic.js:20:44)
  at new PostResolveToken (C:\Users\username\AppData\Local\Temp\jsii-kernel-E0rbbc\node_modules\@aws-cdk\core\lib\util.js:72:9)
  at CfnInstance._toCloudFormation (C:\Users\username\AppData\Local\Temp\jsii-kernel-E0rbbc\node_modules\@aws-cdk\core\lib\cfn-resource.js:167:39)
  at node.addReference.resolve_1.findTokens (C:\Users\username\AppData\Local\Temp\jsii-kernel-E0rbbc\node_modules\@aws-cdk\core\lib\cfn-element.js:84:77)
  at Object.findTokens (C:\Users\username\AppData\Local\Temp\jsii-kernel-E0rbbc\node_modules\@aws-cdk\core\lib\private\resolve.js:126:13)
  at CfnInstance.prepare (C:\Users\username\AppData\Local\Temp\jsii-kernel-E0rbbc\node_modules\@aws-cdk\core\lib\cfn-element.js:84:49)
  at _wrapSandboxCode (C:\Users\username\AppData\Local\Temp\1fy2x0ks.smv\jsii-runtime.js:6498:51)
  at Kernel._wrapSandboxCode (C:\Users\username\AppData\Local\Temp\1fy2x0ks.smv\jsii-runtime.js:7131:20)
  at ret._ensureSync (C:\Users\username\AppData\Local\Temp\1fy2x0ks.smv\jsii-runtime.js:6498:25)
  at Kernel._ensureSync (C:\Users\username\AppData\Local\Temp\1fy2x0ks.smv\jsii-runtime.js:7102:20)
  at Kernel.invoke (C:\Users\username\AppData\Local\Temp\1fy2x0ks.smv\jsii-runtime.js:6497:26)
  at KernelHost.processRequest (C:\Users\username\AppData\Local\Temp\1fy2x0ks.smv\jsii-runtime.js:6191:28)
  at completeCallback (C:\Users\username\AppData\Local\Temp\1fy2x0ks.smv\jsii-runtime.js:6164:25)
  at KernelHost.callbackHandler (C:\Users\username\AppData\Local\Temp\1fy2x0ks.smv\jsii-runtime.js:6145:16)
  at KernelHost.kernel.jsii_kernel_1.Kernel.cb [as callbackHandler] (C:\Users\username\AppData\Local\Temp\1fy2x0ks.smv\jsii-runtime.js:6129:59)
  at CfnInstance.value (C:\Users\username\AppData\Local\Temp\1fy2x0ks.smv\jsii-runtime.js:6848:41)
  at Function.prepare (C:\Users\username\AppData\Local\Temp\jsii-kernel-E0rbbc\node_modules\@aws-cdk\core\lib\construct.js:89:27)
  at Function.synth (C:\Users\username\AppData\Local\Temp\jsii-kernel-E0rbbc\node_modules\@aws-cdk\core\lib\construct.js:52:14)
  at App.synth (C:\Users\username\AppData\Local\Temp\jsii-kernel-E0rbbc\node_modules\@aws-cdk\core\lib\app.js:67:52)
  at _wrapSandboxCode (C:\Users\username\AppData\Local\Temp\1fy2x0ks.smv\jsii-runtime.js:6498:51)
  at Kernel._wrapSandboxCode (C:\Users\username\AppData\Local\Temp\1fy2x0ks.smv\jsii-runtime.js:7131:20)
  at ret._ensureSync (C:\Users\username\AppData\Local\Temp\1fy2x0ks.smv\jsii-runtime.js:6498:25)
  at Kernel._ensureSync (C:\Users\username\AppData\Local\Temp\1fy2x0ks.smv\jsii-runtime.js:7102:20)
  at Kernel.invoke (C:\Users\username\AppData\Local\Temp\1fy2x0ks.smv\jsii-runtime.js:6497:26)
  at KernelHost.processRequest (C:\Users\username\AppData\Local\Temp\1fy2x0ks.smv\jsii-runtime.js:6191:28)
  at KernelHost.run (C:\Users\username\AppData\Local\Temp\1fy2x0ks.smv\jsii-runtime.js:6137:14)
  at processRequest (C:\Users\username\AppData\Local\Temp\1fy2x0ks.smv\jsii-runtime.js:6137:45)
  at KernelHost.processRequest (C:\Users\username\AppData\Local\Temp\1fy2x0ks.smv\jsii-runtime.js:6233:16)
  at KernelHost.run (C:\Users\username\AppData\Local\Temp\1fy2x0ks.smv\jsii-runtime.js:6137:14)
  at processRequest (C:\Users\username\AppData\Local\Temp\1fy2x0ks.smv\jsii-runtime.js:6137:45)
  at KernelHost.processRequest (C:\Users\username\AppData\Local\Temp\1fy2x0ks.smv\jsii-runtime.js:6233:16)
  at KernelHost.run (C:\Users\username\AppData\Local\Temp\1fy2x0ks.smv\jsii-runtime.js:6137:14)
  at processRequest (C:\Users\username\AppData\Local\Temp\1fy2x0ks.smv\jsii-runtime.js:6137:45)
  at KernelHost.processRequest (C:\Users\username\AppData\Local\Temp\1fy2x0ks.smv\jsii-runtime.js:6233:16)
  at KernelHost.run (C:\Users\username\AppData\Local\Temp\1fy2x0ks.smv\jsii-runtime.js:6137:14)
  at processRequest (C:\Users\username\AppData\Local\Temp\1fy2x0ks.smv\jsii-runtime.js:6137:45)
  at KernelHost.processRequest (C:\Users\username\AppData\Local\Temp\1fy2x0ks.smv\jsii-runtime.js:6233:16)
  at KernelHost.run (C:\Users\username\AppData\Local\Temp\1fy2x0ks.smv\jsii-runtime.js:6137:14)
  at processRequest (C:\Users\username\AppData\Local\Temp\1fy2x0ks.smv\jsii-runtime.js:6137:45)
  at KernelHost.processRequest (C:\Users\username\AppData\Local\Temp\1fy2x0ks.smv\jsii-runtime.js:6233:16)
  at KernelHost.run (C:\Users\username\AppData\Local\Temp\1fy2x0ks.smv\jsii-runtime.js:6137:14)
  at processRequest (C:\Users\username\AppData\Local\Temp\1fy2x0ks.smv\jsii-runtime.js:6137:45)
  at KernelHost.processRequest (C:\Users\username\AppData\Local\Temp\1fy2x0ks.smv\jsii-runtime.js:6233:16)
  at KernelHost.run (C:\Users\username\AppData\Local\Temp\1fy2x0ks.smv\jsii-runtime.js:6137:14)
  at processRequest (C:\Users\username\AppData\Local\Temp\1fy2x0ks.smv\jsii-runtime.js:6137:45)
  at KernelHost.processRequest (C:\Users\username\AppData\Local\Temp\1fy2x0ks.smv\jsii-runtime.js:6233:16)
  at KernelHost.run (C:\Users\username\AppData\Local\Temp\1fy2x0ks.smv\jsii-runtime.js:6137:14)
  at processRequest (C:\Users\username\AppData\Local\Temp\1fy2x0ks.smv\jsii-runtime.js:6137:45)
  at KernelHost.processRequest (C:\Users\username\AppData\Local\Temp\1fy2x0ks.smv\jsii-runtime.js:6233:16)
  at KernelHost.run (C:\Users\username\AppData\Local\Temp\1fy2x0ks.smv\jsii-runtime.js:6137:14)
  at processRequest (C:\Users\username\AppData\Local\Temp\1fy2x0ks.smv\jsii-runtime.js:6137:45)
  at KernelHost.processRequest (C:\Users\username\AppData\Local\Temp\1fy2x0ks.smv\jsii-runtime.js:6233:16)
  at KernelHost.run (C:\Users\username\AppData\Local\Temp\1fy2x0ks.smv\jsii-runtime.js:6137:14)
  at processRequest (C:\Users\username\AppData\Local\Temp\1fy2x0ks.smv\jsii-runtime.js:6137:45)
  at KernelHost.processRequest (C:\Users\username\AppData\Local\Temp\1fy2x0ks.smv\jsii-runtime.js:6233:16)
  at KernelHost.run (C:\Users\username\AppData\Local\Temp\1fy2x0ks.smv\jsii-runtime.js:6137:14)
  at processRequest (C:\Users\username\AppData\Local\Temp\1fy2x0ks.smv\jsii-runtime.js:6137:45)
  at promise.then.val (C:\Users\username\AppData\Local\Temp\1fy2x0ks.smv\jsii-runtime.js:6218:21)
   at Amazon.JSII.Runtime.Services.Client.TryDeserialize[TResponse](String responseJson)
   at Amazon.JSII.Runtime.Services.Client.ReceiveResponse[TResponse]()
   at Amazon.JSII.Runtime.Services.Client.TryDeserialize[TResponse](String responseJson)
   at Amazon.JSII.Runtime.Services.Client.ReceiveResponse[TResponse]()
   at Amazon.JSII.Runtime.Deputy.DeputyBase.<InvokeMethodCore>g__GetResult|18_0[T](<>c__DisplayClass18_0`1& )
   at Amazon.JSII.Runtime.Deputy.DeputyBase.InvokeMethodCore[T](JsiiMethodAttribute methodAttribute, Object[] arguments, Func`3 beginFunc, Func`3 invokeFunc)
   at Amazon.JSII.Runtime.Deputy.DeputyBase.InvokeInstanceMethod[T](Object[] arguments, String methodName)
   at Amazon.CDK.CfnElement.Prepare()
@McDoit McDoit added the needs-triage This issue or PR still needs to be triaged. label Aug 15, 2019
@paul42
Copy link

paul42 commented Aug 15, 2019

looks very similar to another issue filed: #3244

@NGL321 NGL321 added duplicate This issue is a duplicate. and removed needs-triage This issue or PR still needs to be triaged. labels Aug 15, 2019
@NGL321
Copy link
Contributor

NGL321 commented Aug 15, 2019

Confirmed duplicate and linked. Closing now

@NGL321 NGL321 closed this as completed Aug 15, 2019
RomainMuller pushed a commit to aws/jsii that referenced this issue Sep 18, 2019
…telisense docs, set target to netcoreapp2.1 (#772)

This PR fixes various issues due to how we convert collection elements, and how the type reference is passed when converting.


These two issues are similar and are due to nested Arrays of object not being casted properly:
Fixes aws/aws-cdk#3244
Fixes aws/aws-cdk#3672
Added a unit test to cover the case

This issue is due to Maps of Arrays of Anys not being casted properly:
Fixes aws/aws-cdk#3813 
Added a unit test to cover the case

Also added support for xml documentation which is now added to the NuGet packages and should allow intellisense to provide in IDE help:
Fixes #749
Fixes aws/aws-cdk#1846

Migrated the target framework to netcoreapp2.1 instead of netstandard2.0:
Fixes #714
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue is a duplicate.
Projects
None yet
3 participants