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

ability to change instance_state #2956

Closed
wants to merge 3 commits into from

Conversation

agadelshin
Copy link

this PR add a feature requested in #1719

@ghost ghost added the size/l label Jan 29, 2019
@agadelshin
Copy link
Author

Should I do something to move this forward?

@rileykarson rileykarson self-requested a review March 6, 2019 19:02
@rileykarson rileykarson self-assigned this Mar 6, 2019
Copy link
Collaborator

@rileykarson rileykarson left a comment

Choose a reason for hiding this comment

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

Sorry! This fell under the radar.

I've mostly got higher level comments for now, make sure to include documentation as well.

@@ -762,6 +770,15 @@ func resourceComputeInstanceRead(d *schema.ResourceData, meta interface{}) error
d.Set("can_ip_forward", instance.CanIpForward)
d.Set("machine_type", GetResourceNameFromSelfLink(instance.MachineType))

// PROVISIONING, STAGING, RUNNING, STOPPING, STOPPED,
// // SUSPENDING, SUSPENDED, and TERMINATED
switch instance.Status {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Instead of flattening several states into either RUNNING or STOPPED, let's see if we can approach this from a different direction.

Right now, we use an Operation from the GCP API to tell if the instance has been provisioned. That doesn't tell us the status of the logical instance, just of the GCP resource. What if we also waited in Create for the instance to be RUNNING if the field is set to RUNNING, and stop it if it's set to TERMINATED.

Then, in Read we can wait to enter a terminal value and d.Set the exact value.

Finally, in Update if we're in a different state than expected we need to start / stop depending on which terminal state we want to be in. There's some additional nuance around this section; https://github.com/terraform-providers/terraform-provider-google/blob/master/google/resource_compute_instance.go#L1253

We'll also need to ensure that TERMINATED instances can be deleted.

The intent of this change would be that we're explicitly entering a terminal state in each of the CRUD methods, so Terraform will always be in a well-known place, and we won't need to worry about how we can transition from PROVISIONING -> TERMINATED for example.

google/resource_compute_instance.go Outdated Show resolved Hide resolved
google/resource_compute_instance.go Outdated Show resolved Hide resolved
@@ -964,6 +981,55 @@ func resourceComputeInstanceUpdate(d *schema.ResourceData, meta interface{}) err
d.SetPartial("tags")
}

if d.HasChange("instance_state") {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Stated above, but we'll need to watch out for changes to the instance state in this method; https://github.com/terraform-providers/terraform-provider-google/blob/master/google/resource_compute_instance.go#L1253

"Error starting an instance (%s): %s", d.Id(), err)
}

stateConf := &resource.StateChangeConf{
Copy link
Collaborator

Choose a reason for hiding this comment

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

We can probably extract this whole chunk into a function like waitForTerminalState and wait for either terminal status?

),
},
{
Config: testAccComputeInstance_stopped(instanceName),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Good start! We'll need to test a handful of cases though.

  • You've covered stopping an existing instance
  • And deleting a stopped instance
  • Updating a field on a stopped instance
  • Also updating a field that requires stopping, like machine_type
  • And doing that at the same time as stopping + starting for each of those
  • Creating a stopped instance

Copy link
Author

Choose a reason for hiding this comment

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

Thank you for useful suggestions and review. I've got you point, looks reasonable. I'm going to start with suggested test cases and will ask you for review!

@rileykarson
Copy link
Collaborator

Superseded with #4797

@rileykarson rileykarson closed this Dec 3, 2019
@ghost
Copy link

ghost commented Mar 29, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 [email protected]. Thanks!

@ghost ghost locked and limited conversation to collaborators Mar 29, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants