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

r/aws_launch_template: Set latest version computed on change #5250

Merged
merged 1 commit into from
Jul 30, 2018
Merged

r/aws_launch_template: Set latest version computed on change #5250

merged 1 commit into from
Jul 30, 2018

Conversation

gordonbondon
Copy link
Contributor

@gordonbondon gordonbondon commented Jul 19, 2018

Proposed changes:

  • Set latest_version as computed on any filed change except name and description. Currently on every change to launch template new version is created. But this version is set to state only after apply is done. So other resources that use latest_version will pick up the change only on second apply.

Can be used as a workaround for #4655 , if later resources use latest_version in launch_template specification.

Output from acceptance testing:

make testacc TEST=./aws TESTARGS='-run=TestAccAWSLaunchTemplate_update'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -run=TestAccAWSLaunchTemplate_update -timeout 120m
=== RUN   TestAccAWSLaunchTemplate_update
--- PASS: TestAccAWSLaunchTemplate_update (79.34s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	79.827s

UPD: Rebased.

@ghost ghost added the size/XL Managed by automation to categorize the size of a PR. label Jul 19, 2018
@bflad bflad added bug Addresses a defect in current functionality. service/ec2 Issues and PRs that pertain to the ec2 service. labels Jul 20, 2018
@ghost ghost added the size/XL Managed by automation to categorize the size of a PR. label Jul 25, 2018
@bflad
Copy link
Contributor

bflad commented Jul 25, 2018

Hi @gordonbondon! 👋 Thanks for submitting this!

While its not documented in the Extending Terraform section of the website quite yet, we generally recommend avoiding any sort of "magic" logic with the schema. Usually this is for readability and long-term maintenance among other things.

Using your acceptance test update, I was able to verify a simpler change using ResourceDiff.GetChangedKeysPrefix() to not only remove the need to extract the schema into its own function, but also shortens the computation needed to testing only for changed keys in the difference:

		CustomizeDiff: customdiff.Sequence(
			customdiff.ComputedIf("latest_version", func(diff *schema.ResourceDiff, meta interface{}) bool {
				for _, changedKey := range diff.GetChangedKeysPrefix("") {
					switch changedKey {
					case "name", "name_prefix", "description", "default_version", "latest_version":
						continue
					default:
						return true
					}
				}
				return false
			}),
		),
$ make testacc TEST=./aws TESTARGS='-run=TestAccAWSLaunchTemplate_update'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -run=TestAccAWSLaunchTemplate_update -timeout 120m
=== RUN   TestAccAWSLaunchTemplate_update
--- PASS: TestAccAWSLaunchTemplate_update (50.85s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	51.457s

What do you think?

@bflad bflad added the waiting-response Maintainers are waiting on response from community or contributor. label Jul 25, 2018
@gordonbondon
Copy link
Contributor Author

@bflad nice, I didn't know about this magic GetChangeKeysPrefix. I'll update my pr to use it. It will look much better this way.

@gordonbondon gordonbondon changed the title r/aws_launch_template: Set latest version computed on change [WIP] r/aws_launch_template: Set latest version computed on change Jul 27, 2018
@ghost ghost added size/M Managed by automation to categorize the size of a PR. and removed size/XL Managed by automation to categorize the size of a PR. labels Jul 28, 2018
@gordonbondon
Copy link
Contributor Author

@bflad i've updated my PR according to your comment. Thanksfor the tip!

Acc tests after change:

make testacc TEST=./aws TESTARGS='-run=TestAccAWSLaunchTemplate_update'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -run=TestAccAWSLaunchTemplate_update -timeout 120m
=== RUN   TestAccAWSLaunchTemplate_update
--- PASS: TestAccAWSLaunchTemplate_update (88.05s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	88.416s

make testacc TEST=./aws TESTARGS='-run=TestAccAWSAutoScalingGroup_launchTemplate_update'
Password:
Password:
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -run=TestAccAWSAutoScalingGroup_launchTemplate_update -timeout 120m
=== RUN   TestAccAWSAutoScalingGroup_launchTemplate_update
--- PASS: TestAccAWSAutoScalingGroup_launchTemplate_update (175.86s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	176.213s

@gordonbondon gordonbondon changed the title [WIP] r/aws_launch_template: Set latest version computed on change r/aws_launch_template: Set latest version computed on change Jul 29, 2018
@bflad bflad removed the waiting-response Maintainers are waiting on response from community or contributor. label Jul 30, 2018
@bflad bflad added this to the v1.30.0 milestone Jul 30, 2018
Copy link
Contributor

@bflad bflad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks @gordonbondon! 🚀

9 tests passed (all tests)
=== RUN   TestAccAWSLaunchTemplate_data
--- PASS: TestAccAWSLaunchTemplate_data (7.16s)
=== RUN   TestAccAWSLaunchTemplate_nonBurstable
--- PASS: TestAccAWSLaunchTemplate_nonBurstable (7.19s)
=== RUN   TestAccAWSLaunchTemplate_basic
--- PASS: TestAccAWSLaunchTemplate_basic (7.36s)
=== RUN   TestAccAWSLaunchTemplate_importData
--- PASS: TestAccAWSLaunchTemplate_importData (7.80s)
=== RUN   TestAccAWSLaunchTemplate_importBasic
--- PASS: TestAccAWSLaunchTemplate_importBasic (8.04s)
=== RUN   TestAccAWSLaunchTemplate_BlockDeviceMappings_EBS
--- PASS: TestAccAWSLaunchTemplate_BlockDeviceMappings_EBS (8.95s)
=== RUN   TestAccAWSLaunchTemplate_networkInterface
--- PASS: TestAccAWSLaunchTemplate_networkInterface (10.93s)
=== RUN   TestAccAWSLaunchTemplate_tags
--- PASS: TestAccAWSLaunchTemplate_tags (12.85s)
=== RUN   TestAccAWSLaunchTemplate_update
--- PASS: TestAccAWSLaunchTemplate_update (48.95s)

@bflad bflad merged commit 2a1a0d8 into hashicorp:master Jul 30, 2018
bflad added a commit that referenced this pull request Jul 30, 2018
@gordonbondon gordonbondon deleted the launch-template-latest-version branch July 30, 2018 18:09
@gordonbondon
Copy link
Contributor Author

🎉

@bflad
Copy link
Contributor

bflad commented Aug 2, 2018

This has been released in version 1.30.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 4, 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 4, 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. size/M Managed by automation to categorize the size of a PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants