Search code examples
troposphere

How do you add a "PrivateIpAddresses" to a Network interface


I am looking for the output of the troposphere to look like this(json). I could not find any examples to point me in the right direction at all. And in the future if I come across similar issues, is there any documentation I should refer to in particular?

"NetworkInterfaces": [
          {
            "DeleteOnTermination": "true",
            "Description": "Primary network interface",
            "DeviceIndex": 0,
            "SubnetId": "subnet-yolo",
            "PrivateIpAddresses": [
              {
                "PrivateIpAddress": "xxx.xx.xx.xx",
                "Primary": "true"
              }
            ],
            "GroupSet": [
              "xxxxxx",
              "yyyyyy"
            ]
          }
        ]

Solution

  • Answer was pretty basic. First we need to make a sample_ip like so

    sample_ip = template.add_parameter(ec2.PrivateIpAddressSpecification(
        "PrivateIpAddress",
        Primary="true",
        PrivateIpAddress="172.168.1.1"
    ))
    

    Then do this:

    PrivateIpAddresses=[Ref(sample_ip)]
    

    I'll keep this here in case some uber beginner like me is not able to do this on his/her own.