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] core: Ensure that DataSourcesMap is handled during apply w/destroy #6913

Conversation

vancluever
Copy link
Contributor

Fixes #6881, which came up for me in #6911 as well.

WIP because I'm still trying to find a good way to test the *schema.Provider part.

During accpeptance tests of some of the first data sources (see
hashicorp#6881 and hashicorp#6911),
"unknown resource type" errors were coming up. It looks like
DataSourcesMap was not being taken into account in
*schema.Provider.Apply(), causing this error.

Also, added a skip in *schema.Resource.Apply() if
*schema.Resource.Destroy() is not defined, as data sources do not define
this, fixing the first error resulted in a nil pointer dereference.
@vancluever vancluever force-pushed the paybyphone_data_source_destroyfix branch from 4695251 to 2da4501 Compare May 28, 2016 17:40
@apparentlymart
Copy link
Contributor

@vancluever do you think this is the same issue @jen20 was trying to address in #6907?

We noticed during some debugging that we're generating "destroy" and "destroy tainted" nodes for data resources, which isn't supposed to happen and isn't handled properly in core... the "destroy" nodes always do the managed resource behavior, regardless of resource type.

He ultimately decided that this wasn't the right fix and we didn't discuss why, but just want to make sure we're not trying to solve the same problem in a multitude of different ways...

@vancluever
Copy link
Contributor Author

@apparentlymart this is a little different - the intention isn't to do anything with the graph, but one thing I did notice is that *schema.Provider.Apply() definitely does not look at the DataSourcesMap when it does its thing, and I didn't necessarily see anything that would lead me to believe that it would only apply to destroys, so it might have been something that should be checked anyway.

If anything I'd say the latter part is more around fixing the destroy walk issue, where we just ignore a missing Delete function and just proceed as normal. I'd image that won't be needed if a destroy walk is not happening on data sources.

I did notice that @jen20 did say that the destroy stuff was needed in some respect, I figured that you guys might have talked about it though :)

Some additional thoughts: I'm not too sure if ignoring Destroy when deleting is the best idea, as it might create a case where bugs with resources (versus data sources) that are not properly designed don't panic when they should, and I'm wondering if the logic put into *schema.Provider.Apply() should be put into the other functions there as well (namely *schema.Provider.Diff() and *schema.Provider.Refresh()).

@apparentlymart
Copy link
Contributor

The intention here is that we never enter schema.Provider.Apply for a data resource, since they are supposed to use the separate function ReadDataApply. So if we are ending up in this codepath for data resources then that's a bug in itself , and I think what @jen20 was looking at for #6907.

If I'm understanding this patch correctly then it makes it illegal to have both a resource and a data source both called aws_ami, which is in conflict with the intent here: we actually want to have matching names, so that e.g. resource "aws_ami" will create and manage an AMI while data "aws_ami" will retrieve the attributes of one that already exists, ideally with the attributes as consistent as possible between the two.

I suspect that whatever patch replaces #6907 will make this patch moot, since it will prevent us from reaching any of the branches you've created here... but we can wait until @jen20 has found a new path and confirm if this remains true.

@vancluever
Copy link
Contributor Author

Yeah, this is something I was wondering about. (I was thinking about renaming the data source in #6911 to aws_ami, incidentally).

Maybe my efforts are better focused on trying to figure out why the root of the issue exists then versus trying to work around it... seeing as I am still trying to figure out how to test schema.Provider.Apply properly and coming up blank, I'm not going to complain!

@vancluever
Copy link
Contributor Author

I think I've found the root cause, closing this now and will be putting in another PR in a sec.

@vancluever vancluever closed this May 29, 2016
@vancluever vancluever deleted the paybyphone_data_source_destroyfix branch May 30, 2016 01:47
@ghost
Copy link

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