I am currently in the process of updating my terraform configuration to newer versions. Unfortunately, we have encountered compatibility issues with our existing library that was built on older versions. In my setup, I'm importing the following:
import { SecurityGroup, SecurityGroupConfig, SecurityGroupIngress, SecurityGroupEgress } from "@cdktf/provider-aws/lib/security-group"
and then adding the ingressInput to the normalize rule array below.
_normalize_rule(rule: SecurityGroupIngress | SecurityGroupEgress) {
defaults(rule, {
description: "security group",
ipv6CidrBlocks: [],
prefixListIds: [],
securityGroups: [],
selfAttribute: false,
cidrBlocks: []
})
return rule
}
add_ingress(config: SecurityGroupIngress) {
this.ingressInput?.push(this._normalize_rule(config))
}
Upon compiling the TypeScript file into JavaScript, I encountered the following error message:
error TS2339: Property 'push' does not exist on type 'IResolvable | SecurityGroupEgress[]'.
Property 'push' does not exist on type 'IResolvable'.
It seems like a type guard is needed to handle the optional variable being of a different type. Despite trying various if statements, I continue to face the same error. It's worth noting that this file compiles without any issues on older versions. Both setups utilize strict compile options in the tsconfig.json file. Any assistance would be greatly appreciated. Thank you!