Reputation: 1
When I use AWS Adapter in CDKTF and create PublicSubnet, the following error occurs and I cannot deploy. I can deploy with no problem using PrivateSubnet. Perhaps there is a problem with the route to the Internet gateway in the route table, as the error message says.
Please let me know the solution.
│ Error: Invalid index
│
│ on cdk.tf.json line 53, in resource.aws_route.adapter_VpcPublicSubnet1DefaultRoute3DA9E72A_5BE14C48 (adapter/VpcPublicSubnet1DefaultRoute3DA9E72A):
│ 53: "gateway_id": "${jsondecode(aws_cloudcontrolapi_resource.adapter_VpcIGWD7BA715C_6AEEE500 (adapter/VpcIGWD7BA715C).properties)[\"Ref\"]}",
│ ├────────────────
│ │ aws_cloudcontrolapi_resource.adapter_VpcIGWD7BA715C_6AEEE500 (adapter/VpcIGWD7BA715C).properties is "{\"InternetGatewayId\":\"igw-05191b9e55b006ed3\",\"Tags\":[]}"
│
│ The given key does not identify an element in this collection value.
The actual code is as follows
import { Construct } from "constructs";
import { App, TerraformStack, S3Backend } from "cdktf";
import { AwsProvider } from "@cdktf/provider-aws/lib/provider";
import { AwsTerraformAdapter } from "@cdktf/aws-cdk";
import { Vpc, IpAddresses, SubnetType} from 'aws-cdk-lib/aws-ec2';
class MyStack extends TerraformStack {
constructor(scope: Construct, id: string) {
super(scope, id);
new AwsProvider(this, "AWS", {
region: "us-east-1",
});
const awsAdapter = new AwsTerraformAdapter(this, "adapter");
const vpc = new Vpc(awsAdapter, 'Vpc', {
vpcName: 'cdktf-test-vpc',
ipAddresses: IpAddresses.cidr('10.1.0.0/16'),
maxAzs: 1,
subnetConfiguration: [
{
cidrMask: 24,
name: 'Public',
subnetType: SubnetType.PUBLIC,
},
],
});
}
}
const app = new App();
const stack = new MyStack(app, "cdktf");
new S3Backend(stack, {
bucket: "tfstate-bucket",
key: "cdktf.tfstate",
region: "us-east-1",
});
app.synth();
Upvotes: 0
Views: 66