简体   繁体   中英

Assigning Elastic IPs to Secondary Private IPs via SecondaryPrivateIpAddresses List Attribute

Below is a snippet of my CloudFormation template used to associate an Elastic IP Address with the primary IP of a network interface:

        "MyInterfaceSelfEipAssociation": {
        "Properties": {
            "AllocationId": "eipalloc-XXXXX",
            "NetworkInterfaceId": {
                "Ref": "MyInterface"
            },
            "PrivateIpAddress": {
                "Fn::GetAtt": [
                    "MyInterface",
                    "PrimaryPrivateIpAddress"
                ]
            }
        },
        "Type": "AWS::EC2::EIPAssociation"

I want to do the same thing for the secondary IPs on this interface, of which there are two (particular IPs I have given in a list, not assigned by AWS). ie the "PrivateIpAddresses" block of the interface looks like this:

                "PrivateIpAddresses": [
                {
                    "PrivateIpAddress": "10.X.X.XX",
                    "Primary": "true"
                },
                {
                    "PrivateIpAddress": "10.X.X.XX",
                    "Primary": "false"
                },
                {
                    "PrivateIpAddress": "10.X.X.XX",
                    "Primary": "false"
                }
            ],

I know I can access the list of secondary private IPs with the Fn:GetAtt attribute call "SecondaryPrivateIpAddresses" which will return the two secondary private IPs above to me as a list. My question is, how can I address this list in JSON - by index?

For example, if I wanted to assign a private IP to the second element in the list of secondary IPs, is it valid to do something like:

                "PrivateIpAddress": {
                "Fn::GetAtt": [
                    "Bigip1subnet1Az1Interface",
                    "SecondaryPrivateIpAddresses[1]"
                ]
            }

How can I achieve this? I feel like it should be straightforward but I'm not clear on how to do this in JSON.

Use the Fn::Select intrinsic function to return a single object from a list of objects by index:

        "PrivateIpAddress": {
          "Fn::Select": [
            1,
            { "Fn::GetAtt": [
                "Bigip1subnet1Az1Interface",
                "SecondaryPrivateIpAddresses"
            ]}
          ]
        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM