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

associate_public_ip_address triggers recreation if instance is stopped #121

Open
syphernl opened this issue Mar 17, 2022 · 1 comment
Open
Labels
bug 🐛 An issue with the system

Comments

@syphernl
Copy link

Describe the Bug

Creating an instance using this module with the following flags:

  associate_public_ip_address = true
  assign_eip_address          = false

causes the instance to be recreated when it is stopped because the "public address" (not EIP) is released when the server is shutdown.

To prevent this from happening we could add a lifecycle configuration which ignores this particular key. Unfortunately this cannot be done on a module object within Terraform so it must be done from inside the module itself.

Expected Behavior

No instance re-creation.

Steps to Reproduce

Steps to reproduce the behavior:

  1. Create an instance with the above flags
  2. Stop the instance
  3. Re-run plan and see that it will be recreated
@syphernl syphernl added the bug 🐛 An issue with the system label Mar 17, 2022
@joelsdc
Copy link

joelsdc commented Apr 13, 2022

I run into this issue...

The workaround I'm using:

# Most of the time the server is off, this manually added data-resource
# avoids the need to constantly switch between on and off config.
data "aws_instance" "test_instance" {
  instance_id = "${the_instance_id}"
}

module "test_instance" {
  source = "cloudposse/ec2-instance/aws"
  version = "x.x.x"
  ...
  ...
  associate_public_ip_address = data.aws_instance.test_instance.instance_state == "running" ? true : false
  ...
  ...
}

This isn't pretty, but at least I can continue to run terraform regardless of the state of the VM.

Hope this helps!
Joel.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 An issue with the system
Projects
None yet
Development

No branches or pull requests

2 participants