Home > front end >  How to parse ingress object in cdktf security group?
How to parse ingress object in cdktf security group?

Time:11-25

Problem Unable to create security group rules in aws using CDKTF

Code

import cdktf_cdktf_provider_aws.security_group as SecurityGroup_
self.security_group_ = SecurityGroup_.SecurityGroup(self.scope_object, id_=self.id, name=self.name, vpc_id=self.vpc_id, ingress=[{"from_port":"3306","to_port":"3306"}])


Error

   29:         "ingress": [
   30:           {
   31:             "cidr_blocks": null,
   32:             "description": "smartstack_dependency",
   33:             "from_port": null,
   34:             "ipv6_cidr_blocks": null,
   35:             "prefix_list_ids": null,
   36:             "protocol": "tcp",
   37:             "security_groups": null,
   38:             "self": null,
   39:             "to_port": null
   40:           }
   41:         ],

 The argument "ingress.0.to_port" is required, but no definition was found.

Tried the following code-

import cdktf_cdktf_provider_aws.security_group as SecurityGroup_
self.security_group_ = SecurityGroup_.SecurityGroup(self.scope_object, id_=self.id, name=self.name, vpc_id=self.vpc_id, ingress=[{"from_port":"3306","to_port":"3306"}])

CodePudding user response:

Change the code to

self.security_group_ = SecurityGroup_.SecurityGroup(
self.scope_object, 
id_=self.id, 
name=self.name, 
vpc_id=self.vpc_id, 
ingress=[SecurityGroup_.SecurityGroupIngress(from_port=3306,to_port=3306, "security_groups":['test-sg'])])

Ingress takes a list of class obj SecurityGroupIngress

  • Related