Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modifying aws_instance.user_data triggers a stop then start but does not update output #24690

Closed
rubiconjosh opened this issue May 7, 2022 · 4 comments · Fixed by #40710
Closed
Labels
bug Addresses a defect in current functionality. service/ec2 Issues and PRs that pertain to the ec2 service.
Milestone

Comments

@rubiconjosh
Copy link

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • 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
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Terraform CLI and Terraform AWS Provider Version

Terraform v1.1.9
on darwin_arm64

  • provider registry.terraform.io/hashicorp/aws v4.13.0

Affected Resource(s)

  • aws_instance

Terraform Configuration Files

terraform {
  required_providers {
    aws = {
      source = "hashicorp/aws"
      version = "~> 4.0"
    }
  }
}

provider "aws" {
  region = "us-east-1"
}

data "aws_ami" "ubuntu" {
  most_recent = true

  filter {
    name = "name"
    values = ["ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-*"]
  }

  filter {
    name = "virtualization-type"
    values = ["hvm"]
  }

  owners = ["099720109477"]
}

resource "aws_instance" "example" {
  ami = data.aws_ami.ubuntu.id
  instance_type = "t3.micro"
}

output "public_ip" {
  value = aws_instance.example.public_ip
}

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 of aws_instance.example.public_ip.

Actual Behavior

When user_data was modified on aws_instance.example a stop/start was triggered. output.public_ip still reflects the original public ip.

Steps to Reproduce

  1. terraform apply
  2. Add user_data = "#" to aws_instance.example
  3. terraform apply
  4. Notice the public IP did not update

Important Factoids

I see the new pubic IP mentioned in the debug log:

2022-05-06T21:24:51.284-0700 [WARN]  Provider "provider[\"registry.terraform.io/hashicorp/aws\"]" produced an unexpected new value for aws_instance.example, but we are tolerating it because it is using the legacy plugin SDK.
    The following problems may be the cause of any confusing errors from downstream operations:
      - .public_ip: was cty.StringVal("44.203.64.34"), but now cty.StringVal("3.92.200.228")

Inspecting state shows that aws_instance.example.public_ip contains the new value, output.public_ip does not.

References

  • #0000
@github-actions github-actions bot added needs-triage Waiting for first response or review from a maintainer. bug Addresses a defect in current functionality. service/ec2 Issues and PRs that pertain to the ec2 service. labels May 7, 2022
@justinretzolk justinretzolk removed the needs-triage Waiting for first response or review from a maintainer. label May 9, 2022
@uniquejava
Copy link

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.

Copy link

Warning

This issue has been closed, meaning that any additional comments are hard for our team to see. Please assume that the maintainers will not see them.

Ongoing conversations amongst community members are welcome, however, the issue will be locked after 30 days. Moving conversations to another venue, such as the AWS Provider forum, is recommended. If you have additional concerns, please open a new issue, referencing this one where needed.

@github-actions github-actions bot added this to the v5.83.0 milestone Dec 30, 2024
Copy link

github-actions bot commented Jan 9, 2025

This functionality has been released in v5.83.0 of the Terraform AWS Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

Copy link

github-actions bot commented Feb 9, 2025

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 9, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Addresses a defect in current functionality. service/ec2 Issues and PRs that pertain to the ec2 service.
Projects
None yet
3 participants