hashicorp / terraform-provider-aws

The AWS Provider enables Terraform to manage AWS resources.
https://registry.terraform.io/providers/hashicorp/aws
Mozilla Public License 2.0
9.83k stars 9.17k forks source link

[Bug]: Don't associate public ip when eip is assigned to instance #37318

Open schiaro98 opened 6 months ago

schiaro98 commented 6 months ago

Terraform Core Version

1.7.5

AWS Provider Version

4.25

Affected Resource(s)

aws_eip, aws_instance

Expected Behavior

After applying the next plan (an aws_instance with eip) in this manner:

resource "aws_eip" "eip1" {
  instance = aws_instance.foo.id
  domain   = "vpc"
}

and instance

resource "aws_instance" "foo" {
  ami           = "ami-5189a661"
  instance_type = "t2.micro"
  ....
associate_public_ip_address = false
}

All goes like estimate, istance has correctly the eip1 public eip, but if a plan is executed after this, the associate_public_ip_address directive force the replacemente of the instance, and the only way to correct this is to comment out or put associate_public_ip_address to true.

Is this behavior correct or a bug? I can't figure how this can be correct, but not having strong experience, preferring to ask to the community

Actual Behavior

The instance is correctly created, but every next plan, requires the istance to be replaced.

Relevant Error/Panic Output Snippet

No response

Terraform Configuration Files

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

  required_version = ">= 1.2.0"
}

provider "aws" {
  region  = "***"
  profile = "***"
}

resource "aws_eip" "eip1" {
  instance = aws_instance.example_server.id
  domain   = "vpc"
}
resource "aws_instance" "example_server" {
  ami           = "ami-04e914639d0cca79a"
  instance_type = "t2.micro"

}

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

github-actions[bot] commented 6 months ago

Community Note

Voting for Prioritization

Volunteering to Work on This Issue

justinretzolk commented 6 months ago

Related #37238