0
votes

I'm trying to get some data using data source, but when defining the data source block and its output and trying to run the plan "before apply", I'm getting error that the resource not found status code: 404.

I understand data source only fetch existing data, so how can I bypass this error without having to comment out these lines till after terraform apply ?!

Another related question: What's the best practice for data source block location? Is in in the main.tf or in the outputs.tf or elsewhere?

Thanks.

1

1 Answers

1
votes

Typically a particular Terraform configuration should either directly manage an object or read that object from elsewhere. It sounds like you've mixed both together in the same configuration, which has therefore left Terraform unclear as to what you are asking it to do.

If your configuration is already creating a particular object then you can typically refer to the attributes from that object in order to get equivalent information to what you'd get from a data resource retrieving that same object, and by passing data around through expressions you'll implicitly give Terraform the information it needs about the appropriate ordering of the operations.

Unfortunately your question is very general and doesn't include any specific examples of what you're working on, so I can't say anything more concrete than this, but if you are running into this situation as a result of decomposing your infrastructure into multiple modules then you might find it useful to review the Module Composition section to see some different module design patterns that rely in various ways on data flow between modules.