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

googleapi: Error 400: Invalid value for field 'region': 'global'. Unknown region., invalid when running import google without regions flag #1928

Open
Shion1305 opened this issue Sep 28, 2024 · 1 comment · May be fixed by #1930
Labels

Comments

@Shion1305
Copy link

When running terraformer import google without the regions flag, the following error appears in the log:

2024/09/29 03:03:13 googleapi: Error 400: Invalid value for field 'region': 'global'. Unknown region., invalid

Although this error doesn't stop the command from completing successfully, it's misleading and could cause confusion for users.

Cause:

The issue arises because, if the regions flag is not set, global is used as the default value for the region. However, global is not a valid region for this API call:

regionsGetCall := computeService.Regions.Get(project, regionName).Fields("name", "zones")

This call triggers the following gRPC API request:

GET https://compute.googleapis.com/compute/v1/projects/{project}/regions/{region}

Since global is not a recognized region, the API responds with an error.

Proposed Solution:

To fix this, the code should handle the case when the region is set to global by skipping the API call. This could be implemented by adding a conditional check in the getRegion function:

func getRegion(project, regionName string) *compute.Region {
	if regionName == "global" {
		return &compute.Region{}
	}
	computeService, err := compute.NewService(context.Background())
	if err != nil {
		log.Println(err)
		return &compute.Region{}
	}
	regionsGetCall := computeService.Regions.Get(project, regionName).Fields("name", "zones")
	region, err := regionsGetCall.Do()
	if err != nil {
		log.Println(err)
		return &compute.Region{}
	}
	return region
}

By making this change, the error message will no longer appear when global is used as the default region, and it will prevent unnecessary API requests.

Additional Information:

  • This issue only occurs when the regions flag is not provided.
  • The error message does not affect the overall functionality of the command.
@Shion1305 Shion1305 linked a pull request Sep 28, 2024 that will close this issue
Copy link

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@github-actions github-actions bot added the Stale label Nov 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant