Terraform is trying to create the resource

Hi Team,

I have recently starting working on existing terraform code to support GCP. The issue I am facing is, terraform plan is suggesting to create a resource which does not exists in the configuration but presents in state file.

In GCP there is a pub-sub topic on the gcp console. When I run the plan it is presenting to create the subscription to that topic. That subscription configuration does not exists in the configuration files, but when I search in the respective state file, I could see that subscription.

If its there in the state, but does not exists in the configuration file, it should suggest for a deletion right ?

Some additional context :

previous team who worked, they were trying to import this resource into modules based on the comments I see, but I do not see that resource on the console and as well as in the module.

Can someone please some direction on how to look at this.

Thank you in advance

Hi @dumpap,

The only explanation I can offer is that you might be looking at the wrong configuration, state, or both; and they are not the ones that are being used by Terraform for the plan. Terraform cannot plan the creation of a resource if that resource does not exist in the configuration. Maybe carefully inspect the module paths to make sure there was no other refactoring going on at the same time.

One detail which could be confusing is that Terraform will not necessarily report that a resource will be deleted if it only exists in the state and that resource also no longer exists in the real infrastructure. If the provider indicates that the resource is gone during the refresh phase of planning, then Terraform knows there is nothing to delete and does not plan any change.