-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Conversation
|
||
## Import | ||
|
||
Instance group can be imported using the `zone` and `name`, e.g. |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
a26feea
to
576d4d5
Compare
There was a problem hiding this 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.
|
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" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
empty if statement?
There was a problem hiding this comment.
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": { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
cca2b3e
to
6f083ba
Compare
@@ -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 |
There was a problem hiding this comment.
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)
👍 , merge at will |
<!-- This change is generated by MagicModules. --> /cc @chrisst
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! |
issue #182
cc/ @danawillow