-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
provider/google: initial commit for node pool resource #11802
Conversation
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.
Thanks for working on this, @danawillow! It looks great, just a couple minor things to look at.
w.Project, w.Zone, w.Op.Name).Do() | ||
log.Printf("[DEBUG] Progress of operation %q: %q", w.Op.Name, resp.Status) | ||
|
||
return resp, resp.Status, err |
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 if err
is not nil
, resp
may be nil, in which case this will panic.
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
return &schema.Resource{ | ||
Create: resourceContainerNodePoolCreate, | ||
Read: resourceContainerNodePoolRead, | ||
Delete: resourceContainerNodePoolDelete, |
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.
This isn't a requirement, but I'd love to see an Exists function here.
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. Can you help me now figure out whether there's anything that can be taken out of the other functions now that the Exists one is there?
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.
Absolutely, I'll mark them up if I find them.
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
}, |
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'd be great if we could a name_prefix or something similar, so we can have random strings attached to the end and not have conflicts when using this with create_before_destroy.
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.
project, err := getProject(d, config) | ||
if err != nil { | ||
return err | ||
} |
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 we want to use a project_id inline here, so we can take advantage of creating projects in Terraform and using them as the host for node pools.
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.
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.
Hm. I don't have a preference either way, and honestly, can see arguments for both:
- project is probably a bit more natural and consistent (e.g., we use disk, instance, not disk_id, instance_id)
- project is going to sound weird in google_project
- project_id leaves us more wiggle room in the future if we need to add/change something and want to avoid BC changes.
Looking into the actual implementation of getProject (I thought it used environment variables...? Maybe I imagined that) I actually don't see anything wrong with it. If we add project
to the schema, everything should be fine, and getProject actually seems like the right way to go. Sorry for the misdirection.
In the future we should standardise on project
, though I think it best to wait to update google_project
as 1) getProject doesn't make sense for that resource and 2) I'm hesitant to deprecate project_id
only like 3 releases after introducing 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.
Seems reasonable. I added a project field.
op, err := config.clientContainer.Projects.Zones.Clusters.NodePools.Create(project, zone, cluster, req).Do() | ||
|
||
if err != nil { | ||
return err |
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 we could add some context to this error, that would be awesome. Something like "Error creating node pool:" or something.
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
func resourceContainerNodePoolRead(d *schema.ResourceData, meta interface{}) error { | ||
config := meta.(*Config) | ||
|
||
project, err := getProject(d, config) |
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.
Same here, I think we want project_id in the config, instead.
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.
Nope, I was wrong, this is still just adding a project attribute to the schema.
func resourceContainerNodePoolDelete(d *schema.ResourceData, meta interface{}) error { | ||
config := meta.(*Config) | ||
|
||
project, err := getProject(d, config) |
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.
This should probably be read from the Config.
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.
Still wrong, just need a project property on the resource.
2add5ae
to
bdcac4f
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.
Big change is just adding a project property to the schema, so getProject will work as intended and we can specify projects besides the authenticating one.
I also need to follow up on Exists and make sure I'm telling you the right thing about what is needed/is not needed.
return &schema.Resource{ | ||
Create: resourceContainerNodePoolCreate, | ||
Read: resourceContainerNodePoolRead, | ||
Delete: resourceContainerNodePoolDelete, |
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.
Absolutely, I'll mark them up if I find them.
project, err := getProject(d, config) | ||
if err != nil { | ||
return err | ||
} |
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.
Hm. I don't have a preference either way, and honestly, can see arguments for both:
- project is probably a bit more natural and consistent (e.g., we use disk, instance, not disk_id, instance_id)
- project is going to sound weird in google_project
- project_id leaves us more wiggle room in the future if we need to add/change something and want to avoid BC changes.
Looking into the actual implementation of getProject (I thought it used environment variables...? Maybe I imagined that) I actually don't see anything wrong with it. If we add project
to the schema, everything should be fine, and getProject actually seems like the right way to go. Sorry for the misdirection.
In the future we should standardise on project
, though I think it best to wait to update google_project
as 1) getProject doesn't make sense for that resource and 2) I'm hesitant to deprecate project_id
only like 3 releases after introducing it.
func resourceContainerNodePoolRead(d *schema.ResourceData, meta interface{}) error { | ||
config := meta.(*Config) | ||
|
||
project, err := getProject(d, config) |
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.
Nope, I was wrong, this is still just adding a project attribute to the schema.
nodePool, err := config.clientContainer.Projects.Zones.Clusters.NodePools.Get( | ||
project, zone, cluster, name).Do() | ||
if err != nil { | ||
if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 404 { |
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 this should no longer be necessary, as Exists should never let this code execute if the resource doesn't exist. But @radeksimko said something that made me doubt that, so I'm going to follow up with him before I start handing out wrong info.
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 that is the case, we (I think) still need somewhere to mark the id as empty. I could do it in Exists but the comments around the declaration of it say The *ResourceData passed to Exists should _not_ be modified.
which certainly is a deterrent for doing it there.
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.
Unless I'm terribly mistaken I don't think you need to run d.SetId("")
in Exists
in order to mark it as gone.
That's what happens automatically if Exists
returns false, see https://github.com/hashicorp/terraform/blob/master/helper/schema/resource.go#L237-L243
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.
That said the Exists
function will need some extra care because right now it's returning false
if it encounters any error (could be 503), so the conditional w/ 404 here should be moved down there and Exists
should always properly return genuine error as true, 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.
Makes sense, thanks @radeksimko!
func resourceContainerNodePoolDelete(d *schema.ResourceData, meta interface{}) error { | ||
config := meta.(*Config) | ||
|
||
project, err := getProject(d, config) |
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.
Still wrong, just need a project property on the resource.
bdcac4f
to
c92cc9c
Compare
All right @paddyforan, I think all comments have been resolved at this point. Over to you. |
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.
Partial review, noticed you pushed a new commit, so gonna leave this here so I can refresh.
"GOOGLE_PROJECT", | ||
"GCLOUD_PROJECT", | ||
"CLOUDSDK_CORE_PROJECT", | ||
}, 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.
I'd rather see this default to an empty string, honestly; getProject
would populate the provider-configured project, if I'm not mistaken.
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.
Huh, for some reason tests were failing when I had it this way before but I just tried again and they passed, so \shrug. Done.
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.
This looks great. 👍 Merge at will.
provider/google: initial commit for node pool resource
* 'master' of github.com:hashicorp/terraform: provider/datadog: Update to datadog_monitor still used d.GetOk (#12497) Check instance is running before trying to attach (#12459) Fix aws_dms_replication_task diff for json with whitespace. (#12380) add "name" to exported attributes (#12483) provider/aws: Adding an acceptance test to for ForceNew on ecs_task_definition volumes provider/aws: (#10587) Changing volumes in ECS task definition should force new revision. provider/aws: Change aws_spot_fleet_request tests to use the correct hash values in test cases Small doc updates (#12165) Improve description of consul_catalog_entry (#12162) provider/aws: Only send iops when creating io1 devices. Fix docs (#12392) provider/google: initial commit for node pool resource (#11802) Fix spurious user_data diffs Properly handle 'vpc_security_group_ids', drop phantom 'security_groups' Default 'ebs_optimized' and 'monitoring' to false
provider/google: initial commit for node pool resource
Is it possible to set machine type for node pool ? |
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 have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further. |
Purposely kept to just required fields for now to keep the PR small.
Will enable further development in this resource, such as is necessary for #8605.