Open rubiconjosh opened 2 years ago
Met the same issue today.
resource "aws_instance" "my_bastion_host" {
ami = var.ami
instance_type = var.instance_type
tags = {
Name = var.name
}
key_name = var.key_name
subnet_id = data.aws_subnet.public_subnet.id
vpc_security_group_ids = [aws_security_group.public_ec2_security_group.id]
# provisioner "remote-exec" {
# inline = [
# "sudo yum -y update",
# "sudo yum -y install socat",
# ]
# }
user_data = <<EOF
#!/bin/bash
sudo yum -y update
sudo yum -y install socat
EOF
}
output "ssh" {
value = format("ssh -i ~/.ssh/%s.pem ec2-user@%s",var.key_name,aws_instance.my_bastion_host.public_dns)
}
I tried to use provisioner "remote-exec"
first, but terraform does not detect any changes. I later changed to user_data, it restarted ec2 which changed its public IP address. however, the terraform output does not reflect the new address value
At last, I have to use terraform destroy
.
Community Note
Terraform CLI and Terraform AWS Provider Version
Terraform v1.1.9 on darwin_arm64
Affected Resource(s)
Terraform Configuration Files
Debug Output
https://gist.github.com/rubiconjosh/bc83076453ca7fdd97bbf7fc0728c444
Panic Output
N/A
Expected Behavior
As documented when user_data is modified a stop/start will be triggered on
aws_instance.example
. This will cause the public IP of the instance to change.output.public_ip
would reflect the new values ofaws_instance.example.public_ip
.Actual Behavior
When
user_data
was modified onaws_instance.example
a stop/start was triggered.output.public_ip
still reflects the original public ip.Steps to Reproduce
terraform apply
user_data = "#"
toaws_instance.example
terraform apply
Important Factoids
I see the new pubic IP mentioned in the debug log:
Inspecting state shows that
aws_instance.example.public_ip
contains the new value,output.public_ip
does not.References
0000