-
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
resource/aws_launch_template: Ensure ebs_optimized argument accepts "unspecified" value #5627
Conversation
Hi @bjwschaap 👋 Thanks for submitting this. Do we know for sure that the default for this attribute is |
It should default to unspecified so the instances that are ebs optimized by default launch with ebs optimization. |
Its likely that this implementation should instead be similar to: #5632 where we use |
@bflad and @blckct thanks for the feedback! I can update the PR, no problem. So as far as I can tell from the documentation the default state for a launch template on AWS is indeed "unspecified". I was too quick with jumping to a conclusion with this implementation, based on the conversation in the issue thread. My apologies.. Based on @bflad comment about #5632 I think I have enough pointers to improve this PR. |
@bflad @blckct I'm hitting an issue when testing. I'm probably missing something obvious here, but I'm a bit stuck at the moment. Maybe you have some pointers for me? I've added
To my understanding I'll commit and push what I have so far so you can take a look. |
@bjwschaap I found the fix required for handling booleans in "ebs_optimized": {
// Use TypeString to allow an "unspecified" value,
// since TypeBool only has true/false with false default.
// The conversion from bare true/false values in
// configurations to TypeString value is currently safe.
Type: schema.TypeString,
Optional: true,
DiffSuppressFunc: suppressEquivalentTypeStringBoolean,
ValidateFunc: validateTypeStringNullableBoolean,
}, |
|
Please review @bflad |
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.
Two more little things then I think we should be good to go 👍
aws/resource_aws_launch_template.go
Outdated
@@ -549,6 +554,10 @@ func resourceAwsLaunchTemplateRead(d *schema.ResourceData, meta interface{}) err | |||
d.Set("user_data", ltData.UserData) | |||
d.Set("vpc_security_group_ids", aws.StringValueSlice(ltData.SecurityGroupIds)) | |||
|
|||
if ltData.EbsOptimized != nil { |
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 probably additionally call d.Set("ebs_optimized", "")
before this if
to handle ensure Terraform catches the scenario where the attribute is set to "unspecified" out of band.
@@ -122,6 +122,7 @@ func TestAccAWSLaunchTemplate_data(t *testing.T) { | |||
resource.TestCheckResourceAttr(resName, "block_device_mappings.#", "1"), | |||
resource.TestCheckResourceAttr(resName, "credit_specification.#", "1"), | |||
resource.TestCheckResourceAttrSet(resName, "disable_api_termination"), | |||
resource.TestCheckResourceAttrSet(resName, "ebs_optimized"), |
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.
Rather than just testing the attribute being set (to anything) we should ensure its value is correct:
resource.TestCheckResourceAttr(resName, "ebs_optimized", "false"),
We should also ensure at least one test whose configuration doesn't include ebs_optimized
has the correct value as well:
resource.TestCheckResourceAttr(resName, "ebs_optimized", ""),
@bflad Thnx for the feedback. Sorry for the late response on my behalf. I'll try and update with your review comments as soon as I can so we can get this shipped. |
|
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.
Looks great! Thanks, @bjwschaap! 🚀
make testacc TEST=./aws TESTARGS='-run=TestAccAWSLaunchTemplate_'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -run=TestAccAWSLaunchTemplate_ -timeout 120m
=== RUN TestAccAWSLaunchTemplate_importBasic
--- PASS: TestAccAWSLaunchTemplate_importBasic (15.93s)
=== RUN TestAccAWSLaunchTemplate_importData
--- PASS: TestAccAWSLaunchTemplate_importData (14.00s)
=== RUN TestAccAWSLaunchTemplate_basic
--- PASS: TestAccAWSLaunchTemplate_basic (12.35s)
=== RUN TestAccAWSLaunchTemplate_BlockDeviceMappings_EBS
--- PASS: TestAccAWSLaunchTemplate_BlockDeviceMappings_EBS (50.21s)
=== RUN TestAccAWSLaunchTemplate_BlockDeviceMappings_EBS_DeleteOnTermination
--- PASS: TestAccAWSLaunchTemplate_BlockDeviceMappings_EBS_DeleteOnTermination (40.73s)
=== RUN TestAccAWSLaunchTemplate_data
--- PASS: TestAccAWSLaunchTemplate_data (11.30s)
=== RUN TestAccAWSLaunchTemplate_update
--- PASS: TestAccAWSLaunchTemplate_update (46.02s)
=== RUN TestAccAWSLaunchTemplate_tags
--- PASS: TestAccAWSLaunchTemplate_tags (23.07s)
=== RUN TestAccAWSLaunchTemplate_nonBurstable
--- PASS: TestAccAWSLaunchTemplate_nonBurstable (13.67s)
=== RUN TestAccAWSLaunchTemplate_networkInterface
--- PASS: TestAccAWSLaunchTemplate_networkInterface (33.65s)
PASS
ok github.com/terraform-providers/terraform-provider-aws/aws 261.728s
This has been released in version 1.36.0 of the AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. |
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! |
First attempt to contribute, so any guidance is much appreciated.
Fixes #5458
Output from acceptance testing: