コード例 #1
0
ファイル: CustomVpc.cs プロジェクト: cbossie/cdk-vpc
        public CustomVpc(Construct scope, string id, string cidr)
            : base(scope, id)
        {
            SubnetConfiguration privateSubnetConfig = new SubnetConfiguration
            {
                CidrMask   = 26,
                SubnetType = SubnetType.PRIVATE,
                Name       = "privateSubnet"
            };

            SubnetConfiguration publicSubnetConfig = new SubnetConfiguration
            {
                CidrMask   = 26,
                SubnetType = SubnetType.PUBLIC,
                Name       = "publicSubnet"
            };

            VpcProps props = new VpcProps
            {
                Cidr = cidr,
                DefaultInstanceTenancy = DefaultInstanceTenancy.DEFAULT,
                MaxAzs = 99,
                SubnetConfiguration = new ISubnetConfiguration[] {
                    privateSubnetConfig,
                    publicSubnetConfig
                },
                NatGateways        = 99,
                EnableDnsHostnames = true,
                EnableDnsSupport   = true
            };
            var vpc = new Vpc(this, id + $"{id}-vpc", props);

            this.Vpc = vpc;
        }
コード例 #2
0
        public NetworkStack(Construct parent, string id, IStackProps props) : base(parent, id, props)
        {
            var ingressSubnet = new SubnetConfiguration
            {
                Name       = "Ingress",
                SubnetType = SubnetType.PUBLIC,
                CidrMask   = 24,
            };

            var applicationSubnet = new SubnetConfiguration
            {
                Name       = "Application",
                SubnetType = SubnetType.PRIVATE,
                CidrMask   = 24,
            };

            var databaseSubnet = new SubnetConfiguration
            {
                Name       = "Database",
                SubnetType = SubnetType.ISOLATED,
                CidrMask   = 24,
            };

            Vpc = new Vpc(
                this,
                "Primary",
                new VpcProps
            {
                Cidr                = "10.1.0.0/16",
                MaxAzs              = 2,
                NatGateways         = 1,
                SubnetConfiguration = new ISubnetConfiguration[]
                {
                    ingressSubnet,
                    applicationSubnet,
                    databaseSubnet,
                },
            });

            PrintPublicSubnetIds();
            PrintPrivateSubnetIds();
            PrintIsolatedSubnetIds();
        }