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

config: new "reverse" interpolation function #18887

Merged

Conversation

sargun
Copy link
Contributor

@sargun sargun commented Sep 17, 2018

It reverses a list.

@sargun
Copy link
Contributor Author

sargun commented Sep 17, 2018

First PR on Terraform. This is useful for https://www.terraform.io/docs/providers/aws/d/ami_ids.html, where it says:

ids is set to the list of AMI IDs, sorted by creation time in descending order.

Assuming you want it in ascending order, you need to reverse the list. for_each may solve this, but for existing terraform configurations, this is invaluable.

@apparentlymart
Copy link
Member

Hi @sargun! Thanks for working on this.

The implementation here looks good to me. The interpolation functions are frozen for the moment while we complete some refactoring in preparation for the 0.12 release, so we'll need to hold on merging this for a little while, but I've labelled this so we'll find it again during our 0.12 release preparation.

The way functions are defined will be changing once we complete this refactoring, so this PR will need some changes to adapt to the new style but we'd be happy to do that step at merge time since it'll just be the same mechanical updates we'll be doing for a number of other pending function pull requests.

Thanks again! We'll be back here to merge this as we get closer to the 0.12 release.

@sargun
Copy link
Contributor Author

sargun commented Sep 18, 2018

@apparentlymart Sounds good. Thanks for taking a look at it. Is there a rough timeline as to 0.12 yet?

inputList := args[0].([]ast.Variable)

reversedList := make([]ast.Variable, len(inputList))
for idx := range inputList {
Copy link

@theodesp theodesp Nov 9, 2018

Choose a reason for hiding this comment

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

One could say that you could iterate over len(inputList) /2 and do swaps:
example pseudocode

        r := make([]ast.Variable, len(inputList))
	copy(r, inputList)
	for i, j := 0, len(r)-1; i < len(r)/2; i, j = i+1, j-1 {
		r[i], r[j] = r[j], r[i]
	}
	return r, nil

@apparentlymart apparentlymart added this to the v0.12.0 milestone Nov 9, 2018
sargun and others added 2 commits March 19, 2019 16:39
This has the same functionality as the "reverse" function that was
implemented in the "config" package, but adapted to the new language type
system.
@apparentlymart apparentlymart force-pushed the add-reverse-interpolation-function branch from f3b5274 to 5922f5a Compare March 20, 2019 00:10
@apparentlymart
Copy link
Member

Sorry for the delay here, @sargun! I rebased your commit to latest master and then ported it into the new functions mechanism in 5922f5a. This'll be included in the forthcoming v0.12.0-beta2 release.

@apparentlymart apparentlymart merged commit 096b1bb into hashicorp:master Mar 20, 2019
@ghost
Copy link

ghost commented Aug 13, 2019

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 have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@hashicorp hashicorp locked and limited conversation to collaborators Aug 13, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants