I have a CloudFormation template which adds OpenVPN to an existing VPC and requires an Elastic IP allocation ID as a parameter. It also adds the public IP address from the same Elastic IP to the OpenVPN instance configuration (in it's UserData
section).
I've currently implemented this as 2 parameters (using made-up defaults) i.e.
Parameters:
ElasticIpAddress:
Description: >-
IP Address of an Elastic IP.
Type: String
Default: 53.176.52.215
ElasticIpAllocationId:
Description: >-
Allocation id of the same Elastic IP to associate OpenVPN server with.
Type: String
Default: eipalloc-f2013ba5
...
NOTE - Both of these must point to the same ElasticIP in AWS!
The ElasticIpAddress
parameter is used when creating the OpenVPN instance in a AWS::EC2::Instance
section as follows: -
openVPN:
Type: 'AWS::EC2::Instance'
Properties:
Tags:
- Key: Name
Value: openVPN server
UserData:
Fn::Base64: !Sub |
public_hostname=${ElasticIpAddress}
admin_user=${OpenVPNASAdminUser}
...
... and the ElasticIpAllocationId
get used in an AWS::EC2::EIPAssociation
section ...
IPAssoc:
Type: 'AWS::EC2::EIPAssociation'
Properties:
AllocationId: !Ref ElasticIpAllocationId
InstanceId: !Ref openVPN
DependsOn: openVPN
It seems very redundant to have (a) allocation ID and (b) IP address of the same Elastic IP!
My main question is - does a function exists which: -
- Retrieve the IP address from an Elastic IP allocation Id or
- Retrieve an allocation Id from an IP address of an elastic IP?
My gut feeling is that I'll have to use the CLI inside the UserData:
section of the instance and use AWS CLI commands - not sure how nicely that will work with the OpenVPN AMI as it currently just takes OpenVPN specific configuration.
Any advice is appreciated!