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

"Unset" value for google_compute_region_instance_group_manager target_size argument? #667

Closed
danisla opened this issue Nov 1, 2017 · 7 comments

Comments

@danisla
Copy link
Contributor

danisla commented Nov 1, 2017

Related issues: #65, #13. Terraform #5471

Affected resources:

  • google_compute_region_instance_group_manager
  • google_compute_instance_group_manager

The target_size argument is mutually exclusive from the autoscaler resource. Is there a way to conditionally set the target_size argument so that when I'm using a autoscaler, it can be unset?

Setting it to0 forces my instance group to 0, which conflicts with the autoscaler.

target_size = "${var.autoscaling ? 0 : var.size}"

If 0 was the unset value, then the above indented use case would work. If 0 is valid, can we use -1?

@danawillow
Copy link
Contributor

Taking a look at what the cloud console claims a REST request for MIG with autoscaling is, I think the "unset" value is actually 1. Can you give that a try @danisla and see if that works?

And now it makes sense to me why 1 was originally the default here. I think the right answer for the future is to get rid of the Computed on it and instead set a default of 1, but leave in the ForceSendFields so people can set zero that want to. @rileykarson, if you have a moment, do you remember off the top of your head whether that was something you had tried? I just gave it a quick go and it looks like tests pass just fine.

@danisla
Copy link
Contributor Author

danisla commented Nov 2, 2017

@danawillow, I set the target_size = 1 and autoscaling min_replicas = 3 and terraform plan wants to change the target_size from 3 back to 1

Terraform will perform the following actions:

  ~ module.mig1.google_compute_region_instance_group_manager.default
      target_size: "3" => "1"

I get an error if I try to apply it:

Error: Error applying plan:

1 error(s) occurred:

* module.mig1.google_compute_region_instance_group_manager.default: 1 error(s) occurred:

* google_compute_region_instance_group_manager.default: Error resizing RegionInstanceGroupManager: googleapi: Error 400: The instance_group_manager resource 'projects/disla-terraform-admin-101/regions/us-central1/instanceGroupManagers/autoscale-cluster' is already being used by 'projects/disla-terraform-admin-101/regions/us-central1/autoscalers/autoscale-cluster', resourceInUseByAnotherResource

I have a hack workaround now, which forces the target_size to follow the min_replicas, I think this will only work if the cluster is at it's minimum scale though.

target_size = "${var.autoscaling ? var.min_replicas : var.size}"

@danawillow
Copy link
Contributor

Ah ok, that makes sense, and now I see why this was so tricky. We want target_size to be computed so that if it's unset it can just go ahead and change. But we also want to be able to specify a size of zero. Unfortunately, terraform can't currently tell the difference between unset and set to zero, so I don't think there's anything I can do in the google provider at the moment to fix this.

@apparentlymart you might be interested in this since I know you're working on improvements in this area.

@danawillow danawillow self-assigned this Nov 2, 2017
@danawillow danawillow removed their assignment Jan 16, 2018
@danawillow
Copy link
Contributor

I haven't actually checked, but this might be fixable now either with GetOkExists or CustomDiff. I'm not working on it right now though so unassigning.

@paddycarver
Copy link
Contributor

This should be resolved by the upcoming 0.12 changes.

luis-silva pushed a commit to luis-silva/terraform-provider-google that referenced this issue May 21, 2019
Signed-off-by: Modular Magician <magic-modules@google.com>
@rileykarson
Copy link
Collaborator

This should be possible in 0.12 with null.

@ghost
Copy link

ghost commented Jul 27, 2019

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 Jul 27, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants