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

credit specification is updated after no changes in the code #5654

Closed
Jonathan-7 opened this issue Aug 22, 2018 · 10 comments · Fixed by #5805
Closed

credit specification is updated after no changes in the code #5654

Jonathan-7 opened this issue Aug 22, 2018 · 10 comments · Fixed by #5805
Labels
bug Addresses a defect in current functionality. service/ec2 Issues and PRs that pertain to the ec2 service.
Milestone

Comments

@Jonathan-7
Copy link

Jonathan-7 commented Aug 22, 2018

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

Hello,
I ran into this a couple of times today while trying out the t3.micro instances. Even if I didn't change anything or I changed an unrelated resource (e.g the security group name) it would still update the credit specification.

Terraform Version

Terraform v0.11.8

Affected Resource(s)

  • aws_instance

Terraform Configuration Files

provider "aws" {
  region = "eu-west-1"
}

resource "aws_instance" "example" {
  ami                    = "ami-0bdb1d6c15a40392c"
  instance_type          = "t3.micro"
  vpc_security_group_ids = ["${aws_security_group.allow_all.id}"]
  key_name = "jons-ubuntu"

  user_data = <<-EOF
              #!/bin/bash
              yum -y install httpd
              systemctl start httpd.service
              systemctl enable httpd
              echo "Hello, World" > /var/www/html/index.html
              EOF

  tags {
    Name = "terraform-example"
  }
}

resource "aws_security_group" "allow_all" {
  name        = "allow_everything"
  description = "Allow all traffic"

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

Debug Output

https://gist.github.com/Jonathan-7/6c33ec9315158eeb1e4278132e2ced1d

Panic Output

Expected Behavior

Don't update anything.

Actual Behavior

Changed credit specification:
Terraform will perform the following actions:

~ aws_instance.example
credit_specification.0.cpu_credits: "unlimited" => "standard"

Steps to Reproduce

run terraform apply twice

  1. terraform apply
  2. terraform apply

Important Factoids

References

  • #0000
@bflad bflad added bug Addresses a defect in current functionality. service/ec2 Issues and PRs that pertain to the ec2 service. labels Aug 22, 2018
@bflad
Copy link
Contributor

bflad commented Aug 22, 2018

According to the T3 instance product documentation:

T3 instances start in Unlimited mode by default

I believe we default the cpu_credits attribute to standard since that matched the previous behavior with T2 instances.

If you would like to continue to not configure the instance credit_specification (leaving the default), you should be able to workaround this issue with the below until a proper code fix is released:

resource "aws_instance" "example" {
  # ... other configuration ...
  lifecycle {
    ignore_changes = ["credit_specification.0.cpu_credits"]
  }
}

george-angel added a commit to utilitywarehouse/tf_kube_aws that referenced this issue Aug 23, 2018
Ignore the credit_specification, we can't optionally specify this (for
`m` type instances, and t3 helpfully defaults to unlimited), more
details:
hashicorp/terraform-provider-aws#5654
@jgreen-zynga
Copy link
Contributor

This issue seems related to mine:

* aws_instance.jenkins: aws_instance.jenkins: diffs didn't match during apply. This is a bug with Terraform and should be reported as a GitHub Issue.

Please include the following information in your report:

    Terraform Version: 0.11.8
    Resource ID: aws_instance.jenkins
    Mismatch reason: attribute mismatch: credit_specification.0.cpu_credits

Diff One: 
credit_specification.0.cpu_credits":*terraform.ResourceAttrDiff{Old:"unlimited", New:"standard", NewComputed:false, NewRemoved:false, NewExtra:interface {}(nil), RequiresNew:false, Sensitive:false, Type:0x0}

Diff Two:
lacks credit_specification

I can provide the full diff on request but I'll have to clean it up.

This occurs when changing the user_data on an aws_instance with instance_type = t3.medium
resource:

resource "aws_instance" "jenkins" {
  ami             = "ami-09261ff1cf8893662"
  instance_type   = "t2.medium"
  subnet_id       = "subnet-64f47202"
  security_groups = ["${aws_security_group.instance.id}"]
  user_data       = "${file("${path.module}/user_data.sh")}"
}

@nhoughto
Copy link

nhoughto commented Aug 27, 2018

Tried the ignore_changes workaround and are still seeing the diffs didn't match during apply error. So workaround doesn't work in all cases? Going back to t2s in the interim.

@kmotrebski
Copy link

I've encountered this with t3.* instances too. My version is Terraform v0.11.1 + provider.aws v1.28.0.

@Jonathan-7 As my workaround I've decided to lock the cpu_credits:

resource "aws_instance" "example" {
  # ...
  credit_specification = {
    cpu_credits = "unlimited"
  }
}

So this is quite similar to ignore_changes solution, or am I wrong here?

@Jonathan-7
Copy link
Author

@kmotrebski your workaround should be fine. I expect them to have the credits as unlimited by default in an upcoming release.

@saravanan30erd
Copy link
Contributor

@bflad I will work on this issue.

@rlees85
Copy link

rlees85 commented Sep 6, 2018

not sure if its relevant but I set

  credit_specification = {
    cpu_credits = "standard"
  }

explicitly in code.... but Terraform still builds t3 instances with t.unlimited enabled. Only a second apply then corrects the credit specification

probably related and would be nice to have fixed

@bflad
Copy link
Contributor

bflad commented Sep 18, 2018

The fix for this has been merged into master for the aws_instance resource and will release with version 1.37.0 of the AWS provider, likely tomorrow.

@bflad
Copy link
Contributor

bflad commented Sep 19, 2018

This has been released in version 1.37.0 of the AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

@ghost
Copy link

ghost commented Apr 3, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

@ghost ghost locked and limited conversation to collaborators Apr 3, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Addresses a defect in current functionality. service/ec2 Issues and PRs that pertain to the ec2 service.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants