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

Add support for source_workstation in workstations_workstation resource. #12549

Merged
merged 1 commit into from
Dec 17, 2024

Conversation

esu
Copy link
Contributor

@esu esu commented Dec 12, 2024

This adds support for workstation PD cloning using source_workstation. It can only be set during workstation resource creation and cannot be updated afterwards: https://cloud.google.com/workstations/docs/reference/rest/v1beta/projects.locations.workstationClusters.workstationConfigs.workstations#Workstation.FIELDS.source_workstation

The primary use case of this field is for recovery, so it doesn't seem possible to write an automated test for it. This is because a workstation must be started manually before it can be cloned, else its PD is not created. If there is a way to write a test that can send API calls outside of Terraform, please let me know.

Fixes hashicorp/terraform-provider-google#19730.

Release Note Template for Downstream PRs (will be copied)

See Write release notes for guidance.

workstations: add `source_workstation` field to `google_workstations_workstation` resource

Copy link

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

@ScottSuarez, 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
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 ( 1 file changed, 5 insertions(+))
google-beta provider: Diff ( 2 files changed, 29 insertions(+))
terraform-google-conversion: Diff ( 1 file changed, 10 insertions(+))

Missing test report

Your PR includes resource fields which are not covered by any test.

Resource: google_workstations_workstation (8 total tests)
Please add an acceptance test which includes these fields. The test should include the following:

resource "google_workstations_workstation" "primary" {
  source_workstation = # value needed
}

@modular-magician
Copy link
Collaborator

Tests analytics

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

Click here to see the affected service packages
  • workstations

🟢 All tests passed!

View the build log

Copy link
Contributor

@ScottSuarez ScottSuarez left a comment

Choose a reason for hiding this comment

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

Can you add tests for this field? Potentially an update and create test.

You can extend existing ones where appropriate

@esu
Copy link
Contributor Author

esu commented Dec 12, 2024

It's difficult to write a create test for this field because it requires a manual human interaction on a dependency resource. A create test would have to:

  1. Create a workstation
  2. Start the workstation so that its PDs are initialized, else the API will reject the next step (and StartWorkstation is not possible through Terraform)
  3. Create a second workstation specifying source_workstation to clone the first workstation's PDs

Is it possible to send GCP API calls without Terraform during a create test? Open to suggestions on how to implement this.
Lastly, if the field is immutable, does it need an update test?

@github-actions github-actions bot requested a review from ScottSuarez December 12, 2024 20:53
Copy link
Contributor

@ScottSuarez ScottSuarez left a comment

Choose a reason for hiding this comment

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

You can do a two step test where you first create a workstation. Then you add another workstation which depends on the previous in that config.

https://github.com/hashicorp/terraform-provider-google-beta/blob/dcc0e42c39d9a69a4d97a7d932cf1eae23835239/google-beta/services/workstations/resource_workstations_workstation_test.go#L12-L46

So your config would look something like

{
	Config: testAccWorkstationsWorkstation_initialWorkStation(context),
},
{
  // import verify 
}
{
	Config: testAccWorkstationsWorkstation_initialWorkStationWithSecondaryReference(context),
},
{
  // import verify 
}

@esu
Copy link
Contributor Author

esu commented Dec 12, 2024

I am not sure we can do that -- the initial workstation can be created using Terraform, but it's created in a STOPPED state in which it is not cloneable, even after the CREATE operation is reported as complete by the API.

In your example, creating a secondary workstation using source_workstation is "cloning" it, which the Workstations API will reject if the initial workstation is not manually started. Workstations are for human use and cannot be started using Terraform.

@github-actions github-actions bot requested a review from ScottSuarez December 12, 2024 22:04
Copy link

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

@ScottSuarez
Copy link
Contributor

Ah! I see! Thanks for that clarification! Let me try and test it locally.

@ScottSuarez ScottSuarez merged commit 3141d28 into GoogleCloudPlatform:main Dec 17, 2024
14 checks passed
@ScottSuarez
Copy link
Contributor

tested locally

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

Successfully merging this pull request may close these issues.

Add support for source_workstation to google_workstations_workstation
3 participants