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.71k stars 9.07k forks source link

failed to change `ec2` type when binding `aws_route53` #10720

Open heqingy opened 4 years ago

heqingy commented 4 years ago

Community Note

Terraform Version

Terraform v0.12.13

Affected Resource(s)

Terraform Configuration Files


  provider "aws" {
    region = "ap-northeast-1"
  }

  resource "aws_vpc" "myvpc" {
    cidr_block = "10.0.0.0/16"
    tags = {
      Name = "myvpc"
    }
  }

  resource "aws_route_table_association" "myroutetableassociation" {
    subnet_id = aws_subnet.mysubnet.id
    route_table_id = aws_route_table.myroutetable.id
  }

  resource "aws_subnet" "mysubnet" {
    vpc_id = "${aws_vpc.myvpc.id}"
    cidr_block = "10.0.0.0/24"
    map_public_ip_on_launch = true
    tags = {
      Name = "mysubnet"
    }
  }

  resource "aws_internet_gateway" "mygateway" {
    vpc_id = "${aws_vpc.myvpc.id}"
    tags = {
      Name = "mygateway"
    }
  }

  resource "aws_route" "myroute" {
    route_table_id = aws_route_table.myroutetable.id
    destination_cidr_block = "0.0.0.0/0"
    gateway_id = aws_internet_gateway.mygateway.id
  }

  resource "aws_route_table" "myroutetable" {
    vpc_id = "${aws_vpc.myvpc.id}"

    tags = {
      Name = "myroutetable"
    }
  }

  data "aws_route53_zone" "mydnszone" {
    name         = "graphtiger.com"
  }

  resource "aws_route53_record" "mydns" {
    zone_id = "${data.aws_route53_zone.mydnszone.zone_id}"
    name    = "test.i.${data.aws_route53_zone.mydnszone.name}"
    type    = "A"
    ttl     = "300"
    records = [aws_instance.myec2.public_ip]
  }

  resource "aws_main_route_table_association" "main_routetable" {
    vpc_id         = "${aws_vpc.myvpc.id}"
    route_table_id = "${aws_route_table.myroutetable.id}"
  }

  resource "aws_security_group" "mysecuritygroup" {
    name        = "all_traffic"
    description = "Allow all inbound traffic"
    vpc_id      = aws_vpc.myvpc.id

    ingress {
        from_port   = 0
        to_port     = 65535
        protocol    = "tcp"

            cidr_blocks = ["0.0.0.0/0"]

    }

    egress {
      from_port       = 0
      to_port         = 0
      protocol        = "-1"
      cidr_blocks     = ["0.0.0.0/0"]
    }
  }

  resource "aws_key_pair" "myawskey" {
    key_name_prefix   = "uid_1_"
    public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCvfgT1ZG03DO0m5DhMMbWTr6gfWZcVmBbmvZxdYu8m2ztFpScDCzGPmhuHrThT/95niXcgUSNERoMXle/HBWJT/SdqZr1XXRIPcPHDdDX0BJXCFiPLz2HhMCzr/r+6w8/cNbM0HshyMpNnoTmz08W5py6SCNiQCvpSfnObD03r/h/tM3+90SMzsnqrlih8voGM/c3bOeQ9EBm0HMeKq28GSbMTn0pxkgwbGeWknwH3xYI991u8vBbMEWBdhefRWe1zevWR4fjmzeUVrftzxLK0+9j14z+JAvPV1WTzVh+54QAnOyBmQQPCoYp5nIphg1peV8yaF41vYYNMaStRFc3P local@local"
  }

  resource "aws_instance" "myec2" {
    ami = "ami-02be181636ed95ac5"
    instance_type = "t3.medium"
    key_name = aws_key_pair.myawskey.key_name
    vpc_security_group_ids = [aws_security_group.mysecuritygroup.id]
    subnet_id = aws_subnet.mysubnet.id
    root_block_device {
        volume_type = "gp2"
        volume_size = 100
        delete_on_termination = true
    }
    tags = {
        Name = "uid_1"
        UID = "1"
    }
  }

  output "InstanceIP" {
    value = aws_instance.myec2.public_ip
  }

  output "InstanceID" {
    value = aws_instance.myec2.id
  }

Debug Output

https://paste.ubuntu.com/p/bvMFtQ5VDS/

Panic Output

Expected Behavior

Terraform should exit successfully

Actual Behavior

It exit with code 1 with following error output:

aws_key_pair.myawskey: Refreshing state... [id=uid_1_20191101223259282300000001]
data.aws_route53_zone.mydnszone: Refreshing state...
aws_vpc.myvpc: Refreshing state... [id=vpc-078029b0c49ab272f]
aws_internet_gateway.mygateway: Refreshing state... [id=igw-0e6a06562cacdabef]
aws_subnet.mysubnet: Refreshing state... [id=subnet-04b8d59d69a497614]
aws_route_table.myroutetable: Refreshing state... [id=rtb-0b40dfba4ac982cd1]
aws_security_group.mysecuritygroup: Refreshing state... [id=sg-0bef9965746fdf4aa]
aws_main_route_table_association.main_routetable: Refreshing state... [id=rtbassoc-08302dc642baa4924]
aws_route.myroute: Refreshing state... [id=r-rtb-0b40dfba4ac982cd11080289494]
aws_route_table_association.myroutetableassociation: Refreshing state... [id=rtbassoc-0a55e9cef34f254b4]
aws_instance.myec2: Refreshing state... [id=i-051bd4281dcdb41ae]
aws_route53_record.mydns: Refreshing state... [id=Z3NQWQ6DN6BMIR_test.i.graphtiger.com_A]
aws_instance.myec2: Modifying... [id=i-051bd4281dcdb41ae]
aws_instance.myec2: Still modifying... [id=i-051bd4281dcdb41ae, 10s elapsed]
aws_instance.myec2: Still modifying... [id=i-051bd4281dcdb41ae, 20s elapsed]
aws_instance.myec2: Still modifying... [id=i-051bd4281dcdb41ae, 30s elapsed]
aws_instance.myec2: Still modifying... [id=i-051bd4281dcdb41ae, 40s elapsed]
aws_instance.myec2: Still modifying... [id=i-051bd4281dcdb41ae, 50s elapsed]
aws_instance.myec2: Still modifying... [id=i-051bd4281dcdb41ae, 1m0s elapsed]
aws_instance.myec2: Still modifying... [id=i-051bd4281dcdb41ae, 1m10s elapsed]
aws_instance.myec2: Still modifying... [id=i-051bd4281dcdb41ae, 1m20s elapsed]
aws_instance.myec2: Modifications complete after 1m23s [id=i-051bd4281dcdb41ae]

Error: Provider produced inconsistent final plan

When expanding the plan for aws_route53_record.mydns to include new values
learned so far during apply, provider "aws" produced an invalid new value for
.records: planned set element cty.StringVal("3.112.61.250") does not correlate
with any element in actual.

This is a bug in the provider, which should be reported in the provider's own
issue tracker.

Steps to Reproduce

  1. terraform apply
  2. change instance_type of myec2 to t3.medium, t3.large or t3.xlarge repeatedly, it has over 70% possibility to be reproduced

Important Factoids

Nothing

References

thomasboussekey commented 4 years ago

Hello,

I encounter the same random behavior with a very similar configuration using: Terraform 0.12.16 Provider AWS 2.39

Any news on this issue?

Thanks in advance,

justinretzolk commented 2 years ago

Hey y'all 👋 Thank you for taking the time to file this issue! Given that there's been a number of AWS provider releases since you initially filed it, can anyone confirm whether you're still experiencing this behavior?

dmartin commented 1 year ago

Just experienced this today with provider v4.55. In my case I was recreating the instance (changing the associated keypair), so the record was empty:

│ When expanding the plan for
│ aws_route53_record.redacted to include new values
│ learned so far during apply, provider "registry.terraform.io/hashicorp/aws"
│ produced an invalid new value for .records: planned set element
│ cty.StringVal("") does not correlate with any element in actual.