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

WIP: implements aws_instances #12624

Closed
wants to merge 1 commit into from

Conversation

artburkart
Copy link
Contributor

@artburkart artburkart commented Mar 12, 2017

I'm not sure if it's acceptable to create an unfinished PR, but I hit a wall and am unsure what to do to resolve it. This PR is in response to the request for an "aws_instances" data source in Issue #12376. My approach was to make the returned data have a field called "instances", which would be a list of instances with the same format as the one returned in the "aws_instance" data source.

I wanted to be able to do something like this: https://gist.github.com/artburkart/16f88b5856861d164dae4b1aeefc0724

Because I wanted it to be similar to the "aws_route_table" data source which lets you do this: https://gist.github.com/artburkart/d5dd81302179493b2ab2c23fbfcb84b8

Everything seems to work. The multiple instances are getting queried and the data sources are getting populated, but for some reason, I can't get them to attach to the "aws_instances" ResourceData object. I have a feeling the problem is in the code here: https://github.com/artburkart/terraform/blob/e7f03452ffd58fc953c0915d77e5b8551e1f70f5/builtin/providers/aws/data_source_aws_instance.go#L315-L334

In this code I tried to follow the pattern laid out in data_source_aws_route_table, but something has gone awry. Whenever I perform a terraform apply with the configs I've provided in this PR, I get this:

data.aws_instances.boxes: Refreshing state...
data.aws_instances.boxes: Refreshing state...
Error applying plan:

1 error(s) occurred:

* data.template_file.boxes: Resource 'data.aws_instances.boxes' does not have attribute 'instances.0.subnet_id' for variable 'data.aws_instances.boxes.instances.0.subnet_id'

For some reason, data.aws_instances.boxes.instances does not exist, and I'm not exactly sure why not. I'm going to keep pecking at it, but if someone could offer some guidance, it would be much appreciated. Once I figure this bug out, I'll add all the tests and docs that generally accompany a new data source.

Cheers

I think this PR includes most of the work required to make aws_instances
work, except I'm stuck on a bug that is probably very simple and easy
to decipher. For some reason, the "instances" field on my resource doesn't
exist when it comes time to `terraform apply`. When this PR is complete, it
should close [Issue 12376](hashicorp#12376).
@artburkart
Copy link
Contributor Author

Well, I've noticed an indication of a bug. Some code is getting double-executed. I think, once I get to the bottom of that, I may have a working solution.

@cemo
Copy link

cemo commented Mar 17, 2017

eager to see :) What is the state of this issue?

@artburkart
Copy link
Contributor Author

I'm still debugging my code, will keep you posted.

@artburkart
Copy link
Contributor Author

I've figured out my problem. Everything I had was more-or-less correct, except I didn't realize resources and data sources must have at least one invocation of d.SetId(). I didn't do this, and so every time it got to the state writing portion of execution, it would see that no id was set and throw a fit.

I should have a working copy with tests and docs soon.

@artburkart
Copy link
Contributor Author

I'm closing this PR in favor of a different one I made. You can find it here:
#12856

@artburkart artburkart closed this Mar 18, 2017
@artburkart artburkart deleted the 12376-aws_instances branch March 18, 2017 23:40
@ghost
Copy link

ghost commented Apr 15, 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 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.

@ghost ghost locked and limited conversation to collaborators Apr 15, 2020
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.

3 participants