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

allow updating additional_zones, turn it into a set #152

Merged
merged 3 commits into from
Jul 5, 2017

Conversation

danawillow
Copy link
Contributor

Fixes #104.

additional_zones had to be turned into a set because GCP returns them in alphabetical order regardless of the order they're set in the request.

if waitErr != nil {
return waitErr
if d.HasChange("additional_zones") {
azs := convertStringArr(d.Get("additional_zones").(*schema.Set).List())
Copy link
Contributor

Choose a reason for hiding this comment

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

convertStringArr is defined in resource_compute_target_pool.go - is there a better place to put it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I put it in provider.go, I think that's the best option we have righ tnow.

return waitErr
if d.HasChange("additional_zones") {
azs := convertStringArr(d.Get("additional_zones").(*schema.Set).List())
locations := append(azs, zoneName)
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 guessing there's no problem if a location is repeated multiple times (i.e. the API doesn't throw an error)? Otherwise it might make sense to do this call before converting it to a list

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch! The API does throw an error. I just added a check like we have in Create

switch v {
case 0:
log.Println("[INFO] Found Container Cluster State v0; migrating to v1")
is, err := migrateClusterStateV0toV1(is)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this can be shorted to just

return migrateCLusterStateV0toV1(is)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

}
}

func migrateClusterStateV0toV1(is *terraform.InstanceState) (*terraform.InstanceState, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: capital 't' in the to part of migrateClusterStateV0toV1?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Leaving it lowercase to match the other files

@@ -219,6 +231,10 @@ func testAccCheckContainerClusterDestroy(s *terraform.State) error {
return nil
}

var setFields map[string]struct{} = map[string]struct{}{
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this just be a list/set of strings rather than having an unused struct{} value?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is basically how you do a set in go, since there's no native set type (there's the terraform-specific one but I don't want to rely on terraform implementation in tests), and lists don't have a contains function so you'd have to scan the whole thing.

Copy link
Contributor

Choose a reason for hiding this comment

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

:( OK

"change additional_zones from list to set": {
StateVersion: 0,
Attributes: map[string]string{
"additional_zones.#": "1",
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be 2?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup! Done.

Copy link
Contributor

@selmanj selmanj left a comment

Choose a reason for hiding this comment

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

👍

@danawillow danawillow merged commit ae5ea9f into hashicorp:master Jul 5, 2017
@danawillow danawillow deleted the is-104 branch July 5, 2017 23:00
negz pushed a commit to negz/terraform-provider-google that referenced this pull request Oct 17, 2017
luis-silva pushed a commit to luis-silva/terraform-provider-google that referenced this pull request May 21, 2019
<!-- This change is generated by MagicModules. -->
/cc @danawillow
@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 👉 [email protected]. 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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Upgrade a GKE cluster from single zone to multi zone without recreating it
2 participants