Write code for dynamically generated data

resource “aws_instance” “ec2_on_demand” {
associate_public_ip_address = true
ami = “ami-0dcc1e21636832c5d”
instance_type = “m5.large”

Debug Output

#aws_instance.ec2_on_demand will be created

  • associate_public_ip_address = true (known after apply)
  • ami = “ami-0dcc1e21636832c5d”
  • instance_type = “m5.large”

Expected Behavior

If “associate_public_ip_address” was previously created with “terraform apply” and now we have manually updated the changes through GUI and later on state as well. Is there a way to update terraform such a way that we do not associate a hard coded value to it. such as: associate_public_ip_address = “”

As in future, the public IP address can be dynamically allocated(when running code from scratch). But, for now it sticks to the value as seen in terraform state.