Using third-party plugins

Regardless to how convenient it is to connect Terraform with other external tools, such as configuration management systems, one would always prefer a built-in, native solution. An example is, as discussed previously, the Chef provisioner: while it's possible to do exactly the same with remote-exec, it's much faster to use special provisioner written just for this purpose. Unfortunately, while the list of supported providers is long, some of the technologies or services you need will be missing.

Luckily, Terraform has a plugin-based architecture, and it's trivial to extend it with custom providers and provisioners. Plugins are written in the Go programming language, and if you want to write your own, you need to have at least basic knowledge of it.

There are plugins available on GitHub that you could use. Ideally, developers should contribute these providers and provisioners to the Terraform core. Sometimes, though, it's not possible: it takes time to create and test a fully functional provider or provisioner, and sometimes, these third-party plugins while being ready to use are not yet accepted by Terraform core team.

It should not stop you from using them, though. You just have to be careful and keep in mind that they are more likely to have bugs than providers that are already part of Terraform.

If you have been following the latest trends in the operations world, then you might have heard about Kubernetes. In essence, it's an orchestration tool for containers, which gives you automated deployment, scaling, and management of containers, regardless of which containers tool you use, be it Docker, rkt, or something else. Kubernetes has many components and entities to manage, such as pods (groups of containers) and services. It's a perfect candidate to be managed by Terraform. And because it's such a complex, big provider it takes a while to get it right. As a result, at the moment it is still not the part of Terraform, but you can still use it as a plugin.

Note

Terraform-provider-kubernetes source code is stored at GitHub: https://github.com/maxmanuylov/terraform-provider-kubernetes. To get latest version running, you would have to compile it yourself, installing Go beforehand. There are already compiled and ready-to-use releases, though, also available at GitHub: https://github.com/maxmanuylov/terraform-provider-kubernetes/releases.

In order to install a plugin, you first need to download it and make it available as part of your PATH environment variable:

$> wget https://github.com/maxmanuylov/terraform-provider-kubernetes
/releases/download/v1.0-beta.3/terraform-provider-kubernetes-v1.0-beta.3-linux.tar.gz
$> tar -xzf terraform-provider-kubernetes-v1.0-beta.3-linux.tar.gz

Then, you need to activate it by adding it to the ~/.terraformrc file, as follows:

providers { 
    kubernetes = "/path/to/terraform-provider-kubernetes" 
} 

In this case, kubernetes is a prefix for all resources. If you want to have some fun, you can name it borg and then all resources will have to prefixed with borg instead of kubernetes. But then, it's rather confusing for your team.

Note

Borg is the name of the internal Google orchestration system. Kubernetes design is based on Borg and is an improved version of it.

That's everything there is to do to make plugin available. You can use all Kubernetes resources inside your template now, as follows:

resource "kubernetes_resource" "mypod" { 
  cluster = "${kubernetes_cluster.main.cluster}" 
  collection = "pods" 
  name = "mypod" 
  content = "${file("mypod.yaml")}" 
} 

Another useful third-party plugin is terraform-provisioner-ansible that, you guessed it right, adds Ansible support to Terraform. The source code of this plugin is available on GitHub: https://github.com/jonmorehouse/terraform-provisioner-ansible. It appears to be nonfunctional with the latest Terraform releases, though. As with every other third-party plugin, you should use it at your own risk.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.141.6