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

Add support for indexing into variables #3

Merged
merged 1 commit into from
Feb 16, 2016
Merged

Conversation

jen20
Copy link
Contributor

@jen20 jen20 commented Feb 16, 2016

This adds support for indexing into variables of the new type "List". The syntax is typical C-style array syntax, so for example, the following is valid for interpolating the element of the list in variable foo at position 1:

"${foo[1]}"

There is a restriction that lists must be homogenous in type. This is to enable the type checker to work without having to actually perform the indexing operation. During discussion there was no compelling use case for lists of heterogenous types - this is open for discussion in future though if one is found.

@jen20
Copy link
Contributor Author

jen20 commented Feb 16, 2016

cc @phinze, @mitchellh.

@jen20 jen20 force-pushed the f-index-operation branch from f74742c to 350ebe6 Compare February 16, 2016 18:51
}

func (n *Index) Accept(v Visitor) Node {
//n.Key = n.Key.Accept(v)
Copy link
Contributor

Choose a reason for hiding this comment

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

Stray line here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch - will fix - that was actually what was causing the panic :-)

@jen20 jen20 force-pushed the f-index-operation branch from 350ebe6 to 0d1756f Compare February 16, 2016 19:01
true,
nil,
ast.TypeInvalid,
},
Copy link
Contributor

Choose a reason for hiding this comment

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

We should add a test here for tests sake that the index can be a reference to another variable ${foo[bar]}.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 and also that it can be the result of a second indexing operation. I'll add these.

This adds support for indexing into variables of the new type "List".
The syntax is typical C-style array syntax, so for example, the
following is valid for interpolating the element of the list in variable
foo at position 1:

    "${foo[1]}"

There is a restriction that lists must be homogenous in type. This is to
enable the type checker to work without having to actually perform the
indexing operation. During discussion there was no compelling use case
for lists of heterogenous types - this is open for discussion in future
though if one is found.
@jen20 jen20 force-pushed the f-index-operation branch from 865db3d to 730ac9b Compare February 16, 2016 19:29
@jen20
Copy link
Contributor Author

jen20 commented Feb 16, 2016

@mitchellh I went with your suggestion of listing the types which are present in the error - which was actually my original implementation hence the stray %s in the format string. There are also new tests for index keys being variables and results of other operations. Squashed into one commit for clean history.

@mitchellh
Copy link
Contributor

LGTM! Woohoo!

jen20 added a commit that referenced this pull request Feb 16, 2016
Add support for indexing into variables
@jen20 jen20 merged commit 0457360 into master Feb 16, 2016
@jen20 jen20 deleted the f-index-operation branch February 16, 2016 20:22
@VladRassokhin
Copy link
Contributor

Is this feature would be present in next Terraform release?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants