0
votes

Working with google cloud here. I just imported a 'project' resource into Terraform from GCP. I'm seeing the following issue-

The resource is not comprehensively imported. The resource 'project' has multiple parameters to be set- each parameter a resource of their own. As you can see below, there is '.project' to name the project, '.new_service_project' to convert it to a service project and '.project_service[n]' for each enabled API of that project.

module.project_12.google_compute_shared_vpc_service_project.new_service_project
module.project_12.google_project.project
module.project_12.google_project_service.project_service[0]
module.project_12.google_project_service.project_service[1]
module.project_12.google_project_service.project_service[2]
module.project_12.google_project_service.project_service[3]
module.project_12.google_project_service.project_service[4]
module.project_12.google_project_service.project_service[5]
module.project_12.google_project_service.project_service[6]
module.project_12.google_project_service.project_service[7]

All these had to be done manually and separately by running separate terraform import commands as below. All imports were successful.

terraform import module.project_12.google_project.project proj-**
terraform import module.project_12.google_compute_shared_vpc_service_project.new_service_project proj-**
terraform import module.project_12.google_project_service.project_service[1] proj-**/cloudbilling.googleapis.com
terraform import module.project_12.google_project_service.project_service[2] proj-**/compute.googleapis.com
terraform import module.project_12.google_project_service.project_service[3] proj-**/bigquery-json.googleapis.com
...

Is there a way to comprehensively import these all together?

1
I'm keen to learn more about GCP and terraform and from there, attempt to assist. Can elaborate on what it is that you are doing? Ive used Terraform to define new resources in GCP but am missing what you mean when you say import a project. Is there a document or link that you might suggest I read to catch up with what you are attempting? - Kolban
Trying to import a resource in terraform.tfstate which was configured in the cloud provider before terraform was deployed. The import will sync terraform state with the cloud. - aplusp

1 Answers

1
votes

There's no way to do a bulk import in terraform at the moment. This proposal would extend the import command to accept a file. If that would help you, give that issue a thumbs up so it might get picked up faster.

For now, you could create (or generate) a batch script that runs terraform import for each resources.