Skip to content

feat: implementation of spanner instance_type to be able to provision a FREE_INSTANCE via terraform #13851

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

ramonvermeulen
Copy link
Contributor

Solves hashicorp/terraform-provider-google#22596

feat: implementation of spanner instance_type to be able to provision a FREE_INSTANCE via terraform

  • had to implement a custom version of exactly_one_of because when provisioning a spanner instance with instance_type = FREE_INSTANCE neither one of num_nodes or processing_units or autoscaling_config is allowed to be configured.

Added / direct affected tests pass locally:

image

Couldn't run all tests locally with -run=TestAccSpannerInstance_ because I ran into some org / quota policies on my sandbox project.

Another thing to keep in mind, that makes testing a bit harder:

image

E.g.: tests always have to run on a "new" GCP project, not sure if that is solved within the CI?

Release Note Template for Downstream PRs (will be copied)

See Write release notes for guidance.

spanner: added field `instance_type` to the `google_spanner_instance` resource

@github-actions github-actions bot requested a review from slevenick May 5, 2025 15:27
Copy link

github-actions bot commented May 5, 2025

Hello! I am a robot. Tests will require approval from a repository maintainer to run. Googlers: see go/terraform-auto-test-runs to set up automatic test runs.

@slevenick, 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 awaiting-approval Pull requests that need reviewer's approval to run presubmit tests service/spanner and removed awaiting-approval Pull requests that need reviewer's approval to run presubmit tests labels May 5, 2025
@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 ( 4 files changed, 128 insertions(+), 4 deletions(-))
google-beta provider: Diff ( 4 files changed, 128 insertions(+), 4 deletions(-))
terraform-google-conversion: Diff ( 1 file changed, 35 insertions(+))

@modular-magician
Copy link
Collaborator

Tests analytics

Total tests: 44
Passed tests: 32
Skipped tests: 5
Affected tests: 7

Click here to see the affected service packages
  • spanner

Action taken

Found 7 affected test(s) by replaying old test recordings. Starting RECORDING based on the most recent commit. Click here to see the affected tests
  • TestAccSpannerInstance_basicWithAsymmetricAutoscalingConfigsUpdate
  • TestAccSpannerInstance_basicWithAutoscalingUsingNodeConfigUpdate
  • TestAccSpannerInstance_basicWithAutoscalingUsingNodeConfigUpdateDisableAutoscaling
  • TestAccSpannerInstance_basicWithAutoscalingUsingPrecessingUnitsConfigUpdateDisableAutoscaling
  • TestAccSpannerInstance_basicWithAutoscalingUsingProcessingUnitConfigUpdate
  • TestAccSpannerInstance_freeInstanceBasicUpdate
  • TestAccSpannerInstance_update

Get to know how VCR tests work

@modular-magician
Copy link
Collaborator

🟢 Tests passed during RECORDING mode:
TestAccSpannerInstance_basicWithAsymmetricAutoscalingConfigsUpdate [Debug log]
TestAccSpannerInstance_basicWithAutoscalingUsingNodeConfigUpdate [Debug log]
TestAccSpannerInstance_basicWithAutoscalingUsingNodeConfigUpdateDisableAutoscaling [Debug log]
TestAccSpannerInstance_basicWithAutoscalingUsingPrecessingUnitsConfigUpdateDisableAutoscaling [Debug log]
TestAccSpannerInstance_basicWithAutoscalingUsingProcessingUnitConfigUpdate [Debug log]
TestAccSpannerInstance_freeInstanceBasicUpdate [Debug log]
TestAccSpannerInstance_update [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

Copy link

github-actions bot commented May 8, 2025

@slevenick This PR has been waiting for review for 3 weekdays. Please take a look! Use the label disable-review-reminders to disable these notifications.

}

if count != 1 {
return nil, fmt.Errorf("Exactly one of `autoscaling_config`, `num_nodes`, or `processing_units` must be specified")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we want to throw this type of error here. exactly_one_of should present a plan-time error, but this is a runtime error.

We may need to remove the exactly_one_of, or replace it with at_least_one_of and include instance_type

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the problem I ran into is that exactly_one_of that was already configured for num_nodes, processing_units and autoscaling_config. However, this now conflicts with instance_type == FREE_INSTANCE, e.g. with FREE_INSTANCE none of these fields are allowed to be configured, while with PROVISIONED instance exactly one of these fields should be configured. So my thought was to do a custom implementation in the encoder to solve this issue.

What would be your suggestion to solve this problem without causing a runtime error.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would probably move to at_least_one_of on all 4 of the fields. It won't be the most restrictive that we could be, but it will accomplish most of the goals at plan time. Most users will continue not setting instance_type, and instead have to specify one of the other fields

Copy link
Contributor Author

@ramonvermeulen ramonvermeulen May 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, that makes sense. With the idea of it being an edge case, and the API will reject it with a descriptive message during the apply phase anyways for the users that still configure both?

Copy link
Contributor Author

@ramonvermeulen ramonvermeulen May 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just applied this, but thinking about it now this doesn't solve the problem (test TestAccSpannerInstance_freeInstanceBasicUpdate also fails now). Because at_least_one_of requires that either num_nodes, processing_units or autoscaling_config is set. For a FREE_INSTANCE none of these fields can be set which conflicts with "at least one of ...".

I guess the best way moving forward is only setting conflicts?

@github-actions github-actions bot requested a review from slevenick May 10, 2025 06:59
@modular-magician modular-magician added the awaiting-approval Pull requests that need reviewer's approval to run presubmit tests label May 10, 2025
@modular-magician modular-magician removed the awaiting-approval Pull requests that need reviewer's approval to run presubmit tests label May 12, 2025
@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 ( 4 files changed, 128 insertions(+), 4 deletions(-))
google-beta provider: Diff ( 4 files changed, 128 insertions(+), 4 deletions(-))
terraform-google-conversion: Diff ( 1 file changed, 35 insertions(+))

@modular-magician
Copy link
Collaborator

Tests analytics

Total tests: 45
Passed tests: 39
Skipped tests: 5
Affected tests: 1

Click here to see the affected service packages
  • spanner

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
  • TestAccSpannerInstance_freeInstanceBasicUpdate

Get to know how VCR tests work

@modular-magician
Copy link
Collaborator

🔴 Tests failed during RECORDING mode:
TestAccSpannerInstance_freeInstanceBasicUpdate [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

@github-actions github-actions bot requested a review from slevenick May 12, 2025 13:54
@modular-magician modular-magician added the awaiting-approval Pull requests that need reviewer's approval to run presubmit tests label May 12, 2025
@ramonvermeulen ramonvermeulen force-pushed the ramon/22596-google-spanner-instance-type branch 8 times, most recently from 55f8aec to 59bdfb5 Compare May 12, 2025 14:55
@ramonvermeulen ramonvermeulen force-pushed the ramon/22596-google-spanner-instance-type branch from 59bdfb5 to d9c56f9 Compare May 12, 2025 14:56
@ramonvermeulen ramonvermeulen force-pushed the ramon/22596-google-spanner-instance-type branch from d9c56f9 to 773c866 Compare May 12, 2025 14:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting-approval Pull requests that need reviewer's approval to run presubmit tests service/spanner
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants