I have the below code sample code(variables are substituted properly )
resource "aws_instance" "ec2-demo1" {
ami = var.amzn-ami-id
instance_type = var.instance_type
key_name = var.key_name
tags = {
Name = "ec2-demo"
}
user_data = file("${path.module}/app1-install.sh")
//user_data_replace_on_change = true
}
output "ec2-instance-public-ip" {
description = "Print the public ip of the created EC2 instance"
value = aws_instance.ec2-demo1.public_ip
}
Issue is that whenever I update the user-data sh script, the ec2 resource is stopped and restarted but in output the previous instance's public address is printed. Below is what is see in the state file
"outputs": {
"ec2-instance-public-ip": {
"value": "54.173.141.184",
"type": "string"
}
// elsewhere in same state file
"public_dns": "ec2-54-165-159-38.compute-1.amazonaws.com",
"public_ip": "54.165.159.38",
Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request.
Volunteering to Work on This Issue
If you are interested in working on this issue, please leave a comment.
If this would be your first contribution, please review the contribution guide.
Terraform Core Version
1.5.7
AWS Provider Version
5.19.0
Affected Resource(s)
Affected resource - aws_instance.
Expected Behavior
The updated value should be given in output
Actual Behavior
Previous IP address is given in output
Relevant Error/Panic Output Snippet
I am on below terraform and aws provider version $ terraform --version Terraform v1.5.7 on windows_386
I have the below code sample code(variables are substituted properly )
Issue is that whenever I update the user-data sh script, the ec2 resource is stopped and restarted but in output the previous instance's public address is printed. Below is what is see in the state file
--- Output from stdout
When i set the flag
user_data_replace_on_change
, the correct IP address is given in outputTerraform Configuration Files
Steps to Reproduce
Debug Output
No response
Panic Output
No response
Important Factoids
No response
References
No response
Would you like to implement a fix?
None