magic-modules icon indicating copy to clipboard operation
magic-modules copied to clipboard

Proposal: use embedded structs to minimise repetitive Configure functions on PF-implemented resources & data sources

Open SarahFrench opened this issue 1 year ago • 12 comments

Blocked by muxing fixes PR (this PR contains that PR's commits)

Description

Each resource and data source implemented with the plugin-framework will require a Configure method. The Configure method receives incoming 'meta'/meta data that describes how the provider is configured (the data is the result of the provider itself being configured) and needs to make sure that anything needed from that data is accessible to CRUD methods, later.

Currently, we just enable each resource and data source to access that data, as a Config struct, using a pointer. That pointer is stored in the struct that describes the resource/data source and is the receiver for all methods, including CRUD methods.

Because we implement the Configure method identically for each resource/data source we can define the method on a separate struct, func (ds *DataSourceWithConfigure) Configure , and embed the DataSourceWithConfigure struct inside each resource/data source.

This is an approach used in other providers, e.g. AWS provider: https://github.com/hashicorp/terraform-provider-aws/blob/main/internal/framework/resource_with_configure.go

If a particular resource needed different logic in Configure we can choose to not embed DataSourceWithConfigure.

Release Note Template for Downstream PRs (will be copied)


SarahFrench avatar Oct 04 '24 16:10 SarahFrench

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 ( 22 files changed, 243 insertions(+), 236 deletions(-)) google-beta provider: Diff ( 28 files changed, 275 insertions(+), 333 deletions(-))

Errors

google-beta provider:

  • The diff processor failed to build. This is usually due to the downstream provider failing to compile.

modular-magician avatar Oct 04 '24 16:10 modular-magician

Tests analytics

Total tests: 0 Passed tests: 0 Skipped tests: 0 Affected tests: 0

Click here to see the affected service packages

All service packages are affected

#### Non-exercised tests

Tests were added that are skipped in VCR:

  • TestAccSdkProvider_impersonate_service_account_delegates 🔴 Errors occurred during REPLAYING mode. Please fix them to complete your PR.

View the build log

modular-magician avatar Oct 04 '24 16:10 modular-magician

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 ( 22 files changed, 241 insertions(+), 273 deletions(-)) google-beta provider: Diff ( 28 files changed, 267 insertions(+), 370 deletions(-))

Errors

google-beta provider:

  • The diff processor failed to build. This is usually due to the downstream provider failing to compile.

modular-magician avatar Oct 04 '24 16:10 modular-magician

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 ( 22 files changed, 241 insertions(+), 273 deletions(-)) google-beta provider: Diff ( 28 files changed, 279 insertions(+), 379 deletions(-))

modular-magician avatar Oct 04 '24 16:10 modular-magician

Tests analytics

Total tests: 4139 Passed tests: 3717 Skipped tests: 411 Affected tests: 11

Click here to see the affected service packages

All service packages are affected

Action taken

Found 11 affected test(s) by replaying old test recordings. Starting RECORDING based on the most recent commit. Click here to see the affected tests
  • TestAccDataSourceGoogleFirebaseAndroidAppConfig
  • TestAccDataSourceGoogleFirebaseAppleAppConfig
  • TestAccDataformRepositoryReleaseConfig_dataformRepositoryReleaseConfigExample
  • TestAccDataformRepositoryWorkflowConfig_dataformRepositoryWorkflowConfigExample
  • TestAccDataformRepository_dataformRepositoryWithCloudsourceRepoAndSshExample
  • TestAccDataformRepository_updated
  • TestAccDataprocCluster_withAutoscalingPolicy
  • TestAccFirebaseWebApp_firebaseWebAppFull
  • TestAccFrameworkProviderBasePath_setBasePath
  • TestAccFrameworkProviderMeta_setModuleName
  • TestAccProjectIamPolicy_invalidMembers

Get to know how VCR tests work

modular-magician avatar Oct 04 '24 17:10 modular-magician

Tests analytics

Total tests: 4139 Passed tests: 3718 Skipped tests: 411 Affected tests: 10

Click here to see the affected service packages

All service packages are affected

Action taken

Found 10 affected test(s) by replaying old test recordings. Starting RECORDING based on the most recent commit. Click here to see the affected tests
  • TestAccDataSourceGoogleFirebaseAndroidAppConfig
  • TestAccDataSourceGoogleFirebaseAppleAppConfig
  • TestAccDataformRepositoryReleaseConfig_dataformRepositoryReleaseConfigExample
  • TestAccDataformRepositoryWorkflowConfig_dataformRepositoryWorkflowConfigExample
  • TestAccDataformRepository_dataformRepositoryWithCloudsourceRepoAndSshExample
  • TestAccDataformRepository_updated
  • TestAccDataprocCluster_withAutoscalingPolicy
  • TestAccFirebaseWebApp_firebaseWebAppFull
  • TestAccFrameworkProviderBasePath_setBasePath
  • TestAccFrameworkProviderMeta_setModuleName

Get to know how VCR tests work

modular-magician avatar Oct 04 '24 18:10 modular-magician

🟢 Tests passed during RECORDING mode: TestAccDataSourceGoogleFirebaseAndroidAppConfig[Debug log] TestAccDataSourceGoogleFirebaseAppleAppConfig[Debug log] TestAccFirebaseWebApp_firebaseWebAppFull[Debug log] TestAccFrameworkProviderBasePath_setBasePath[Debug log] TestAccFrameworkProviderMeta_setModuleName[Debug log] TestAccProjectIamPolicy_invalidMembers[Debug log]

🟢 No issues found for passed tests after REPLAYING rerun.


🔴 Tests failed during RECORDING mode: TestAccDataformRepositoryReleaseConfig_dataformRepositoryReleaseConfigExample[Error message] [Debug log] TestAccDataformRepositoryWorkflowConfig_dataformRepositoryWorkflowConfigExample[Error message] [Debug log] TestAccDataformRepository_dataformRepositoryWithCloudsourceRepoAndSshExample[Error message] [Debug log] TestAccDataformRepository_updated[Error message] [Debug log] TestAccDataprocCluster_withAutoscalingPolicy[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

modular-magician avatar Oct 04 '24 18:10 modular-magician

🟢 Tests passed during RECORDING mode: TestAccDataSourceGoogleFirebaseAndroidAppConfig[Debug log] TestAccDataSourceGoogleFirebaseAppleAppConfig[Debug log] TestAccFirebaseWebApp_firebaseWebAppFull[Debug log] TestAccFrameworkProviderBasePath_setBasePath[Debug log] TestAccFrameworkProviderMeta_setModuleName[Debug log]

🟢 No issues found for passed tests after REPLAYING rerun.


🔴 Tests failed during RECORDING mode: TestAccDataformRepositoryReleaseConfig_dataformRepositoryReleaseConfigExample[Error message] [Debug log] TestAccDataformRepositoryWorkflowConfig_dataformRepositoryWorkflowConfigExample[Error message] [Debug log] TestAccDataformRepository_dataformRepositoryWithCloudsourceRepoAndSshExample[Error message] [Debug log] TestAccDataformRepository_updated[Error message] [Debug log] TestAccDataprocCluster_withAutoscalingPolicy[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

modular-magician avatar Oct 04 '24 18:10 modular-magician

Checking if those test failures are still around: /gcbrun

Ah- merge conflicts stopped the build. I'll do it tomorrow

SarahFrench avatar Oct 14 '24 22:10 SarahFrench

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 ( 21 files changed, 240 insertions(+), 272 deletions(-)) google-beta provider: Diff ( 27 files changed, 276 insertions(+), 375 deletions(-))

modular-magician avatar Oct 15 '24 09:10 modular-magician

Tests analytics

Total tests: 4163 Passed tests: 3749 Skipped tests: 413 Affected tests: 1

Click here to see the affected service packages

All service packages are affected

Action taken

Found 1 affected test(s) by replaying old test recordings. Starting RECORDING based on the most recent commit. Click here to see the affected tests
  • TestAccComputeRegionPerInstanceConfig_removeInstanceOnDestroy

Get to know how VCR tests work

modular-magician avatar Oct 15 '24 10:10 modular-magician

🟢 Tests passed during RECORDING mode: TestAccComputeRegionPerInstanceConfig_removeInstanceOnDestroy[Debug log]

🟢 No issues found for passed tests after REPLAYING rerun.


🟢 All tests passed!

View the build log or the debug log for each test

modular-magician avatar Oct 15 '24 11:10 modular-magician

Just rebased, now that the muxing fixes are merged to main

SarahFrench avatar Nov 22 '24 13:11 SarahFrench

@c2thorn @NickElliot - I've added you as reviewers/assignees just so this doesn't fall off your radars, but I don't have any expectation of review. Feel free to implement these changes in different PRs if it's an approach that you want to use in future 😁

SarahFrench avatar Nov 22 '24 13:11 SarahFrench

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 ( 5 files changed, 102 insertions(+), 88 deletions(-)) google-beta provider: Diff ( 8 files changed, 118 insertions(+), 172 deletions(-))

modular-magician avatar Nov 22 '24 13:11 modular-magician

Tests analytics

Total tests: 4311 Passed tests: 3901 Skipped tests: 407 Affected tests: 3

Click here to see the affected service packages

All service packages are affected

Action taken

Found 3 affected test(s) by replaying old test recordings. Starting RECORDING based on the most recent commit. Click here to see the affected tests
  • TestAccApigeeDeveloper_apigeeDeveloperUpdateTest
  • TestAccComputeInstanceNetworkIntefaceWithSecurityPolicy
  • TestAccComputeRegionPerInstanceConfig_removeInstanceOnDestroy

Get to know how VCR tests work

modular-magician avatar Nov 22 '24 15:11 modular-magician

🟢 Tests passed during RECORDING mode: TestAccComputeRegionPerInstanceConfig_removeInstanceOnDestroy [Debug log]

🟢 No issues found for passed tests after REPLAYING rerun.


🔴 Tests failed during RECORDING mode: TestAccApigeeDeveloper_apigeeDeveloperUpdateTest [Error message] [Debug log] TestAccComputeInstanceNetworkIntefaceWithSecurityPolicy [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

modular-magician avatar Nov 22 '24 15:11 modular-magician