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

Add rancher_host resource type #11545

Merged
merged 3 commits into from
Mar 14, 2017
Merged

Add rancher_host resource type #11545

merged 3 commits into from
Mar 14, 2017

Conversation

raphink
Copy link
Contributor

@raphink raphink commented Jan 31, 2017

Add rancher_host resource type

This adds a rancher_host resource type.
For now, the goal is to detect if the host already exists,
so that it can be purged cleanly when the host is deprovisioned.

The typical use is to create both an instance (e.g. aws_instance)
and a rancher_host resources with the same hostname. The rancher_host
resource will detect when the agent has registered itself.

When removing the host, both the instance and the rancher_host
resources can be removed, ensuring the host is purged from Rancher.

In future versions, this could support creating hosts as well.

@raphink
Copy link
Contributor Author

raphink commented Feb 7, 2017

/cc @johnrengelman any take on this?

@johnrengelman
Copy link
Contributor

Hmm, I see what you're trying to do here, but personally I wouldn't use TF to manage these things because I think the experience would be frustrating with TF not creating the host. You're effectively using the Create function to do an Import which seems like it would lead to potential issues.

@johnrengelman
Copy link
Contributor

I think the if we were to implement this resource, then the only appropriate way to do it would be to call the host provisioning APIs in Rancher and manage the host that way.

@johnrengelman
Copy link
Contributor

I think this is going to lead us into the conversation about supporting the v2-beta api though because hosts creation is quite a bit different in the 2 api version. Which I'd be interested in @stack72's opinion on how that should be supported in TF.

  1. Create a new rancher-v2 provider
  2. Create resources that specify the version - i.e. rancher_stack_v2.foo vs rancher_stack.foo
  3. Provide a configuration option on which API version to use and then only allow some resources to be created with the v2 API.
  4. Try to transparently detect the API version under the covers - i.e. try the v2-beta api and use it if it works.

@cpoole
Copy link

cpoole commented Feb 8, 2017

@johnrengelman I vote for for option 3.

The only issue I see there is if you change the api version from v1 to v2 upgrade logic would need to be created (I assume that would require logic for destroying a v1 host and creating a new v2 host).

@johnrengelman
Copy link
Contributor

@cpoole I don't believe that's the case in Rancher. A Host created in Rancher is available under either the v1 or the v2-beta api. It's just changing the API to do those things (the JSON definition and such).

@raphink
Copy link
Contributor Author

raphink commented Feb 8, 2017

Pretty sure of that, too (re v2). By the way, while the v2 API is marked beta, it is finalized and will not move (confirmed from Rancher employee).

@johnrengelman I do want to manage hosts in Terraform though, so that I can autoscale some environments cleanly, which is not possible if I can't remove hosts from Rancher when I shut down nodes. And using rancher hosts to create them is not a good option imo, as it will dynamically create security groups and such, which won't be purgeable in Terraform, so I'd rather control how things are done cleanly, using Terraform.

@johnrengelman
Copy link
Contributor

@raphink that's How I manage hosts as well...Use TF to create a Launch Configuration and ASG so when the instance launches it joins in.

In this case, TF would never come into play with the hosts and I image an out-of-band process to reap hosts would be a better solution than using TF to do (just IMO). I've been looking at this - https://github.com/ampedandwired/rancher-reaper but haven't tried it out yet.

@cpoole
Copy link

cpoole commented Feb 9, 2017

I agree with @johnrengelman. We have a lambda function that does this here at Daqri. I'll try and opensource it by end of next week.

@mcanevet
Copy link
Contributor

mcanevet commented Mar 7, 2017

A rancher_host resource would not only allow to purge it from the Rancher API on instance removal, but also allow to manage host labels from TF which would be cool.
So I think this resource is a good idea.

@stack72
Copy link
Contributor

stack72 commented Mar 8, 2017

@raphink / @johnrengelman

Is this ready to merge? If so, please can it be rebased?

@raphink
Copy link
Contributor Author

raphink commented Mar 13, 2017

@stack72 I'll have a look to see what's missing (and rebase)

@raphink
Copy link
Contributor Author

raphink commented Mar 13, 2017

Just fixed and rebased.

@raphink
Copy link
Contributor Author

raphink commented Mar 13, 2017

Example usage:

resource rancher_host "wrk8" {
  name           = "wrk8"
  description    = "my fabulous machine"
  environment_id = "1a113948"
  hostname       = "wrk8.example.com"
}

@stack72
Copy link
Contributor

stack72 commented Mar 13, 2017

@raphink still failing i'm afraid ;)

@raphink
Copy link
Contributor Author

raphink commented Mar 13, 2017

Ok I'll need to check. I'll also add support for host labels.

This adds a rancher_host resource type.
For now, the goal is to detect if the host already exists,
so that it can be purged cleanly when the host is deprovisioned.

The typical use is to create both an instance (e.g. aws_instance)
and a rancher_host resources with the same hostname. The rancher_host
resource will detect when the agent has registered itself.

When removing the host, both the instance and the rancher_host
resources can be removed, ensuring the host is purged from Rancher.

In future versions, this could support creating hosts as well.
@raphink
Copy link
Contributor Author

raphink commented Mar 14, 2017

@stack72 I added host labels support. I've kept it (so far) as two patches, because there's a little hack linked to rancher/rancher#8165. Ideally, I'm hoping Rancher Labs will store their computed labels in another API so we don't need to filter these ro_labels, but in the meanwhile I see no other way of managing them idempotently.

Also, build is now 💚

@stack72 stack72 merged commit 1917646 into hashicorp:master Mar 14, 2017
@stack72
Copy link
Contributor

stack72 commented Mar 14, 2017

Thanks for all the work here @raphink :)

@raphink
Copy link
Contributor Author

raphink commented Mar 14, 2017

Thanks for merging!

stack72 pushed a commit that referenced this pull request Mar 14, 2017
* Add rancher_host resource type

This adds a rancher_host resource type.
For now, the goal is to detect if the host already exists,
so that it can be purged cleanly when the host is deprovisioned.

The typical use is to create both an instance (e.g. aws_instance)
and a rancher_host resources with the same hostname. The rancher_host
resource will detect when the agent has registered itself.

When removing the host, both the instance and the rancher_host
resources can be removed, ensuring the host is purged from Rancher.

In future versions, this could support creating hosts as well.

* Use ro_labels to avoid removing internal Rancher labels

As reported in rancher/rancher#8165

* Do not ForceNew on environment_id
@ghost
Copy link

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

5 participants