[英]Connecting EC2 with Default VPC vs Customized VPC in AWS Terraform
[英]ec2 cloudformation template without default vpc
EC2 模板是一個基本模板,但它失敗了,因為默認 vpc 不再存在。 結果它出錯,通常會在參數默認值下設置它。
不幸的是,創建默認 VPC 不是一個選項......
如何修改它以使用特定的 VPC?
只有在弄清楚錯誤的真正含義后,我才知道我必須分配 VPC 並且不能告訴它使用“默認”
Parameters:
VPC:
Description: Testing using VPC created
Type: String
Default: vpc-8787789
Subnet:
Type: String
Default: subnet-7657657578
...
...
...
Resources:
EC2Instance:
Type: AWS::EC2::Instance
Properties:
InstanceType: !Ref 'InstanceType'
VpcId: !Ref VPC
SecurityGroups:
- !Ref 'InstanceSecurityGroup'
KeyName: !Ref 'KeyName'
ImageId: !FindInMap
- AWSRegionArch2AMI
- !Ref 'AWS::Region'
- HVM64
InstanceSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: Enable SSH access via port 22
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: '22'
ToPort: '22'
CidrIp: !Ref 'SSHLocation'
我想我想了解的是我如何修改此代碼以使用特定的 vpcid。
該錯誤很可能來自InstanceSecurityGroup
因為它沒有為VpcId
指定值。 因此,它默認為默認VPC,它不存在。 要解決此問題,請添加: VpcId: VPC
InstanceSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: Enable SSH access via port 22
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: '22'
ToPort: '22'
CidrIp: !Ref 'SSHLocation'
VpcId: !Ref VPC
將 su.net id 添加到 EC2 配置,將 VpcID 添加到安全組,您應該能夠使用非默認 VPC 創建 EC2 和鏈接的安全組
EC2Instance:
Type: AWS::EC2::Instance
Properties:
SubnetId: !Ref EC2SubnetID
...
InstanceSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
Vpcid: !Ref VpcId
...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.