-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
r/aws_instance: add T2 unlimited to aws instance resources #2619
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @kl4w
thanks for the PR.
Is there any reason to drift away from the API specs?
How would you feel about modelling it like
resource "aws_instance" "..." {
...
credit_specification {
cpu_credits = "unlimited"
}
}
It may look safe to simplify the experience for the user now, but we have learnt over time that Amazon is constantly adding new features to the API and if we build abstractions we effectively block ourselves from implementing future changes or at the very least make it more difficult.
For the same reason I think we shouldn't try to be too clever and validate instance_type
- we have no idea how is the API going to change in the future and I think (correct me if I'm wrong) we can just rely on the API validation here?
Yes absolutely, I've been going back and forth about how to implement this portion and I believe your suggestion makes complete sense. Also considering that the launch template also takes the same structure in its data. I'll implement the change and get back to you |
@radeksimko Hopefully this covers your review. make testacc TEST=./aws TESTARGS='-run=TestAccAWSInstance_creditSpecification'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -run=TestAccAWSInstance_creditSpecification -timeout 120m
=== RUN TestAccAWSInstance_creditSpecification_standardCpuCredits
--- PASS: TestAccAWSInstance_creditSpecification_standardCpuCredits (220.17s)
=== RUN TestAccAWSInstance_creditSpecification_unlimitedCpuCredits
--- PASS: TestAccAWSInstance_creditSpecification_unlimitedCpuCredits (231.52s)
=== RUN TestAccAWSInstance_creditSpecification_updateCpuCredits
--- PASS: TestAccAWSInstance_creditSpecification_updateCpuCredits (129.54s)
PASS
ok github.com/terraform-providers/terraform-provider-aws/aws 581.273s
make testacc TEST=./aws TESTARGS='-run=TestAccAWSInstanceDataSource_creditSpecification'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -run=TestAccAWSInstanceDataSource_creditSpecification -timeout 120m
=== RUN TestAccAWSInstanceDataSource_creditSpecification
--- PASS: TestAccAWSInstanceDataSource_creditSpecification (124.64s)
PASS
ok github.com/terraform-providers/terraform-provider-aws/aws 124.673s |
@radeksimko Was there anything else missing from this PR? I was looking at preping the change for launch configurations for once that update is done in the ASW SDK/CLI but without this implementation confirmed I didn't want to get too far into anything. |
aws/resource_aws_instance.go
Outdated
@@ -1024,6 +1048,26 @@ func resourceAwsInstanceUpdate(d *schema.ResourceData, meta interface{}) error { | |||
} | |||
} | |||
|
|||
if d.HasChange("credit_specification") { | |||
creditSpecifications := d.Get("credit_specification").([]interface{}) | |||
if len(creditSpecifications) == 1 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we're limiting ourselves here to cases when credit_specification
is always in the config, which means we're not covering the case of removal of credit_specification
(i.e. user basically can't disable it once it's enabled).
I'm not sure what's the best approach, but I assume we'll need to call ModifyInstanceCreditSpecification
too with empty slice?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@radeksimko I have a question about HasChange. It looks like it doesn't detect removal of the attributes. Has this always been the case?
It looks like in order to disable the credit_specification
once it's enabled means setting the value back to standard
.
What would your recommendation on how to handle this be?
aws/resource_aws_instance.go
Outdated
cs := v.([]interface{}) | ||
if len(cs) > 1 { | ||
return nil, errors.New("Cannot specify more than one credit_specification.") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No big deal, but this is already guaranteed by the MaxItems: 1
in the schema, so this check is redundant.
aws/data_source_aws_instance_test.go
Outdated
@@ -20,6 +20,7 @@ func TestAccAWSInstanceDataSource_basic(t *testing.T) { | |||
resource.TestCheckResourceAttr("data.aws_instance.web-instance", "ami", "ami-4fccb37f"), | |||
resource.TestCheckResourceAttr("data.aws_instance.web-instance", "tags.%", "1"), | |||
resource.TestCheckResourceAttr("data.aws_instance.web-instance", "instance_type", "m1.small"), | |||
resource.TestCheckResourceAttr("data.aws_instance.web-instance", "t2_unlimited", "false"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👀 ^
@@ -233,6 +242,7 @@ The following attributes are exported: | |||
* `security_groups` - The associated security groups. | |||
* `vpc_security_group_ids` - The associated security groups in non-default VPC | |||
* `subnet_id` - The VPC subnet ID. | |||
* `t2_unlimited` - Whether [T2 Unlimited](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/t2-unlimited.html) is enabled. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👀 ^
@radeksimko aside from your comment on the HasChange, i've taken account of the others, rebased and squashed the commits.
|
sorry to be a pest but any timeline on when this will be released? |
Is there any reason why this hasn't been pulled yet? We're hitting a very obscure yet very real limitation in AWS where you can only spin up ~100 t2 instances with full credits in a 24 hour period and t2.unlimited will solve this for us. |
My company's in serious need of Terraform-based support for this, can we please get this pulled? |
We really want to make use of this too. Please can it be merged and released ASAP. Thank you! |
This comment has been minimized.
This comment has been minimized.
@kl4w Could you please rebase this? |
I've actually taken the liberty of rebasing the branch, I'm just running the acceptance tests now. We will see if I can push directly to the branch (allow edits from maintainers). Affected tests from rebase
|
aws/resource_aws_instance.go
Outdated
"cpu_credits": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Computed: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this have validation? I'm not familiar with the API, but I only seen unlimited
and standard
in the results? Is it really free form?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe the API complains if you use something other than unlimited
and standard
, leaving this opaque in terraform gives out of the box support for new cpu_credit
types in the future.
@kl4w I took the liberty rebasing your branch (I only solved the merge conflicts I didn't change anything), this means you will need to do a reset locally. I'm new to the TF team so I might have jumped the gun on rebasing your work to try and get it across the finish line, my sincerest apologies if that's the case. Feel free to ping me if there is anything I can do on this PR going forward. Otherwise amazing work 🎉 |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This feature is pretty important for me too. I do not understand why this feature is pushed back and why related comments are marked as off-topic. |
Can't tell who marked the comments as off-topic, but maybe @bflad can elaborate on why it keeps getting pushed out to the next milestone when seemingly, from this pull requests, all is ready to go? |
@kl4w we just ran into a similar situation with Removing Then using this behavior for handle the update when it was removed: Maybe worth giving this a shot here too? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left some feedback below. Please let us know if you have any questions.
aws/data_source_aws_instance.go
Outdated
if err != nil { | ||
return err | ||
} | ||
d.Set("credit_specification", creditSpecifications) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should return errors when attempting to set non-scalar attributes in the state (otherwise it will silently use the value of the configuration or in the case of the data source, not set it at all):
if err := d.Set("credit_specification", creditSpecifications); err != nil {
return fmt.Errorf("error setting credit_specification: %s", err)
}
aws/resource_aws_instance.go
Outdated
if err != nil { | ||
return err | ||
} | ||
d.Set("credit_specification", creditSpecifications) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here -- we should return errors when attempting to set non-scalar attributes in the state (otherwise it will silently use the value of the configuration or in the case of the data source, not set it at all):
if err := d.Set("credit_specification", creditSpecifications); err != nil {
return fmt.Errorf("error setting credit_specification: %s", err)
}
aws/resource_aws_instance.go
Outdated
@@ -1644,6 +1689,18 @@ func buildAwsInstanceOpts( | |||
InstanceType: aws.String(d.Get("instance_type").(string)), | |||
} | |||
|
|||
if v, ok := d.GetOk("credit_specification"); ok { | |||
cs := v.([]interface{}) | |||
for _, csValue := range cs { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since there will only be one element if its defined, we can skip the loop and directly access cs[0]
resource.TestCheckResourceAttr(resName, "credit_specification.#", "1"), | ||
resource.TestCheckResourceAttr(resName, "credit_specification.0.cpu_credits", "unlimited"), | ||
), | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a TestStep
that removes the credit_specification
configuration and expects to find credit_specification.0.cpu_credits
set to standard
@bflad I've rebased (from some time yesterday iirc) and made changes based on your review
However I'm getting some failures on tests (even on master and also unrelated to my changes) with some aws_instance (both resource and data resource). How would you like me to proceed? |
Are they related to the I'll kick off a full acceptance test run now and ensure nothing here is breaking backwards compatibility. |
Yeah, both of those resources. Also, this is on latest master (all the data resource tests fail)
|
We'll address this separately 😉 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Another great PR, @kl4w! 🚀
Test failures unrelated:
Tests failed: 2 (2 new), passed: 67
=== RUN TestAccAWSInstance_importInDefaultVpcBySgId
--- PASS: TestAccAWSInstance_importInDefaultVpcBySgId (171.13s)
=== RUN TestAccAWSInstanceDataSource_gp2IopsDevice
--- PASS: TestAccAWSInstanceDataSource_gp2IopsDevice (200.82s)
=== RUN TestAWSInstanceMigrateState
--- PASS: TestAWSInstanceMigrateState (0.00s)
=== RUN TestAWSInstanceMigrateState_empty
--- PASS: TestAWSInstanceMigrateState_empty (0.00s)
=== RUN TestAccAWSInstanceDataSource_rootInstanceStore
--- PASS: TestAccAWSInstanceDataSource_rootInstanceStore (206.63s)
=== RUN TestAccAWSInstanceDataSource_blockDevices
--- PASS: TestAccAWSInstanceDataSource_blockDevices (217.94s)
=== RUN TestAccAWSInstanceDataSource_AzUserData
--- PASS: TestAccAWSInstanceDataSource_AzUserData (241.73s)
=== RUN TestAccAWSInstance_importInEc2Classic
--- PASS: TestAccAWSInstance_importInEc2Classic (101.30s)
=== RUN TestAccAWSInstanceDataSource_keyPair
--- PASS: TestAccAWSInstanceDataSource_keyPair (276.50s)
=== RUN TestAccAWSInstanceDataSource_tags
--- PASS: TestAccAWSInstanceDataSource_tags (282.41s)
=== RUN TestAccAWSInstanceDataSource_VPC
--- PASS: TestAccAWSInstanceDataSource_VPC (290.85s)
=== RUN TestAccAWSInstanceDataSource_privateIP
--- PASS: TestAccAWSInstanceDataSource_privateIP (307.23s)
=== RUN TestAccAWSInstance_GP2IopsDevice
--- PASS: TestAccAWSInstance_GP2IopsDevice (101.54s)
=== RUN TestAccAWSInstanceDataSource_basic
--- PASS: TestAccAWSInstanceDataSource_basic (340.56s)
=== RUN TestAccAWSInstanceDataSource_VPCSecurityGroups
--- PASS: TestAccAWSInstanceDataSource_VPCSecurityGroups (343.86s)
=== RUN TestAccAWSInstance_GP2WithIopsValue
--- PASS: TestAccAWSInstance_GP2WithIopsValue (102.76s)
=== RUN TestAccAWSInstance_blockDevices
--- PASS: TestAccAWSInstance_blockDevices (96.66s)
=== RUN TestAccAWSInstance_rootInstanceStore
--- PASS: TestAccAWSInstance_rootInstanceStore (101.73s)
=== RUN TestAccAWSInstanceDataSource_creditSpecification
--- PASS: TestAccAWSInstanceDataSource_creditSpecification (378.84s)
=== RUN TestAccAWSInstance_importInDefaultVpcBySgName
--- PASS: TestAccAWSInstance_importInDefaultVpcBySgName (396.66s)
=== RUN TestAccAWSInstance_ipv6AddressCountAndSingleAddressCausesError
--- PASS: TestAccAWSInstance_ipv6AddressCountAndSingleAddressCausesError (77.83s)
=== RUN TestAccAWSInstance_userDataBase64
--- PASS: TestAccAWSInstance_userDataBase64 (239.05s)
=== RUN TestAccAWSInstance_vpc
--- PASS: TestAccAWSInstance_vpc (150.44s)
=== RUN TestAccAWSInstanceDataSource_SecurityGroups
--- PASS: TestAccAWSInstanceDataSource_SecurityGroups (486.93s)
=== RUN TestAccAWSInstance_importBasic
--- PASS: TestAccAWSInstance_importBasic (538.37s)
=== RUN TestAccAWSInstance_placementGroup
--- PASS: TestAccAWSInstance_placementGroup (235.32s)
=== RUN TestAccAWSInstance_multipleRegions
--- PASS: TestAccAWSInstance_multipleRegions (198.34s)
=== RUN TestAccAWSInstance_ipv6_supportAddressCountWithIpv4
--- PASS: TestAccAWSInstance_ipv6_supportAddressCountWithIpv4 (222.06s)
=== RUN TestAccAWSInstance_basic
--- PASS: TestAccAWSInstance_basic (395.98s)
=== RUN TestAccAWSInstance_tags
--- PASS: TestAccAWSInstance_tags (170.62s)
=== RUN TestAccAWSInstancesDataSource_basic
--- PASS: TestAccAWSInstancesDataSource_basic (626.53s)
=== RUN TestAccAWSInstance_ipv6_supportAddressCount
--- PASS: TestAccAWSInstance_ipv6_supportAddressCount (298.70s)
=== RUN TestAccAWSInstance_keyPairCheck
--- PASS: TestAccAWSInstance_keyPairCheck (89.06s)
=== RUN TestAccAWSInstance_volumeTags
--- PASS: TestAccAWSInstance_volumeTags (271.76s)
=== RUN TestAccAWSInstance_volumeTagsComputed
--- PASS: TestAccAWSInstance_volumeTagsComputed (310.21s)
=== RUN TestAccAWSInstance_withIamInstanceProfile
--- PASS: TestAccAWSInstance_withIamInstanceProfile (235.00s)
=== RUN TestAccAWSInstance_privateIP
--- PASS: TestAccAWSInstance_privateIP (262.07s)
=== RUN TestAccAWSInstance_rootBlockDeviceMismatch
--- PASS: TestAccAWSInstance_rootBlockDeviceMismatch (232.90s)
=== RUN TestAccAWSInstance_forceNewAndTagsDrift
--- PASS: TestAccAWSInstance_forceNewAndTagsDrift (253.23s)
=== RUN TestAccAWSInstance_instanceProfileChange
--- PASS: TestAccAWSInstance_instanceProfileChange (372.28s)
=== RUN TestAccAWSInstance_primaryNetworkInterfaceSourceDestCheck
--- PASS: TestAccAWSInstance_primaryNetworkInterfaceSourceDestCheck (172.18s)
=== RUN TestAccAWSInstance_disableApiTermination
--- PASS: TestAccAWSInstance_disableApiTermination (696.36s)
=== RUN TestAccAWSInstance_associatePublicIPAndPrivateIP
--- PASS: TestAccAWSInstance_associatePublicIPAndPrivateIP (446.04s)
=== RUN TestAccAWSInstance_associatePublic_defaultPrivate
--- PASS: TestAccAWSInstance_associatePublic_defaultPrivate (198.72s)
=== RUN TestAccAWSInstance_associatePublic_defaultPublic
--- FAIL: TestAccAWSInstance_associatePublic_defaultPublic (236.10s)
testing.go:518: Step 0 error: Check failed: Check 2/3 error: aws_instance.foo: Attribute 'associate_public_ip_address' expected "true", got "false"
=== RUN TestAccAWSInstance_changeInstanceType
--- PASS: TestAccAWSInstance_changeInstanceType (444.06s)
=== RUN TestAccAWSInstance_NetworkInstanceRemovingAllSecurityGroups
--- PASS: TestAccAWSInstance_NetworkInstanceRemovingAllSecurityGroups (690.35s)
=== RUN TestAccAWSInstance_addSecondaryInterface
--- PASS: TestAccAWSInstance_addSecondaryInterface (333.47s)
=== RUN TestAccAWSInstance_primaryNetworkInterface
--- PASS: TestAccAWSInstance_primaryNetworkInterface (447.25s)
=== RUN TestAccAWSInstance_associatePublic_explicitPublic
--- PASS: TestAccAWSInstance_associatePublic_explicitPublic (278.83s)
=== RUN TestAccAWSInstance_associatePublic_overridePublic
--- PASS: TestAccAWSInstance_associatePublic_overridePublic (253.69s)
=== RUN TestAccAWSInstanceDataSource_PlacementGroup
--- PASS: TestAccAWSInstanceDataSource_PlacementGroup (1216.15s)
=== RUN TestAccAWSInstance_creditSpecification_standardCpuCredits
--- PASS: TestAccAWSInstance_creditSpecification_standardCpuCredits (133.81s)
=== RUN TestAccAWSInstance_noAMIEphemeralDevices
--- PASS: TestAccAWSInstance_noAMIEphemeralDevices (977.35s)
=== RUN TestAccAWSInstance_addSecurityGroupNetworkInterface
--- PASS: TestAccAWSInstance_addSecurityGroupNetworkInterface (460.06s)
=== RUN TestAccAWSInstance_creditSpecification_unspecifiedDefaultsToStandard
--- PASS: TestAccAWSInstance_creditSpecification_unspecifiedDefaultsToStandard (193.76s)
=== RUN TestAccAWSInstanceDataSource_getPasswordData_falseToTrue
--- PASS: TestAccAWSInstanceDataSource_getPasswordData_falseToTrue (1288.35s)
=== RUN TestAccAWSInstance_creditSpecification_updateCpuCredits
--- PASS: TestAccAWSInstance_creditSpecification_updateCpuCredits (206.50s)
=== RUN TestAccAWSInstanceDataSource_getPasswordData_trueToFalse
--- PASS: TestAccAWSInstanceDataSource_getPasswordData_trueToFalse (1348.50s)
=== RUN TestAccAWSInstance_associatePublic_overridePrivate
--- PASS: TestAccAWSInstance_associatePublic_overridePrivate (345.78s)
=== RUN TestAccAWSInstance_NetworkInstanceSecurityGroups
--- PASS: TestAccAWSInstance_NetworkInstanceSecurityGroups (982.66s)
=== RUN TestAccAWSInstance_creditSpecification_removalReturnsStandard
--- PASS: TestAccAWSInstance_creditSpecification_removalReturnsStandard (257.10s)
=== RUN TestAccAWSInstance_associatePublic_explicitPrivate
--- PASS: TestAccAWSInstance_associatePublic_explicitPrivate (492.94s)
=== RUN TestAccAWSInstance_creditSpecification_unlimitedCpuCredits
--- PASS: TestAccAWSInstance_creditSpecification_unlimitedCpuCredits (328.52s)
=== RUN TestAccAWSInstance_sourceDestCheck
--- PASS: TestAccAWSInstance_sourceDestCheck (1173.94s)
=== RUN TestAccAWSInstance_NetworkInstanceVPCSecurityGroupIDs
--- FAIL: TestAccAWSInstance_NetworkInstanceVPCSecurityGroupIDs (1080.88s)
testing.go:518: Step 0 error: After applying this step, the plan was not empty:
DIFF:
UPDATE: aws_security_group.tf_test_foo
ingress.#: "0" => "1"
ingress.1799340084.cidr_blocks.#: "0" => "1"
ingress.1799340084.cidr_blocks.0: "" => "0.0.0.0/0"
ingress.1799340084.description: "" => ""
ingress.1799340084.from_port: "" => "-1"
ingress.1799340084.ipv6_cidr_blocks.#: "0" => "0"
ingress.1799340084.protocol: "" => "icmp"
ingress.1799340084.security_groups.#: "0" => "0"
ingress.1799340084.self: "" => "false"
ingress.1799340084.to_port: "" => "-1"
=== RUN TestAccAWSInstancesDataSource_tags
--- PASS: TestAccAWSInstancesDataSource_tags (1537.26s)
=== RUN TestAccAWSInstance_getPasswordData_trueToFalse
--- PASS: TestAccAWSInstance_getPasswordData_trueToFalse (543.83s)
=== RUN TestAccAWSInstance_getPasswordData_falseToTrue
--- PASS: TestAccAWSInstance_getPasswordData_falseToTrue (568.82s)
Just to reiterate on a couple of questions in this thread, specifically from @GoodMirek and @rbnrye : I did mark a couple of comments as off-topic and didn't provide further explanation - apologies for that. I'll be sure to do this in future where these comments are non-trivial. Generally speaking using reactions is always a preferred way to express interest (or other emotions) as we can use these when sorting PRs and issues easily. Comments along the lines of "+1" or "when will this ship" whilst seeming helpful send everybody involved a notification which causes issues across a larger repository (such that we ask that folks use the reactions to indicate you're interested in a feature). We're taking advantage of the new "off-topic" feature in PR's and Issues to try and make it clearer what the remaining state of the PR is (e.g. any comments from PR review, discussions about how it should be implemented etc.). TL;DR: We do appreciate people expressing interest in PRs and helping us prioritise, but comments are not the best way to do so, for the reasons mentioned. |
This has been released in version 1.16.0 of the AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. |
I just wanted to let you know that this change breaks deployments into the GovCloud region of us-gov-west-1. Haven't tested elsewhere in GovCloud This is the error that I receive.
|
The fix for GovCloud and China (or really anything throwing |
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! |
I think this should cover: #2491