Skip to content

Commit 2f60eea

Browse files
Merge pull request #351 from PierreBeucher/fix-aws-static-ip-deletion-on-stop
chore: do not delete AWS static IP address on stop
2 parents ae98341 + 8264e63 commit 2f60eea

1 file changed

Lines changed: 19 additions & 14 deletions

File tree

src/providers/aws/pulumi/main.ts

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -254,20 +254,6 @@ class CloudyPadEC2Instance extends pulumi.ComponentResource {
254254

255255
this.volumes.push(vol)
256256
})
257-
258-
259-
if (args.publicIpType === PUBLIC_IP_TYPE_STATIC) {
260-
this.eip = new aws.ec2.Eip(`${name}-eip`, {
261-
tags: globalTags
262-
}, commonPulumiOpts);
263-
264-
new aws.ec2.EipAssociation(`${name}-eipAssoc`, {
265-
instanceId: this.ec2Instance.id,
266-
allocationId: this.eip.id,
267-
}, commonPulumiOpts);
268-
} else if (args.publicIpType !== PUBLIC_IP_TYPE_DYNAMIC) {
269-
throw `publicIpType must be either '${PUBLIC_IP_TYPE_STATIC}' or '${PUBLIC_IP_TYPE_DYNAMIC}'`
270-
}
271257

272258
// set client-facing values
273259
this.instanceId = this.ec2Instance.id
@@ -279,6 +265,25 @@ class CloudyPadEC2Instance extends pulumi.ComponentResource {
279265
this.volumes = []
280266
}
281267

268+
// public IP must be outside of instance reation block to avoid deletion on stop
269+
if (args.publicIpType === PUBLIC_IP_TYPE_STATIC) {
270+
this.eip = new aws.ec2.Eip(`${name}-eip`, {
271+
tags: globalTags
272+
}, commonPulumiOpts);
273+
274+
// Attach IP to instance if it exists
275+
// otherwise keep IP
276+
if(this.ec2Instance){
277+
new aws.ec2.EipAssociation(`${name}-eipAssoc`, {
278+
instanceId: this.ec2Instance.id,
279+
allocationId: this.eip.id,
280+
}, commonPulumiOpts);
281+
}
282+
283+
} else if (args.publicIpType !== PUBLIC_IP_TYPE_DYNAMIC) {
284+
throw `publicIpType must be either '${PUBLIC_IP_TYPE_STATIC}' or '${PUBLIC_IP_TYPE_DYNAMIC}'`
285+
}
286+
282287
this.publicIp = this.eip ? this.eip.publicIp : this.ec2Instance?.publicIp || pulumi.output("")
283288
}
284289
}

0 commit comments

Comments
 (0)