File tree Expand file tree Collapse file tree 5 files changed +45
-3
lines changed Expand file tree Collapse file tree 5 files changed +45
-3
lines changed Original file line number Diff line number Diff line change @@ -131,9 +131,12 @@ cloud_providers:
131
131
size: s-1vcpu-1gb
132
132
image: " ubuntu-18-04-x64"
133
133
ec2:
134
- # Change the encrypted flag to "true" to enable AWS volume encryption, for encryption of data at rest.
135
- # Warning: the Algo script will take approximately 6 minutes longer to complete.
134
+ # Change the encrypted flag to "true" to enable AWS volume encryption, for encryption of data at rest.
135
+ # Warning: the Algo script will take approximately 6 minutes longer to complete.
136
136
encrypted: false
137
+ # Set use_existing_eip to "true" if you want to use a pre-allocated Elastic IP
138
+ # Additional prompt will be raised to determine which IP to use
139
+ use_existing_eip: true
137
140
size: t2.micro
138
141
image:
139
142
name: " ubuntu-bionic-18.04"
Original file line number Diff line number Diff line change @@ -5,3 +5,4 @@ ec2_vpc_nets:
5
5
cidr_block : 172.16.0.0/16
6
6
subnet_cidr : 172.16.254.0/23
7
7
ec2_venv : " {{ playbook_dir }}/configs/.venvs/aws"
8
+ existing_eip : " "
Original file line number Diff line number Diff line change @@ -11,6 +11,12 @@ Parameters:
11
11
Type : String
12
12
WireGuardPort :
13
13
Type : String
14
+ UseThisElasticIP :
15
+ Type : String
16
+ Default : ' '
17
+ Conditions :
18
+ AllocateNewEIP : !Equals [!Ref UseThisElasticIP, '']
19
+ AssociateExistingEIP : !Not [!Equals [!Ref UseThisElasticIP, '']]
14
20
Resources :
15
21
VPC :
16
22
Type : AWS::EC2::VPC
@@ -175,13 +181,22 @@ Resources:
175
181
176
182
ElasticIP :
177
183
Type : AWS::EC2::EIP
184
+ Condition : AllocateNewEIP
178
185
Properties :
179
186
Domain : vpc
180
187
InstanceId : !Ref EC2Instance
181
188
DependsOn :
182
189
- EC2Instance
183
190
- VPCGatewayAttachment
184
191
192
+ ElasticIPAssociation :
193
+ Type : AWS::EC2::EIPAssociation
194
+ Condition : AssociateExistingEIP
195
+ Properties :
196
+ AllocationId : !Ref UseThisElasticIP
197
+ InstanceId : !Ref EC2Instance
198
+
199
+
185
200
Outputs :
186
201
ElasticIP :
187
- Value : !Ref ElasticIP
202
+ Value : !GetAtt [EC2Instance, PublicIp]
Original file line number Diff line number Diff line change 12
12
PublicSSHKeyParameter : " {{ lookup('file', SSH_keys.public) }}"
13
13
ImageIdParameter : " {{ ami_image }}"
14
14
WireGuardPort : " {{ wireguard_port }}"
15
+ UseThisElasticIP : " {{ existing_eip }}"
15
16
tags :
16
17
Environment : Algo
17
18
register : stack
Original file line number Diff line number Diff line change 53
53
[{{ default_region }}]
54
54
register : _algo_region
55
55
when : region is undefined
56
+
57
+ - block :
58
+ - name : Get existing available Elastic IPs
59
+ ec2_eip_facts :
60
+ register : raw_eip_addresses
61
+
62
+ - set_fact :
63
+ available_eip_addresses : " {{ raw_eip_addresses.addresses | selectattr('association_id', 'undefined') | list }}"
64
+
65
+ - pause :
66
+ prompt : >-
67
+ What Elastic IP would you like to use?
68
+ {% for eip in available_eip_addresses %}
69
+ {{ loop.index }}. {{ eip['public_ip'] }}
70
+ {% endfor %}
71
+
72
+ Enter the number of your desired Elastic IP
73
+ register : _use_existing_eip
74
+
75
+ - set_fact :
76
+ existing_eip : " {{ available_eip_addresses[_use_existing_eip.user_input | int -1 ]['allocation_id'] }}"
77
+ when : cloud_providers.ec2.use_existing_eip
You can’t perform that action at this time.
0 commit comments