云形成:一个ENI上有2个EIP,2个PIP

时间:2017-06-01 15:35:29

标签: amazon-ec2 amazon-cloudformation elastic-ip

获取“EIP不会稳定”错误。代码如下......可能是代码,或者可能是cloudformation bug。

我想在接口上附加2个EIP,一个到主要私有IP,一个到辅助私有IP。当我从控制台进行操作时,它可以正常工作。

如果我注释掉“VIP”或“EIP”代码,我还可以成功添加2个私有IP和单个EIP连接到主要或辅助私有IP。一个人可以工作,但不能两个人一起工作。

  #ServerOne.
  ServerOne:
    Type: AWS::EC2::Instance
    Properties:
      AvailabilityZone: !Ref AvailabilityZoneA
      DisableApiTermination: !Ref disableInstanceDeletion
      ImageId: !FindInMap [ RegionMap, !Ref "AWS::Region", ServerOne ]
      InstanceType: !FindInMap [ InstanceSizingMap, !Ref StackSizing, ServerOne ]
      EbsOptimized: !FindInMap [ InstanceSizingMap, !Ref StackSizing, ebsOptimizedInstances ]
      BlockDeviceMappings: 
          - DeviceName: "/dev/sda1"
            Ebs: 
              DeleteOnTermination: !FindInMap [ InstanceSizingMap, !Ref StackSizing, DeleteOnTermination ]
      KeyName: !Ref SSHKeyName
      Monitoring: 'false'
      NetworkInterfaces:
        -
          NetworkInterfaceId: !Ref ServerOneInterface
          DeviceIndex: 0
      Tags:
      - Key: Name
        Value: ServerOne
      - Key: Role
        Value: Infrastructure

        # ServerOne Server Network.  2 Private IPs, 2 EIPs all on one interface.
          ServerOneEIP:
            Type: AWS::EC2::EIP
            DependsOn: IGW
            Properties:
              InstanceId: !Ref ServerOne
              Domain: vpc

          ServerOneVIP:
            Type: AWS::EC2::EIP
            DependsOn: IGW
            Properties:
              InstanceId: !Ref ServerOne
              Domain: vpc

          ServerOneEIPAssociation:
            Type: AWS::EC2::EIPAssociation
            DependsOn: ServerOneVIPAssociation
            Properties:
              AllocationId: !GetAtt ServerOneEIP.AllocationId
              NetworkInterfaceId: !Ref ServerOneInterface
              PrivateIpAddress: !GetAtt ServerOneInterface.PrimaryPrivateIpAddress

          ServerOneVIPAssociation:
            Type: AWS::EC2::EIPAssociation
            DependsOn: IGW
            Properties:
              AllocationId: !GetAtt ServerOneVIP.AllocationId
              NetworkInterfaceId: !Ref ServerOneInterface
              PrivateIpAddress: !Select [ 0, !GetAtt ServerOneInterface.SecondaryPrivateIpAddresses ]

          ServerOneInterface:
            Type: AWS::EC2::NetworkInterface
            Properties:
              SubnetId: !Ref PublicSubnetA
              SecondaryPrivateIpAddressCount: 1
              Description: ServerOne Network Interface
              GroupSet: [
                !Ref PuppetClientSG ]
        # ServerOne is doing NAT, so Source/Dest is false.
              SourceDestCheck: false

1 个答案:

答案 0 :(得分:1)

代码如下。

---
Parameters:
Subnet:
Description: ID of the Subnet the instance should be launched in, this will 
link the instance to the same VPC.
Type: List<AWS::EC2::Subnet::Id>
Resources:
EIP1:
    Type: AWS::EC2::EIP
Properties:
  Domain: VPC
EIP2:
Type: AWS::EC2::EIP
Properties:
  Domain: VPC
Association1:
  Type: AWS::EC2::EIPAssociation
DependsOn:
- ENI
- EIP1
Properties:
  AllocationId:
    Fn::GetAtt:
    - EIP1
    - AllocationId
  NetworkInterfaceId:
    Ref: ENI
  PrivateIpAddress:
    Fn::GetAtt:
    - ENI
    - PrimaryPrivateIpAddress
Association2:
Type: AWS::EC2::EIPAssociation
DependsOn:
- ENI
- EIP2
Properties:
  AllocationId:
  Fn::GetAtt:
    - EIP2
    - AllocationId
  NetworkInterfaceId:
    Ref: ENI
  PrivateIpAddress:
    Fn::Select:
    - '0'
    - Fn::GetAtt:
      - ENI
      - SecondaryPrivateIpAddresses
ENI:
Type: AWS::EC2::NetworkInterface
Properties:
  SecondaryPrivateIpAddressCount: 1
  SourceDestCheck: false
  SubnetId:
    Fn::Select:
    - '0'
    - Ref: Subnet
OpenVPN:
    Type: AWS::EC2::Instance
    DependsOn:
    - ENI
    Properties:
    InstanceType: t2.micro
      AvailabilityZone: us-east-2a
      NetworkInterfaces:
      - NetworkInterfaceId:
          Ref: ENI
        DeviceIndex: '0'
    ImageId: ami-8a7859ef
    KeyName: jimkey