I have struggled for a long time, I can see how it works with regular terraform, but don’t know how to do it with CDK. I would be grateful if I can get some help here.
so far, I have code:
var zoneIterator = TerraformIterator.FromList(availabilityZones.Names);
var subnets = new Subnet(this,
$"private-subnets", new SubnetConfig()
{
ForEach = zoneIterator,
AvailabilityZone = Token.AsString(zoneIterator.Value),
CidrBlock = FnGenerated.Cidrsubnet(defaultVpc.CidrBlock, 4,
startNetNum +
Token.AsNumber(FnGenerated.Index(availabilityZones.Names, Token.AsString(zoneIterator.Value)))),
VpcId = defaultVpc.Id,
Tags = config.Tags
});
var subnetsIds = TerraformIterator.FromResources(subnets);
var endpoint = new VpcEndpoint(this, "app-runner-endpoint", new VpcEndpointConfig()
{
VpcId = defaultVpc.Id,
ServiceName = $"com.amazonaws.{config.EnvironmentVariables.AwsRegion}.apprunner.requests",
SubnetIds = Token.AsList(subnetsIds.PluckProperty("id"))
});
With this code, I got error when validating the stack with ShouldBeValidTerraform
test:
“Could not infer JSII type for .NET type ‘_Proxy’ (Parameter ‘type’)”
The problem bit is: SubnetIds = subnetsIds.GetList(“id”), commenting out the line passes the test.
Thank you!
Rex