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

Support import for google_compute_instance_group #201

Merged
merged 4 commits into from
Jul 20, 2017

Conversation

rosbo
Copy link
Contributor

@rosbo rosbo commented Jul 14, 2017

issue #182

cc/ @danawillow


## Import

Instance group can be imported using the `zone` and `name`, e.g.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just wondering if you and @danawillow have talked about what we want to do for region and zone across all importable resources - we've checked against the provider region, or against all the provider region's zones in the past to find objects by Id alone.

I like this approach a lot - it means we don't clutter read with parsing logic by using an import func, we don't need to write migration functions, and it lets users import resources from more than 1 region/1 set of zones inside a single provider. Are we going to use the same approach across all importable resources going forward and do we have a plan to bring it to older ones?

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 decided to import using zone/name because it is a valid case to have multiple instance groups with the same name across different zones.

I will sync up with @danawillow to ensure consistency on our approach for all importable resources.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After talking with @danawillow and Evan, we decided that import method should:

  • Always supports the fully specified resource identifier (implemented in this PR).
  • For convenience, we can add support for partial specification by name only if guessing the other parameters is feasible. The logic for guessing should be in the ImportFunc and not the read method to avoid polluting the read method's logic. If more than one resource match the name (e.g. two instance groups in two different zones), fail with an error message to avoid surprising behavior.
  • We will go ahead and submit this PR as is. I will add support for the convenient import by name only in a separate PR.
  • We should update the import method for all the other resources to support the fully specified resource. Otherwise, in the case where two resources have the same name in two different zones or regions, the user cannot import the resource.

Copy link
Collaborator

Choose a reason for hiding this comment

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

SGTM! 👍

Thanks for taking the time to flesh out a concrete plan for this.

@rosbo rosbo force-pushed the import_compute_instance_group branch from a26feea to 576d4d5 Compare July 17, 2017 17:17
Copy link
Contributor

@danawillow danawillow left a comment

Choose a reason for hiding this comment

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

You'll also want to add a migration fn in resource_compute_instance_group_migrate.go to change the ids of resources that already exist. The way things are right now aren't a huge deal since it looks like nothing is reading the id anymore, but just in case someone decides to in the future we should probably canonicalize all existing ids.

@danawillow
Copy link
Contributor

make testacc TEST=./google TESTARGS='-run=TestAccComputeInstanceGroup_'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./google -v -run=TestAccComputeInstanceGroup_ -timeout 120m
=== RUN   TestAccComputeInstanceGroup_import
--- PASS: TestAccComputeInstanceGroup_import (136.04s)
=== RUN   TestAccComputeInstanceGroup_basic
--- PASS: TestAccComputeInstanceGroup_basic (92.69s)
=== RUN   TestAccComputeInstanceGroup_update
--- PASS: TestAccComputeInstanceGroup_update (134.13s)
=== RUN   TestAccComputeInstanceGroup_outOfOrderInstances
--- PASS: TestAccComputeInstanceGroup_outOfOrderInstances (93.11s)
=== RUN   TestAccComputeInstanceGroup_network
--- PASS: TestAccComputeInstanceGroup_network (154.72s)
PASS
ok  	github.com/terraform-providers/terraform-provider-google/google	610.832s

@rosbo
Copy link
Contributor Author

rosbo commented Jul 18, 2017

Added ID state migration.

There was already a MigrateState function from version 0 to 1 but it wasn't properly setup. I have wired it properly. Let me know if you have any concerns about this.

}

for k, v := range tc.ExpectedAttributes {
if k == "id" {
Copy link
Contributor

Choose a reason for hiding this comment

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

empty if statement?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oupps. Removed. The id assertions is done above.

}{
"change instances from list to set": {
"v1 to v2": {
Copy link
Contributor

Choose a reason for hiding this comment

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

It doesn't look like this test is actually running:

=== RUN   TestComputeInstanceGroupMigrateState
2017/07/19 10:00:58 [INFO] Found Compute Instance Group State v0; migrating to v1
2017/07/19 10:00:58 [DEBUG] Attributes before migration: map[string]string{"instances.#":"1", "instances.0":"https://www.googleapis.com/compute/v1/projects/project_name/zones/zone_name/instances/instancegroup-test-1", "instances.1":"https://www.googleapis.com/compute/v1/projects/project_name/zones/zone_name/instances/instancegroup-test-0"}
2017/07/19 10:00:58 [DEBUG] Attributes after migration: map[string]string{"instances.#":"1", "instances.1519187872":"https://www.googleapis.com/compute/v1/projects/project_name/zones/zone_name/instances/instancegroup-test-0", "instances.764135222":"https://www.googleapis.com/compute/v1/projects/project_name/zones/zone_name/instances/instancegroup-test-1"}
--- PASS: TestComputeInstanceGroupMigrateState (0.00s)

It's not showing anything migrating to v2

Copy link
Contributor

Choose a reason for hiding this comment

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

wait just kidding, I forgot to actually pull your latest commit. Nothing to see here.

@rosbo rosbo force-pushed the import_compute_instance_group branch from cca2b3e to 6f083ba Compare July 19, 2017 17:19
@@ -108,6 +104,10 @@ func TestComputeInstanceGroupMigrateState_empty(t *testing.T) {
is = &terraform.InstanceState{}
is, err = resourceComputeInstanceGroupMigrateState(tc.StateVersion, is, meta)

// should handle non-nil but empty
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 these few lines can be removed (they're the same as what's directly above them)

@danawillow
Copy link
Contributor

👍 , merge at will

@rosbo rosbo merged commit 076d31d into hashicorp:master Jul 20, 2017
@rosbo rosbo deleted the import_compute_instance_group branch July 20, 2017 16:21
negz pushed a commit to negz/terraform-provider-google that referenced this pull request Oct 17, 2017
chrisst pushed a commit to chrisst/terraform-provider-google that referenced this pull request Nov 9, 2018
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 @chrisst
@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.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants