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

tpgresource: added support for default location in tpgresource.ReplaceVars #12320

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

wyardley
Copy link
Contributor

This supports inferring {{location}} from the provider (similar to what is done with {{region}} and {{zone}} in
tpgresource.ReplaceVars(), vs. just taking a value if it's explicitly set.

Even if all tests pass, it's probably necessary for someone who understands how this is used to weigh in and make sure this isn't likely to have any unintended consequences / side effects.

While ReplaceVars() is used all over the place, like the replacements for {{region}} and {{zone}}, BuildReplacementFunc() is using a method (GetLocation(), in this case) that was seemingly originally intended for use with GKE clusters, but probably generically will work in some situations.

In this case, for an artifact registry repository resource with a location set at provider level, this fixes some issues with import if the resource is in the same region that's configured at provider level.

Part of hashicorp/terraform-provider-google#19266

Release Note Template for Downstream PRs (will be copied)

See Write release notes for guidance.


…ceVars`

This supports inferring `{{location}}` from the provider (similar to
what is done with `{{region}}` and `{{zone}}` in
`tpgresource.ReplaceVars()`

Part of hashicorp/terraform-provider-google#19266
Copy link

Hello! I am a robot. Tests will require approval from a repository maintainer to run.

@zli82016, a repository maintainer, has been assigned to review your changes. If you have not received review feedback within 2 business days, please leave a comment on this PR asking them to take a look.

You can help make sure that review is quick by doing a self-review and by running impacted tests locally.

@modular-magician modular-magician added the awaiting-approval Pull requests that needs reviewer's approval to run presubmit tests label Nov 13, 2024
@modular-magician modular-magician removed the awaiting-approval Pull requests that needs reviewer's approval to run presubmit tests label Nov 13, 2024
@modular-magician
Copy link
Collaborator

Hi there, I'm the Modular magician. I've detected the following information about your changes:

Diff report

Your PR generated some diffs in downstreams - here they are.

google provider: Diff ( 2 files changed, 53 insertions(+), 1 deletion(-))
google-beta provider: Diff ( 2 files changed, 53 insertions(+), 1 deletion(-))

@wyardley
Copy link
Contributor Author

I'll take a look at the TGC unit test failures later as well. But would be good to get some input from whoever has some institutional knowledge about this area of the codebase.

@modular-magician
Copy link
Collaborator

Tests analytics

Total tests: 4292
Passed tests: 3831
Skipped tests: 410
Affected tests: 51

Click here to see the affected service packages

All service packages are affected

Action taken

Found 51 affected test(s) by replaying old test recordings. Starting RECORDING based on the most recent commit. Click here to see the affected tests
  • TestAccBackupDRBackupPlan_backupDrBackupPlanSimpleExample
  • TestAccBigQueryJob_bigqueryJobCopyExample
  • TestAccBigQueryJob_bigqueryJobCopyTableReferenceExample
  • TestAccBigQueryJob_bigqueryJobExtractExample
  • TestAccBigQueryJob_bigqueryJobExtractTableReferenceExample
  • TestAccBigQueryJob_bigqueryJobLoadExample
  • TestAccBigQueryJob_bigqueryJobLoadGeojsonExample
  • TestAccBigQueryJob_bigqueryJobLoadParquetExample
  • TestAccBigQueryJob_bigqueryJobLoadTableReferenceExample
  • TestAccBigQueryJob_bigqueryJobQueryExample
  • TestAccBigQueryJob_bigqueryJobQueryTableReferenceExample
  • TestAccCloudBuildTrigger_available_secrets_config
  • TestAccCloudBuildTrigger_basic
  • TestAccCloudBuildTrigger_basic_bitbucket
  • TestAccCloudBuildTrigger_cloudbuildTriggerAllowExitCodesExample
  • TestAccCloudBuildTrigger_cloudbuildTriggerAllowFailureExample
  • TestAccCloudBuildTrigger_cloudbuildTriggerBuildExample
  • TestAccCloudBuildTrigger_cloudbuildTriggerManualBitbucketServerExample
  • TestAccCloudBuildTrigger_cloudbuildTriggerManualExample
  • TestAccCloudBuildTrigger_cloudbuildTriggerServiceAccountExample
  • TestAccCloudBuildTrigger_cloudbuildTriggerWebhookConfigExample
  • TestAccCloudBuildTrigger_disable
  • TestAccCloudBuildTrigger_fullStep
  • TestAccCloudBuildTrigger_pubsub_config
  • TestAccCloudBuildTrigger_webhook_config
  • TestAccContainerCluster_withFleetConfig
  • TestAccDialogflowCXEntityType_dialogflowcxEntityTypeFullExample
  • TestAccDialogflowCXEntityType_update
  • TestAccDialogflowCXEnvironment_dialogflowcxEnvironmentFullExample
  • TestAccDialogflowCXEnvironment_dialogflowcxEnvironmentRegionalExample
  • TestAccDialogflowCXEnvironment_update
  • TestAccDialogflowCXFlow_defaultStartFlow
  • TestAccDialogflowCXFlow_dialogflowcxFlowBasicExample
  • TestAccDialogflowCXFlow_dialogflowcxFlowDefaultStartFlowExample
  • TestAccDialogflowCXFlow_dialogflowcxFlowFullExample
  • TestAccDialogflowCXFlow_update
  • TestAccDialogflowCXIntent_defaultIntents
  • TestAccDialogflowCXIntent_dialogflowcxIntentDefaultNegativeIntentExample
  • TestAccDialogflowCXIntent_dialogflowcxIntentDefaultWelcomeIntentExample
  • TestAccDialogflowCXIntent_dialogflowcxIntentFullExample
  • TestAccDialogflowCXIntent_update
  • TestAccDialogflowCXPage_dialogflowcxPageFullExample
  • TestAccDialogflowCXPage_update
  • TestAccDialogflowCXTestCase_dialogflowcxTestCaseFullExample
  • TestAccDialogflowCXTestCase_update
  • TestAccDialogflowCXVersion_dialogflowcxVersionFullExample
  • TestAccDialogflowCXVersion_dialogflowcxVersionRegionalExample
  • TestAccDialogflowCXVersion_update
  • TestAccDialogflowCXWebhook_dialogflowcxWebhookFullExample
  • TestAccDialogflowCXWebhook_update
  • TestAccDocumentAIProcessorDefaultVersion_documentaiDefaultVersionExample

Get to know how VCR tests work

@modular-magician
Copy link
Collaborator

🔴 Tests failed during RECORDING mode:
TestAccBackupDRBackupPlan_backupDrBackupPlanSimpleExample [Error message] [Debug log]
TestAccBigQueryJob_bigqueryJobCopyExample [Error message] [Debug log]
TestAccBigQueryJob_bigqueryJobCopyTableReferenceExample [Error message] [Debug log]
TestAccBigQueryJob_bigqueryJobExtractExample [Error message] [Debug log]
TestAccBigQueryJob_bigqueryJobExtractTableReferenceExample [Error message] [Debug log]
TestAccBigQueryJob_bigqueryJobLoadExample [Error message] [Debug log]
TestAccBigQueryJob_bigqueryJobLoadGeojsonExample [Error message] [Debug log]
TestAccBigQueryJob_bigqueryJobLoadParquetExample [Error message] [Debug log]
TestAccBigQueryJob_bigqueryJobLoadTableReferenceExample [Error message] [Debug log]
TestAccBigQueryJob_bigqueryJobQueryExample [Error message] [Debug log]
TestAccBigQueryJob_bigqueryJobQueryTableReferenceExample [Error message] [Debug log]
TestAccCloudBuildTrigger_available_secrets_config [Error message] [Debug log]
TestAccCloudBuildTrigger_basic [Error message] [Debug log]
TestAccCloudBuildTrigger_basic_bitbucket [Error message] [Debug log]
TestAccCloudBuildTrigger_cloudbuildTriggerAllowExitCodesExample [Error message] [Debug log]
TestAccCloudBuildTrigger_cloudbuildTriggerAllowFailureExample [Error message] [Debug log]
TestAccCloudBuildTrigger_cloudbuildTriggerBuildExample [Error message] [Debug log]
TestAccCloudBuildTrigger_cloudbuildTriggerManualBitbucketServerExample [Error message] [Debug log]
TestAccCloudBuildTrigger_cloudbuildTriggerManualExample [Error message] [Debug log]
TestAccCloudBuildTrigger_cloudbuildTriggerServiceAccountExample [Error message] [Debug log]
TestAccCloudBuildTrigger_cloudbuildTriggerWebhookConfigExample [Error message] [Debug log]
TestAccCloudBuildTrigger_disable [Error message] [Debug log]
TestAccCloudBuildTrigger_fullStep [Error message] [Debug log]
TestAccCloudBuildTrigger_pubsub_config [Error message] [Debug log]
TestAccCloudBuildTrigger_webhook_config [Error message] [Debug log]
TestAccContainerCluster_withFleetConfig [Error message] [Debug log]
TestAccDialogflowCXEntityType_dialogflowcxEntityTypeFullExample [Error message] [Debug log]
TestAccDialogflowCXEntityType_update [Error message] [Debug log]
TestAccDialogflowCXEnvironment_dialogflowcxEnvironmentFullExample [Error message] [Debug log]
TestAccDialogflowCXEnvironment_dialogflowcxEnvironmentRegionalExample [Error message] [Debug log]
TestAccDialogflowCXEnvironment_update [Error message] [Debug log]
TestAccDialogflowCXFlow_defaultStartFlow [Error message] [Debug log]
TestAccDialogflowCXFlow_dialogflowcxFlowBasicExample [Error message] [Debug log]
TestAccDialogflowCXFlow_dialogflowcxFlowDefaultStartFlowExample [Error message] [Debug log]
TestAccDialogflowCXFlow_dialogflowcxFlowFullExample [Error message] [Debug log]
TestAccDialogflowCXFlow_update [Error message] [Debug log]
TestAccDialogflowCXIntent_defaultIntents [Error message] [Debug log]
TestAccDialogflowCXIntent_dialogflowcxIntentDefaultNegativeIntentExample [Error message] [Debug log]
TestAccDialogflowCXIntent_dialogflowcxIntentDefaultWelcomeIntentExample [Error message] [Debug log]
TestAccDialogflowCXIntent_dialogflowcxIntentFullExample [Error message] [Debug log]
TestAccDialogflowCXIntent_update [Error message] [Debug log]
TestAccDialogflowCXPage_dialogflowcxPageFullExample [Error message] [Debug log]
TestAccDialogflowCXPage_update [Error message] [Debug log]
TestAccDialogflowCXTestCase_dialogflowcxTestCaseFullExample [Error message] [Debug log]
TestAccDialogflowCXTestCase_update [Error message] [Debug log]
TestAccDialogflowCXVersion_dialogflowcxVersionFullExample [Error message] [Debug log]
TestAccDialogflowCXVersion_dialogflowcxVersionRegionalExample [Error message] [Debug log]
TestAccDialogflowCXVersion_update [Error message] [Debug log]
TestAccDialogflowCXWebhook_dialogflowcxWebhookFullExample [Error message] [Debug log]
TestAccDialogflowCXWebhook_update [Error message] [Debug log]
TestAccDocumentAIProcessorDefaultVersion_documentaiDefaultVersionExample [Error message] [Debug log]

🔴 Errors occurred during RECORDING mode. Please fix them to complete your PR.

View the build log or the debug log for each test

@zli82016
Copy link
Member

zli82016 commented Nov 13, 2024

It becomes much more complicated then the original issue and some other tests failed. It looks like there are some special cases for the location field in some resources. Do you want to just fix the import issue for google_artifact_registry_repository instead of modifying the tpgresource.ReplaceVars function?

@wyardley
Copy link
Contributor Author

Unless it's something very trivially fixable, I'm probably going to move this one to draft soon., but if you have ideas (or if there are folks you can pull in who have ideas) about generally speaking whether this is a good idea, and how it should work), would appreciate the comments.

I did take a look at some of the tests, and at least the cloudbuild ones seem to fail for me off of main as well, though I don't see an open ticket for them. The bigquery ones seem a bit easier to reproduce... for example, TestAccBigQueryJob_bigqueryJobCopyExample. High level, seems like
location=US is getting rewritten to location=us-central by ReplaceVars, maybe because thegoogle_bigquery_job itself doesn't have location set, and US is the default for bigquery specifically.

@wyardley
Copy link
Contributor Author

@zli82016 I'm definitely going to punt on this for now.

I'm not sure if there are any easy fixes for the google_artifact_registry_repository thing that are worth it -- I could switch to custom code for the import function, and use something other than ReplaceVars() in it, but it still wouldn't be easy to fix the problem for multi-region repositories anyway, so I'm inclined to PR some of my docs fixes separately (and maybe remove {{repository_id}} as a valid import path entirely?). I may leave this open as a draft for a few weeks in case anyone has thoughts / comments about how it "should" work.

@wyardley wyardley marked this pull request as draft November 13, 2024 23:21
@zli82016
Copy link
Member

I did take a look at some of the tests, and at least the cloudbuild ones seem to fail for me off of main as well, though I don't see an open ticket for them. The bigquery ones seem a bit easier to reproduce... for example, TestAccBigQueryJob_bigqueryJobCopyExample. High level, seems like location=US is getting rewritten to location=us-central by ReplaceVars, maybe because thegoogle_bigquery_job itself doesn't have location set, and US is the default for bigquery specifically.

That is the reason for the tests failure in google_bigquery_job

Also, I checked the resource google_cloudbuild_trigger and there is a custom code for the location field in import function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants