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 update support for bigtable clusters (such as resizing) #2350

Closed
wants to merge 3 commits into from

Conversation

stankiewicz
Copy link
Contributor

This PR is to address Issue #2521 for terraform-google-provider

What will be doable is scaling up and down number of clusters within instance without recreate.
If anything else is changed within cluster (change of disk, zone, name) it will be forced to recreate, so the behaviour mimics what is possible in UI.

fyi:

  • this is my first PR in this project
  • this is my first golang chunk of code
  • I'm new to TF

I've tested it with all kind of scenarios (resize, force recreate, both)

Any feedback highly appreciated so I can complete this PR.

@modular-magician
Copy link
Collaborator

Hello! I am a robot who works on Magic Modules PRs.

I have detected that you are a community contributor, so your PR will be assigned to someone with a commit-bit on this repo for initial review. They will authorize it to run through our CI pipeline, which will generate downstream PRs.

Thanks for your contribution! A human will be with you soon.

@rileykarson, please review this PR or find an appropriate assignee.

@stankiewicz
Copy link
Contributor Author

Will add test for this case.

@stankiewicz
Copy link
Contributor Author

One challenge I have,
Error: Provider produced inconsistent final plan

   " When expanding the plan for google_bigtable_instance.instance to include new
    values learned so far during apply, provider "google" produced an invalid new
    value for .cluster[1].zone: was cty.StringVal("us-central1-b"), but now
    cty.StringVal("us-central1-c")."

old_cluster_order = append(old_cluster_order, c)
}
}
for _, value := range clusters {
old_cluster_order = append(old_cluster_order, value)
}

err := diff.SetNew("cluster", old_cluster_order)
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 producing "Provider produced inconsistent final plan" after the change.

@rileykarson
Copy link
Member

This feature is being tracked at a new issue, hashicorp/terraform-provider-google#4318. (Sorry for the web of BT cluster updating issues! I think I missed an xref between them somewhere.) I've been working with a member of the BT team to have this functionality added directly to the BT client library as https://code-review.googlesource.com/c/gocloud/+/44410, which should land soon.

I'd strongly prefer we use that implementation instead of a separate one in TF. It's a commitment of mine to add it to the provider once that change lands. Given that, I'll probably take over the implementation unless you'd prefer to make the contribution.

FWIW, the error you encountered is because Terraform 0.12 and onwards are very strict that values shown in terraform plan match the ordering of values before/after terraform apply. I suspect that ordering in the CustomizeDiff is different than the real ordering applied in d.Set, causing the issue you encountered.

@stankiewicz
Copy link
Contributor Author

@rileykarson I've spoken to Gary about that. If his change can land soon then great!
I think that in that case you can take over integration or I can help under your guidance if you don't have capacity. I have some and some work is done here already as same logic will need to be implemented. I know where is the issue but I don't know yet how to fix it.

@stankiewicz
Copy link
Contributor Author

@rileykarson , I've updated code and tests, so I don't have any more "inconsistent final plan".

@rileykarson
Copy link
Member

Sorry for the wait- I think https://code-review.googlesource.com/c/gocloud/+/44410 is close to merging.

@@ -335,29 +364,43 @@ func resourceBigtableInstanceClusterReorderTypeList(diff *schema.ResourceDiff, m
return fmt.Errorf("config is invalid: Too many cluster blocks: No more than 4 \"cluster\" blocks are allowed")
}

if old_count.(int) != new_count.(int) {
Copy link
Member

Choose a reason for hiding this comment

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

The validation above here is worth preserving. I'd expect the new CustomizeDiff can supersede the rest, though.

@@ -236,16 +234,47 @@ func resourceBigtableInstanceUpdate(d *schema.ResourceData, meta interface{}) er
clusterMap[cluster.Name] = cluster
}

clusterTodoMap := make(map[string]interface{}, d.Get("cluster.#").(int))
Copy link
Member

Choose a reason for hiding this comment

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

I'd expect all this updating logic will go away, and get replaced by expanders very similar (if not identical) to Create; https://github.com/googleapis/google-cloud-go/blob/master/bigtable/admin.go#L1290 presents the same interface as it.

If they end up identical, feel free to refactor into a shared "expandBigtableInstance" method or just copy/paste. Either is fine.

new_clusters := make(map[string]interface{}, new_count.(int))
old_clusters := make(map[string]interface{}, old_count.(int))

for i := 0; i < new_count.(int) || i < old_count.(int); i++ {
Copy link
Member

Choose a reason for hiding this comment

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

Do you mind commenting the blocks like this with what they're doing? While it's possible to figure out, customizeDiffs are pretty finicky and it's a big help to be able to read quickly what they're doing.

Steps: []resource.TestStep{
{
Config: testAccBigtableInstance_one_in_the_cluster(instanceName, 3),
Check: resource.ComposeTestCheckFunc(
Copy link
Member

Choose a reason for hiding this comment

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

After rebasing, you'll probably need to change to use "import-style" checks. See https://github.com/GoogleCloudPlatform/magic-modules/pull/2409/files#diff-1296b3b7cf174ed6b01d0139e46bdd24L69-R76.

If you're seeing differences on cluster in "ImportStateVerify" that you don't expect, flag them here and don't worry about fixing them before pushing.

@rileykarson
Copy link
Member

Superseded with #2923

Thanks for taking the time to submit this! Sorry about the unfortunate timing between your work + the client lib work I'd been waiting to integrate, you did a great job with your changes.

@rileykarson rileykarson closed this Jan 7, 2020
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.

4 participants