Significance of aws_eip_association resource in Terraform.

Significance of aws_eip_association resource in Terraform.

Hello Folks, in this article we will discuss the significance of resource:aws_eip_association.Here we will understand the significance of resource using two cases first without using dedicated resource and second with dedicated resource .

Case 1 : Without using a dedicated resource: aws_eip_association.

Consider you are hosting a website on AWS EC2 server with DNS pointing to Elastic IP. you created EC2 instance and Elastic IP resource through Terraform, which would assign Elastic IP to EC2 instance by direct association.

Now as Terraform handles dependencies on its own in case you want to update EC2 instance resource by default Terraform will destroy first and recreate instance . This would also trigger destruction and recreation on Elastic IP as it is inherently dependent on EC2 instance(terraform internal dependency).


Article content
Associating elastic IP directly to the instance without using resource


Now this update of Elastic IP resource will lead to the loss of the previous IP address which your DNS was pointing to. In a real-world production environment, it’s a Nightmare. To Save us from landing in this situation a separate Resource aws_eip_association is essential.



Case 2: Using Resource aws_eip_association.

Creating separate association resource decouples dependency(between EC2 and Elastic IP)which otherwise Terraform was managing internally.

So in this second case even if EC2 state gets refreshed the newly created EC2 instance will automatically get assigned the previous Elastic IP as we have decoupled dependency and Elastic IP resource is retained and also your DNS entry remains the same and points to a new server.


Article content
using eip_association resource.


In this way using dedicated block resource aws_eip_association you don’t lose your Elastic IP on refresh of terraform state.


Aakib Khan

Cloud computing | AWS | GCP | Azure | DevOps | 31k+ LinkedIn |Kubernetes | Docker| Terraform | Jenkins | 5 million+ impressions

1y

Very useful

Like
Reply
Pramod Sakhare

Cloud Engineer at Hitachi Digital Services | DevOps | AWS Certified Solutions Architect

1y

Good one..Jay Dhamale

Like
Reply

To view or add a comment, sign in

More articles by Jay Dhamale

Insights from the community

Others also viewed

Explore topics