希望你今天过得愉快。
我有以下vpc:
VPC创建
self.vpc = ec2.Vpc(self, 'VPN',
cidr = '10.0.0.0/16',
max_azs = 1,
enable_dns_hostnames = True,
enable_dns_support = True,
# configuration will create 2 subnets in a single AZ.
subnet_configuration=[
ec2.SubnetConfiguration(
name = 'Public-Subnet',
subnet_type = ec2.SubnetType.PUBLIC,
cidr_mask = 20,
),
ec2.SubnetConfiguration(
name = 'Private-Subnet',
subnet_type = ec2.SubnetType.PRIVATE_WITH_NAT,
cidr_mask = 20
)
],
nat_gateways = 1,
nat_gateway_subnets=ec2.SubnetSelection(subnet_group_name="Public-Subnet"),
nat_gateway_provider=ec2.NatProvider.gateway(eip_allocation_ids=[elastic_ip_id]),
)我想用IPAM分配cidr,我已经创建了一个堆栈来创建池:
Ipam创建
cfn_iPAM = ec2.CfnIPAM(self,"MyCfnIPAM",description="description",description=)
# Top level ipam pool creation used by accounts or regions
cfn_Top_IpamPool = ec2.CfnIPAMPool(self, "TOP-CfnIPAMPool",
address_family="ipv4",
ipam_scope_id=cfn_iPAM.attr_private_default_scope_id,
auto_import=False,
description="top-level-pool",
locale="None",
provisioned_cidrs=[ec2.CfnIPAMPool.ProvisionedCidrProperty(
cidr=cidr_range
)],
publicly_advertisable=False,
)
# region level ipam pool used by regions
cfn_Region_iPAMPool = ec2.CfnIPAMPool(self, "Local-CfnIPAMPool",
address_family="ipv4",
ipam_scope_id=cfn_iPAM.attr_private_default_scope_id,
auto_import=False,
description="region-level-pool",
locale=self.region,
provisioned_cidrs=[ec2.CfnIPAMPool.ProvisionedCidrProperty(
cidr=region_cidr_range
)],
publicly_advertisable=False,
source_ipam_pool_id=cfn_Top_IpamPool.source_ipam_pool_id,
)
cfn_iPAMAllocation = ec2.CfnIPAMAllocation(self, "MyCfnIPAMAllocation",
ipam_pool_id=cfn_Top_IpamPool.attr_ipam_pool_id,
)主要问题是如何在ec2.vpc中使用这个池,我在CfnVpc中发现它是一个参数,但是我想在ec2.vpc中使用它,因为我有依赖于它的所有堆栈资源,就像VPnendpoint natgateway子网.我不想重复这一切,因为ec2.vcp中没有关于ipamPool id的任何参数。
谢谢你的帮助
发布于 2022-08-01 09:29:46
我可能已经找到了解决这个问题的方法,我的想法是利用ipam池中的自动导入选项。
1-使用ipam池id创建临时的L1 vpc,例如分配10.0.0.0/16
2-部署tmp vcp堆栈
3-用cidr输出获取vpc的cidr并将其存储在文件cidr.txt中。
4-销毁tm vpc堆栈以释放ipam中的分配。
5-在变量vpc_cidr中读取app.py中的文件,并将其作为参数传递到最终的vpc堆栈中。
6-使用cidr参数创建最终的L2 vpc vpc_cidr
7-对另一个vpc重复相同的步骤,而无需等待发布(几分钟后,ipam将自动将前一个vpc附加到没有重叠的->兼容的分配中)
注意:为了确保tmp vpc的分配考虑到其他ipam分配,并避免在分配为空或不完整时附加它,即使这种情况很少,我们可以在bash脚本中使用此检查:
aws ec2 get-ipam-pool-allocations --ipam-pool-id $(<ipamid) | grep $(<cidr2.txt) | cut -d\" -f4 | tr -d "\n" > check;
while [[ $(<cidr2.txt) != $(<check) ]]; do echo "waiting for allocation in ipam..."; sleep 5; done;
希望能帮助或改进在ec2.vpc中直接使用ipam param :)
https://stackoverflow.com/questions/72885600
复制相似问题