Terraform-provider-aws: lightsail_static_ip_attachment detached when lightsail_instance recreate

Created on 18 Sep 2019  路  5Comments  路  Source: hashicorp/terraform-provider-aws

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 "me too" comments, 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 Version

Terraform v0.12.7

  • provider.archive v1.2.2
  • provider.aws v2.28.1
  • provider.template v2.1.2

Affected Resource(s)

  • aws_lightsail_static_ip_attachment (mainly)
  • aws_lightsail_static_ip
  • aws_lightsail_instance

following the example found in the docs: https://www.terraform.io/docs/providers/aws/r/lightsail_static_ip_attachment.html
for creating a lightsail static IP attachment.

Expected Behavior

when I update the configuration of the aws_lightsail_instance changing the bundle_id or any other attribute that requires destroy/add new instance, I'm expecting that the aws_lightsail_static_ip_attachment would still work (and be re-attached to the new lightsail instance`

Actual Behavior

I get the static IP detached from the old destroyed instance, but not attached to the new instance.

Steps to Reproduce

  1. follow the example in the terraform documentation
resource "aws_lightsail_static_ip_attachment" "test" {
  static_ip_name = "${aws_lightsail_static_ip.test.name}"
  instance_name  = "${aws_lightsail_instance.test.name}"
}

resource "aws_lightsail_static_ip" "test" {
  name = "example"
}

resource "aws_lightsail_instance" "test" {
  name              = "example"
  availability_zone = "eu-central-1a"
  blueprint_id      = "centos_7_1901_01" # or any other valid blueprint
  bundle_id         = "nano_2_0" # or any other valid bundle
}
  1. terraform apply
  2. change the bundle_id to be micro_2_0 (or any other valid option to make the instance destroy and recreate)
  3. terraform apply
  4. you can find the detached static IP in the lightsail dashboard
needs-triage serviclightsail

Most helpful comment

Well, there's a ticket for that, even comment specifically for that: https://github.com/hashicorp/terraform/issues/8099#issuecomment-494121768

However now that I took a second look at it shouldn't you just use id instead of name? It's the same value but id is generated.

All 5 comments

It will work if you do terraform apply again. The name of the instance doesn't change so it's hard to plan the change.

thanks, it does work after a second terraform apply, but isn't there a way to make the 2 resources aware of each other?

Well, there's a ticket for that, even comment specifically for that: https://github.com/hashicorp/terraform/issues/8099#issuecomment-494121768

However now that I took a second look at it shouldn't you just use id instead of name? It's the same value but id is generated.

Awesome, thanks a lot... using the ID instead of the name actually solved the problem...
Should it be mentioned in the documentation/example somehow (as I was following it)?

I have a PR open for updating the documentation of lightsail ip attachment #10141
I could add a footnote or somthing about this.

Well, updating the documentation is probably a great idea and if you won't make the PR I will when I have some time to test it.

Was this page helpful?
0 / 5 - 0 ratings