Description
When using the aws_eip
resource with aws_eip_association
for an aws_instance
, you need two terraform apply
for the state to be updated.
Hence, driftctl detects drift when there isn't.
The following fields in the state are empty after the first tf apply and get filled only after a second tf apply:
"association_id": "",
"instance": "",
"network_interface": "",
"private_dns": null,
"private_ip": "",
Here is the fake positive drift detected:
Found drifted resources:
- eipalloc-0e2894d8ea42851df (aws_eip):
~ AssociationId: "" => "eipassoc-0ee67e1ca759733a2"
~ Instance: "" => "i-004611704837fd09a"
~ NetworkInterface: "" => "eni-0a62972b0471447f6"
~ PrivateDns: <nil> => "ip-172-31-40-4.eu-west-3.compute.internal"
~ PrivateIp: "" => "172.31.40.4"
State, after the first TF apply:
{
"mode": "managed",
"type": "aws_eip",
"name": "eip_test_instance_2",
"provider": "provider[\"registry.terraform.io/hashicorp/aws\"]",
"instances": [
{
"schema_version": 0,
"attributes": {
"allocation_id": null,
"associate_with_private_ip": null,
"association_id": "",
"customer_owned_ip": "",
"customer_owned_ipv4_pool": "",
"domain": "vpc",
"id": "eipalloc-0e2894d8ea42851df",
"instance": "",
"network_border_group": "eu-west-3",
"network_interface": "",
"private_dns": null,
"private_ip": "",
"public_dns": "ec2-35-180-56-77.eu-west-3.compute.amazonaws.com",
"public_ip": "35.180.56.77",
"public_ipv4_pool": "amazon",
"tags": {
"Name": "eip_test_instance_2"
},
"timeouts": null,
"vpc": true
},
"sensitive_attributes": [],
"private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiZGVsZXRlIjoxODAwMDAwMDAwMDAsInJlYWQiOjkwMDAwMDAwMDAwMCwidXBkYXRlIjozMDAwMDAwMDAwMDB9fQ=="
}
]
State, 2nd terraform apply:
{
"mode": "managed",
"type": "aws_eip",
"name": "eip_test_instance_2",
"provider": "provider[\"registry.terraform.io/hashicorp/aws\"]",
"instances": [
{
"schema_version": 0,
"attributes": {
"allocation_id": null,
"associate_with_private_ip": null,
"association_id": "eipassoc-0ee67e1ca759733a2",
"customer_owned_ip": "",
"customer_owned_ipv4_pool": "",
"domain": "vpc",
"id": "eipalloc-0e2894d8ea42851df",
"instance": "i-004611704837fd09a",
"network_border_group": "eu-west-3",
"network_interface": "eni-0a62972b0471447f6",
"private_dns": "ip-172-31-40-4.eu-west-3.compute.internal",
"private_ip": "172.31.40.4",
"public_dns": "ec2-35-180-56-77.eu-west-3.compute.amazonaws.com",
"public_ip": "35.180.56.77",
"public_ipv4_pool": "amazon",
"tags": {
"Name": "eip_test_instance_2"
},
"timeouts": null,
"vpc": true
},
"sensitive_attributes": [],
Environment
- OS: linux
- driftctl version: 0.1.1 (docker)
How to reproduce
A minimal aws_instance
, with a minimal aws_eip
and a minimal aws_eip_association
resource "aws_instance" "test_instance_1" {
ami = data.aws_ami.ubuntu.id
instance_type = "t3.micro"
tags = {
Name = "test_instance_1"
}
volume_tags = {
Name = "rootVol"
}
root_block_device {
volume_type = "gp2"
volume_size = 20
delete_on_termination = true
}
}
resource "aws_eip" "eip_test_instance_2" {
tags = {
Name = "eip_test_instance_2"
}
}
resource "aws_eip_association" "eip_assoc_instance_1" {
instance_id = aws_instance.test_instance_1.id
allocation_id = aws_eip.eip_test_instance_2.id
}
Possible Solution
issue a warning?
Additional context
This relevant terraform issue explaining the root cause found by @wbeuil hashicorp/terraform-provider-aws#15093 (comment)
Also similar to #11