You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request.
Please do not leave +1 or me too comments, they generate extra noise for issue followers and do not help prioritize the request.
If you are interested in working on this issue or have submitted a pull request, please leave a comment.
If an issue is assigned to a user, that user is claiming responsibility for the issue.
Customers working with a Google Technical Account Manager or Customer Engineer can ask them to reach out internally to expedite investigation and resolution of this issue.
Description
Proposed change
When parsing an import id with a regex, the regex should match the entire id, and not allow partial matches.
Currently, we allow substring matching of import ids. This can lead to unexpected behaviour (see below).
This could be introduced as a breaking change in the next major version. Before then, it could be surfaced as a warning/deprecation message to the user.
I would be happy to work on this feature, if it would be accepted.
Motivation
When importing resources, if the import id is in the incorrect format, the error message produced can be misleading and unhelpful.
My specific case was importing a google_dns_record_set. I provided the id in the format projects/alice/managedzones/bob/rrsets/charlie/A, and got the opaque failure:
Multiple formats are supported for the google_dns_record_set resource (source code). For an example resource, valid ids would be:
projects/alice/managedZones/bob/rrsets/charlie/A
alice/bob/charlie/A
bob/charlie/A
The import id is checked against each format in turn, with the first match being used. The pattern does not have to match the whole id, just a substring of it (source code).
I mistyped the id above with a lowercase z in managedzones. This causes the id to fail to match the first id format.
However, it matches the second id format coincidentally, as trailing characters are ignored:
This then leads to an API request that fails, and confusing error message Error: Error when reading or editing DNS Record Set "managedzones": googleapi: Error 403: Permission denied on resource project projects.
New or Affected Resource(s)
google_dns_record_set
google_*
Any resource that calls the ParseImportId function is affected.
Potential Terraform Configuration
Configuration would remain unchanged.
It would be nice to pass this through as an opt-in feature, and make it a breaking change in the next major release, but I don't think there's a nice way to do that without overloading the id field in the import block, which I don't think is a good idea.
Community Note
Description
Proposed change
When parsing an import id with a regex, the regex should match the entire id, and not allow partial matches.
Currently, we allow substring matching of import ids. This can lead to unexpected behaviour (see below).
This could be introduced as a breaking change in the next major version. Before then, it could be surfaced as a warning/deprecation message to the user.
I would be happy to work on this feature, if it would be accepted.
Motivation
When importing resources, if the import id is in the incorrect format, the error message produced can be misleading and unhelpful.
My specific case was importing a
google_dns_record_set
. I provided the id in the formatprojects/alice/managedzones/bob/rrsets/charlie/A
, and got the opaque failure:Cause
Multiple formats are supported for the
google_dns_record_set
resource (source code). For an example resource, valid ids would be:projects/alice/managedZones/bob/rrsets/charlie/A
alice/bob/charlie/A
bob/charlie/A
The import id is checked against each format in turn, with the first match being used. The pattern does not have to match the whole id, just a substring of it (source code).
I mistyped the id above with a lowercase
z
inmanagedzones
. This causes the id to fail to match the first id format.However, it matches the second id format coincidentally, as trailing characters are ignored:
This leads to extracting the field values as:
This then leads to an API request that fails, and confusing error message
Error: Error when reading or editing DNS Record Set "managedzones": googleapi: Error 403: Permission denied on resource project projects.
New or Affected Resource(s)
Any resource that calls the
ParseImportId
function is affected.Potential Terraform Configuration
Configuration would remain unchanged.
It would be nice to pass this through as an opt-in feature, and make it a breaking change in the next major release, but I don't think there's a nice way to do that without overloading the
id
field in theimport
block, which I don't think is a good idea.References
Regexp.FindStringSubmatch
reference: https://pkg.go.dev/regexp#Regexp.FindStringSubmatchimport
block reference: https://developer.hashicorp.com/terraform/language/import#syntaxterraform-provider-google/google/services/dns/resource_dns_record_set.go
Line 653 in 51fbf6a
terraform-provider-google/google/tpgresource/import.go
Line 31 in 51fbf6a
b/392628703
The text was updated successfully, but these errors were encountered: