gpt4 book ai didi

python - 如何解析 cdktf 安全组中的入口对象?

转载 作者:行者123 更新时间:2023-12-05 03:16:40 31 4
gpt4 key购买 nike

问题 无法使用 CDKTF 在 aws 中创建安全组规则

代码

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"}])


错误

   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.

尝试了以下代码-

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"}])

最佳答案

将代码改为

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 需要一个 list 类 obj SecurityGroupIngress

关于python - 如何解析 cdktf 安全组中的入口对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74559553/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com