We are able to see the app engine details using gcloud command. However, TF import command is not importing the state of App engine using following command. Even we tried with project ID and defaultHostname of app engine at the end of terraform import command ( part of cloud resource id ) still it’s not importing the app engine details.
$ terraform import -var-file irn-xxxxx-xxx.tfvars google_app_engine_application.app apps/irn-xxxxx-xxx-xx
data.google_iam_policy.sa_user_for_root_runner[0]: Reading...
data.google_iam_policy.sa_user_for_root_runner[0]: Read complete after 0s [id=xxxxxxxxx]
data.null_data_source.sshkey[0]: Reading...
data.null_data_source.sshkey[0]: Read complete after 0s [id=static]
data.google_compute_subnetwork.subnet-ifnotconnect2hostproject[0]: Reading...
data.template_file.init_jumpbox_linux_script[0]: Reading...
data.template_file.init_jumpbox_linux_script[0]: Read complete after 0s [id=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx]
data.google_compute_subnetwork.subnet-ifnotconnect2hostproject[0]: Read complete after 0s [id=projects/host-xxxxx-xxxxx-1/regions/europe-xxxxx/subnetworks/xxxxx-xxxxxxx-xxxxxx-1-subnet3]
Import successful!
The resources that were imported are shown above. These resources are now in
your Terraform state and will henceforth be managed by Terraform.
In the latest release there is a bug where specifying an instance key that doesn’t match any of the instances declared in the configuration ends up not matching any of the objects after Terraform resolves for_each (or count) and so Terraform never actually visits the address specified on the command line and so doesn’t notice the problem.
I believe that others on the team are currently working on fixing that but in the meantime the solution is to correct your import address to match what’s declared in your configuration. You can find what’s declared in the configuration by running terraform plan and finding the “… will be created” action for the relevant resource instance and use exactly the address Terraform was proposing to create as your import destination.
(If the address contains any characters that your shell considers to be special, such as quotes, you’ll need to escape them to ensure that they get interpreted by Terraform instead of by your shell.)
Ah, it is as I thought. Because you have used count, google_app_engine_application.app is no longer the correct address to be passing on the import command line.
Once count is in use you must add a square-bracketed index to identify which element of the counted resource - in this case: google_app_engine_application.app[0]
Granted, this seems fairly academic when the count can only be zero or one, but it is still required.
Unfortunately, due to a bug, Terraform currently does not give good feedback when this is forgotten in an import command.