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

Changed google_compute_instance_group_manager target_size default to 0. #65

Merged

Conversation

rileykarson
Copy link
Collaborator

Set the default target_size to 0 so that target sizes of 0 don't get set as the old default of 1. Existing configurations won't change as a result of changing the default, since the field is computed.

This is not a breaking change for existing configurations; resources with no value set will stay at their current setting. Scripts that rely on the old default of 1 at creation time will need to be updated.

Fixes #13
@danawillow

@rileykarson
Copy link
Collaborator Author

Related: hashicorp/terraform#5694 tracks the ability to both have a default of 1 + allow 0 values for this field.

@@ -256,7 +256,6 @@ func resourceComputeInstanceGroupManagerRead(d *schema.ResourceData, meta interf
d.Set("named_port", flattenNamedPorts(manager.NamedPorts))
d.Set("fingerprint", manager.Fingerprint)
d.Set("instance_group", manager.InstanceGroup)
d.Set("target_size", manager.TargetSize)
Copy link
Contributor

Choose a reason for hiding this comment

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

This was removed because it could change with the autoscaler, right? If so mind adding a comment of that nature?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It was getting set twice before, the other d.Set is just out of view here.

Copy link
Contributor

Choose a reason for hiding this comment

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

boooo github

@@ -132,18 +132,18 @@ func resourceComputeInstanceGroupManagerCreate(d *schema.ResourceData, meta inte
return err
}

// Get group size, default to 1 if not given
var target_size int64 = 1
var targetSize int64 = 0
Copy link
Contributor

Choose a reason for hiding this comment

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

targetSize := 0

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Go is convinced this is an int, not int64 with that syntax; using targetSize := int64(0)

}

// Build the parameter
manager := &compute.InstanceGroupManager{
Name: d.Get("name").(string),
BaseInstanceName: d.Get("base_instance_name").(string),
InstanceTemplate: d.Get("instance_template").(string),
TargetSize: target_size,
TargetSize: targetSize,
ForceSendFields: []string{"TargetSize"},
Copy link
Contributor

Choose a reason for hiding this comment

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

might be nice to have a comment here like "Force send TargetSize to allow it to have a value of 0"

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

@@ -382,23 +381,19 @@ func resourceComputeInstanceGroupManagerUpdate(d *schema.ResourceData, meta inte
d.SetPartial("named_port")
}

// If size changes trigger a resize
// We won't ever see changes if target_size is unset
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not quite sure what this comment is trying to tell me

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Removed.

if err != nil {
return fmt.Errorf("Error updating InstanceGroupManager: %s", err)
}
target_size := int64(d.Get("target_size").(int))
Copy link
Contributor

Choose a reason for hiding this comment

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

targetSize

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

func TestAccInstanceGroupManager_targetSizeZero(t *testing.T) {
var manager compute.InstanceGroupManager

template := fmt.Sprintf("igm-test-%s", acctest.RandString(10))
Copy link
Contributor

Choose a reason for hiding this comment

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

optional nit: templateName, igmName

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

* `target_size` - (Optional) If not given at creation time, this defaults to 1.
Do not specify this if you are managing the group with an autoscaler, as
this will cause fighting.
* `target_size` - (Optional, Default `0`) The target number of running instances for this managed
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we normally put the default in that spot? I don't necessarily have a problem with it, but I think normally we just put it in the description.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We use that style in a few places, I think I happened to have seen one of those right before writing this. Updated.

@danawillow
Copy link
Contributor

TF_ACC=1 go test ./google -v -run=TestAccInstanceGroupManager -timeout 120m
=== RUN   TestAccInstanceGroupManager_importBasic
--- PASS: TestAccInstanceGroupManager_importBasic (253.35s)
=== RUN   TestAccInstanceGroupManager_importUpdate
--- PASS: TestAccInstanceGroupManager_importUpdate (263.10s)
=== RUN   TestAccInstanceGroupManager_basic
--- PASS: TestAccInstanceGroupManager_basic (222.92s)
=== RUN   TestAccInstanceGroupManager_targetSizeZero
--- PASS: TestAccInstanceGroupManager_targetSizeZero (46.14s)
=== RUN   TestAccInstanceGroupManager_update
--- PASS: TestAccInstanceGroupManager_update (288.82s)
=== RUN   TestAccInstanceGroupManager_updateLifecycle
--- PASS: TestAccInstanceGroupManager_updateLifecycle (114.07s)
=== RUN   TestAccInstanceGroupManager_updateStrategy
--- PASS: TestAccInstanceGroupManager_updateStrategy (231.41s)
=== RUN   TestAccInstanceGroupManager_separateRegions
--- PASS: TestAccInstanceGroupManager_separateRegions (231.78s)
PASS

@danawillow danawillow merged commit fc3d41e into hashicorp:master Jun 16, 2017
pdecat pushed a commit to pdecat/terraform-provider-google that referenced this pull request Jun 29, 2017
…nager-target-size

Changed google_compute_instance_group_manager target_size default to 0.
chrisst pushed a commit to chrisst/terraform-provider-google that referenced this pull request Nov 9, 2018
…nager-target-size

Changed google_compute_instance_group_manager target_size default to 0.
luis-silva pushed a commit to luis-silva/terraform-provider-google that referenced this pull request May 21, 2019
@ghost
Copy link

ghost commented Mar 31, 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 👉 hashibot-feedback@hashicorp.com. Thanks!

@ghost ghost locked and limited conversation to collaborators Mar 31, 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.

in google_compute_instance_group_manager if target_size is set to 0 value get ignored
2 participants