I'm trying to add a private, isolated subnet to my existing VPC using the CDK. Here are the old and new configurations.
OLD
Vpc = new Vpc(this, "vpc", new VpcProps
{
Cidr = "172.0.3.0/24",
DefaultInstanceTenancy = DefaultInstanceTenancy.DEFAULT,
EnableDnsHostnames = true,
EnableDnsSupport = true,
NatGateways = 1,
MaxAzs = 2,
SubnetConfiguration = new ISubnetConfiguration[]
{
new SubnetConfiguration{ SubnetType = SubnetType.PUBLIC, CidrMask = 26, Name = "public-" },
new SubnetConfiguration{ SubnetType = SubnetType.PRIVATE_WITH_EGRESS, CidrMask = 26, Name = "private-" }
}
});
NEW
Vpc = new Vpc(this, "vpc", new VpcProps
{
Cidr = "172.0.3.0/24",
DefaultInstanceTenancy = DefaultInstanceTenancy.DEFAULT,
EnableDnsHostnames = true,
EnableDnsSupport = true,
NatGateways = 1,
MaxAzs = 2,
SubnetConfiguration = new ISubnetConfiguration[]
{
new SubnetConfiguration{ SubnetType = SubnetType.PUBLIC, CidrMask = 26, Name = "public-" },
new SubnetConfiguration{ SubnetType = SubnetType.PRIVATE_WITH_EGRESS, CidrMask = 26, Name = "private-" },
new SubnetConfiguration{ SubnetType = SubnetType.PRIVATE_ISOLATED, CidrMask = 26, Name = "isolated" }
}
});
However, when I make this change and then run the cdk diff command I get an error that isn't telling me what's going on, I think there is a bug in the AWS CDK tool, because it looks like it's failing when trying to deserialize the error message for display.
Unhandled exception. Newtonsoft.Json.JsonSerializationException: Error converting value "Error" to type 'Amazon.JSII.JsonModel.Api.Response.ErrorResponseName'. Path 'name'.
---> System.ArgumentException: Requested value 'Error' was not found.
at Newtonsoft.Json.Utilities.EnumUtils.ParseEnum(Type enumType, NamingStrategy namingStrategy, String value, Boolean disallowNumber)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.EnsureType(JsonReader reader, Object value, CultureInfo culture, JsonContract contract, Type targetType)
--- End of inner exception stack trace ---
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.EnsureType(JsonReader reader, Object value, CultureInfo culture, JsonContract contract, Type targetType)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.ResolvePropertyAndCreatorValues(JsonObjectContract contract, JsonProperty containerProperty, JsonReader reader, Type objectType)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObjectUsingCreatorWithParameters(JsonReader reader, JsonObjectContract contract, JsonProperty containerProperty, ObjectConstructor`1 creator, String id)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateNewObject(JsonReader reader, JsonObjectContract objectContract, JsonProperty containerMember, JsonProperty containerProperty, String id, Boolean& createdFromNonDefaultCreator)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
at Newtonsoft.Json.JsonSerializer.Deserialize(JsonReader reader, Type objectType)
at Newtonsoft.Json.Linq.JToken.ToObject(Type objectType, JsonSerializer jsonSerializer)
at Newtonsoft.Json.Linq.JToken.ToObject(Type objectType)
at Newtonsoft.Json.Linq.JToken.ToObject[T]()
at Amazon.JSII.Runtime.Services.Client.TryDeserialize[TResponse](String responseJson)
at Amazon.JSII.Runtime.Services.Client.ReceiveResponse[TResponse]()
at Amazon.JSII.Runtime.Services.Client.Send[TRequest,TResponse](TRequest requestObject)
at Amazon.JSII.Runtime.Services.Client.Create(CreateRequest request)
at Amazon.JSII.Runtime.Services.Client.Create(String fullyQualifiedName, Object[] arguments, Override[] overrides, String[] interfaces)
at Amazon.JSII.Runtime.Deputy.DeputyBase..ctor(DeputyProps props)
at Constructs.Construct..ctor(DeputyProps props)
at Amazon.CDK.Resource..ctor(DeputyProps props)
at Amazon.CDK.AWS.EC2.Vpc..ctor(Construct scope, String id, IVpcProps props)
I'm not sure how I can find out what the cause of my error is, but if I remove that new subnet configuration the error goes away so I know it's related. Does someone know what the underlying error might be here or how I can get the CDK to tell me the real error?
BTW, I have noticed that the Cidr is a /24 whereas my CidrMask is set to 26 but I thought I wouldn't change this yet since that configuration is what is already working and active in the environment.
Thanks
OK, I figured out what the problem was and it had everything to do with how rusty I am with configuring subnets. Essentially, my address range wasn't big enough to contain another subnet. I never got a legitimate error from the CDK but after researching subnet address ranges and fixing mine to support enough hosts for my subnets my problem went away. Here's the new, working configuration.
Vpc = new Vpc(this, "copilot-vpc", new VpcProps
{
Cidr = "172.0.3.0/16",
DefaultInstanceTenancy = DefaultInstanceTenancy.DEFAULT,
EnableDnsHostnames = true,
EnableDnsSupport = true,
NatGateways = 1,
MaxAzs = 2,
SubnetConfiguration = new ISubnetConfiguration[]
{
new SubnetConfiguration{ SubnetType = SubnetType.PUBLIC, CidrMask = 24, Name = "public-" },
new SubnetConfiguration{ SubnetType = SubnetType.PRIVATE_WITH_EGRESS, CidrMask = 24, Name = "private-" },
new SubnetConfiguration{ SubnetType = SubnetType.PRIVATE_ISOLATED, CidrMask = 24, Name = "isolated" }
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With