-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Enable 'zone' to be specified at the provider level instead of per-resource. #816
Enable 'zone' to be specified at the provider level instead of per-resource. #816
Conversation
@rosbo This seems to have gone right, but as mentioned I'm not in a good state to run all the acctests. I'm running the ones I can now and I'll report back with any failures I suspect are related. |
Aha, there was a problem with the provider config. Hang on, I'll fix it and report back. edit: Well, sort of a problem. More like a "choice I made without thinking about it". :) I don't think you should have to specify zone in the tests, so I want to change it from required to optional. Tests are running now and seem to be passing save for the quota issues I mentioned in #815. I'll push that commit once these tests are done. |
// given, an error is returned. | ||
// given, checks for "zone" in either the given resource data or provider, | ||
// and extracts region from zone. If "zone" is not provided, returns an | ||
// error. | ||
func getRegion(d *schema.ResourceData, config *Config) (string, error) { |
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.
Probably worth it to add a unit test for getRegion and getZone.
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'm sure you're right - I'll get on that. :)
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.
Done.
FYI: The CI is server is running all the acceptance tests on this branch. |
google/resource_compute_disk.go
Outdated
if err != nil { | ||
return handleNotFoundError(err, d, fmt.Sprintf("Disk %q", d.Get("name").(string))) | ||
} | ||
} else if err != nil { |
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 should remove this else if block. If no zone are specified, it is fine and the logic in the else block tries to guess the zone.
This comment also applies to group manager and autoscaler.
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've done this as well, sorry.
google/resource_compute_disk.go
Outdated
@@ -279,12 +287,14 @@ func resourceComputeDiskRead(d *schema.ResourceData, meta interface{}) error { | |||
} | |||
|
|||
var disk *compute.Disk | |||
if zone, ok := d.GetOk("zone"); ok { | |||
if zone, err := getZone(d, config); zone != "" && err == nil { |
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.
If the zone is empty, the err
returned by getZone
should not be nil and therefor, the zone != nil
is redundant
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.
Ah, shoot, I thought that was idiomatic because of the way that .Get() works in Schema. :) I'll fix it.
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.
Fixed that, also. Thanks!
- Fetch Zone attribute any place where it *was* being fetched from the schema by combination schema / provider-level attribute. -Allow region to be unspecified if zone is specified.
Individual resources will fail if they can't find a zone.
79f473c
to
cd2a9b9
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.
The acceptance tests passed
Signed-off-by: Modular Magician <[email protected]>
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! |
Fixes #772. Tested:
and confirmed I got all the places I needed to replace:
(both of which are correct)