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

cdk.Output should validate that it is non-empty #2012

Closed
mahe-work opened this issue Mar 14, 2019 · 1 comment · Fixed by #2219 · May be fixed by MechanicalRock/account-reaper#6
Closed

cdk.Output should validate that it is non-empty #2012

mahe-work opened this issue Mar 14, 2019 · 1 comment · Fixed by #2219 · May be fixed by MechanicalRock/account-reaper#6
Assignees
Labels
@aws-cdk/core Related to core CDK functionality bug This issue is a bug. effort/small Small work item – less than a day of effort

Comments

@mahe-work
Copy link

mahe-work commented Mar 14, 2019

When trying to create a VpcNetwork without VpnGateway, VpcNetworks import props cannot be exported.

cdk deploy output:

cdk  deploy 
vpc-stack: deploying...
vpc-stack: creating CloudFormation changeset...

 ❌  vpc-stack failed: ValidationError: Template format error: Every Outputs member must contain a Value object
Template format error: Every Outputs member must contain a Value object

vpc.ts:

import cdk = require("@aws-cdk/cdk");
import ec2 = require("@aws-cdk/aws-ec2");

export interface VPCStackProps extends cdk.StackProps {
    cidr: string,
}

export class VPCStack extends cdk.Stack {
    public readonly exports: ec2.VpcNetworkImportProps;

    constructor(scope: cdk.App, id: string, props: VPCStackProps) {
        super(scope, id)
        const vpc = new ec2.VpcNetwork(this, "vpc", {
            cidr: props.cidr,
            subnetConfiguration: [
                {
                    cidrMask: 26,
                    name: "Public",
                    subnetType: ec2.SubnetType.Public
                },
                {
                    cidrMask: 26,
                    name: "Private",
                    subnetType: ec2.SubnetType.Private
                },
                {
                    cidrMask: 27,
                    name: "DB",
                    subnetType: ec2.SubnetType.Isolated
                },
            ],
            vpnGateway: false
        })

        this.exports = vpc.export();
    }
}

cfn template Outputs section from cdk synth:

Outputs:
  vpcPublicSubnetIDs7CDCF73A:
    Value:
      Fn::Join:
        - ","
        - - Ref: vpcPublicSubnet1Subnet2E65531E
          - Ref: vpcPublicSubnet2Subnet009B674F
          - Ref: vpcPublicSubnet3Subnet11B92D7C
    Export:
      Name: vpc-stack:vpcPublicSubnetIDs7CDCF73A
  vpcPrivateSubnetIDs121CC6B5:
    Value:
      Fn::Join:
        - ","
        - - Ref: vpcPrivateSubnet1Subnet934893E8
          - Ref: vpcPrivateSubnet2Subnet7031C2BA
          - Ref: vpcPrivateSubnet3Subnet985AC459
    Export:
      Name: vpc-stack:vpcPrivateSubnetIDs121CC6B5
  vpcIsolatedSubnetIDs67369DC2:
    Value:
      Fn::Join:
        - ","
        - - Ref: vpcDBSubnet1SubnetA8C3A9ED
          - Ref: vpcDBSubnet2SubnetDB39CD7E
          - Ref: vpcDBSubnet3Subnet54DAF0DD
    Export:
      Name: vpc-stack:vpcIsolatedSubnetIDs67369DC2
  vpcVpcIdE284377C:
    Value:
      Ref: vpcA2121C38
    Export:
      Name: vpc-stack:vpcVpcIdE284377C
  vpcVpnGatewayIdDCE6028A:
    Export:
      Name: vpc-stack:vpcVpnGatewayIdDCE6028A
@mahe-work mahe-work changed the title VpcNetwork.export creates a stack output without value if vpnGateway: false VpcNetwork.export creates a stack output without value if no vpnGateway Mar 14, 2019
@rix0rrr rix0rrr changed the title VpcNetwork.export creates a stack output without value if no vpnGateway cdk.Output should validate that it is non-empty Mar 15, 2019
@rix0rrr rix0rrr added bug This issue is a bug. @aws-cdk/core Related to core CDK functionality labels Mar 15, 2019
@rix0rrr
Copy link
Contributor

rix0rrr commented Mar 15, 2019

This is a bug that would have been caught early on if cdk.Output were to validate its properties.

I'm going to mark it as such; the fixer of this issue will have to deal with the special case of the VpcNetwork export (which should be unit tested already, so should throw once this fix is made).

@eladb eladb self-assigned this Apr 2, 2019
eladb pushed a commit that referenced this issue Apr 10, 2019
Throw an error if `value` is undefined when defining a `CfnOutput`.

Fixes #2012 such that a VPC can be exported without a VPN gateway (there
is already unit test coverage).
eladb pushed a commit that referenced this issue Apr 10, 2019
Throw an error if `value` is undefined when defining a `CfnOutput`.

Fixes #2012 such that a VPC can be exported without a VPN gateway (there
is already unit test coverage).
@fulghum fulghum added the effort/small Small work item – less than a day of effort label Apr 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/core Related to core CDK functionality bug This issue is a bug. effort/small Small work item – less than a day of effort
Projects
None yet
4 participants