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

provider/google: initial commit for node pool resource #11802

Merged
merged 5 commits into from
Mar 6, 2017

Conversation

danawillow
Copy link
Contributor

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.

Copy link
Contributor

@paddycarver paddycarver left a 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
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 if err is not nil, resp may be nil, in which case this will panic.

Copy link
Contributor Author

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,
Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Contributor

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,
},
Copy link
Contributor

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.

Copy link
Contributor Author

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
}
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 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

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.

Copy link
Contributor Author

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
Copy link
Contributor

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.

Copy link
Contributor Author

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)
Copy link
Contributor

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.

Copy link
Contributor

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)
Copy link
Contributor

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.

Copy link
Contributor

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.

@danawillow danawillow force-pushed the gke-nodepool branch 2 times, most recently from 2add5ae to bdcac4f Compare February 22, 2017 23:17
Copy link
Contributor

@paddycarver paddycarver left a 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,
Copy link
Contributor

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
}
Copy link
Contributor

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)
Copy link
Contributor

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 {
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 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.

Copy link
Contributor Author

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.

Copy link
Member

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

Copy link
Member

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.

Copy link
Contributor Author

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)
Copy link
Contributor

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.

@danawillow
Copy link
Contributor Author

All right @paddyforan, I think all comments have been resolved at this point. Over to you.

Copy link
Contributor

@paddycarver paddycarver left a 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),
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

@paddycarver paddycarver left a 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.

@danawillow danawillow merged commit 3220446 into hashicorp:master Mar 6, 2017
danawillow added a commit that referenced this pull request Mar 6, 2017
provider/google: initial commit for node pool resource
@danawillow danawillow deleted the gke-nodepool branch March 6, 2017 23:12
catsby added a commit that referenced this pull request Mar 7, 2017
* '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
yanndegat pushed a commit to yanndegat/terraform that referenced this pull request Mar 13, 2017
provider/google: initial commit for node pool resource
@ragdaj
Copy link

ragdaj commented May 24, 2017

Is it possible to set machine type for node pool ?

@ghost
Copy link

ghost commented Apr 12, 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 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.

@ghost ghost locked and limited conversation to collaborators Apr 12, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants