Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Experimenting Locally with Terraform

Tags:

terraform

We are looking into Terraform as a way of managing our infrastructure and it looks very interesting.

However, currently our corporate proxy/firewall is causing terraform apply to fail due to security restrictions.

While we wait for these network issues to be resolved, is there any way that I can experiment with Terraform locally without needing to connect to Azure or AWS? Perhaps with VirtualBox?

like image 843
David Brower Avatar asked Aug 29 '16 16:08

David Brower


People also ask

Can Terraform be used locally?

Terraform supports a bunch of providers, but the vast majority of them are public cloud based. However, you could set up a local VMware vSphere cluster and use the vSphere provider to interact with that to get you going. There's also a provider for OpenStack if you want to set up an OpenStack cluster.

Can you use Terraform for on premise?

Terraform can be used for on-premises infrastructure. Whilst Terraform is known for being cloud-agnostic and supporting public clouds such as AWS, Azure, GCP, it can also be used for on-prem infrastructure including VMware vSphere and OpenStack.

What is local provider in Terraform?

The Local provider is used to manage local resources, such as files. Use the navigation to the left to read about the available resources. Note. Terraform primarily deals with remote resources which are able to outlive a single Terraform run, and so local resources can sometimes violate its assumptions.

Can Terraform be used with virtualbox?

The Virtualbox provider for Terraform allows to manage local virtualbox machines using Terraform. The main purpose of this provider is to make you familiar with Terraform and provisioning machines, without leaving your machine, therefore saving you costs.


2 Answers

Terraform supports a bunch of providers, but the vast majority of them are public cloud based.

However, you could set up a local VMware vSphere cluster and use the vSphere provider to interact with that to get you going. There's also a provider for OpenStack if you want to set up an OpenStack cluster.

Alternatively you could try using something like HPE's Eucalyptus which provides API compatibility with AWS, but on-premises.

That said, unless you already have a datacenter running VMware, all of those options are pretty awful and will take a lot of effort to get setup so you may be best waiting for your firewall to be opened up instead.

There isn't unfortunately a nice frictionless first party implementation of a VirtualBox provider but you could try this third-party VirtualBox provider.

like image 188
ydaetskcoR Avatar answered Sep 23 '22 18:09

ydaetskcoR


One way to get used to a few things that Terraform is great at (dependency management, data driven configuration, resource lifecycle, etc.) is to use the null_resource provisioner on your workstation. This assumes that you have enough control over your workstation to get Terraform on it (this is pretty difficult at a lot of places that have high security needs).

By just using Terraform's null_resource provisioner you can get used to a lot of the things you'll use with a cloud. If you have the ability to install Docker on your workstation, you can go really far to acting like a cloud because Docker supports swarm mode on a workstation.

For example,

resource "null_resource" "docker_swarm" {      provisioner "local-exec" {       command = "docker swarm init"     }      provisioner "local-exec" {       command = <<EOF         docker swarm leave --force          # Careful here. This assumes you want a clean Docker slate,         # remove all Docker volumes from your machine.         docker volume rm -f $(docker volume ls -q)  EOF       when = "destroy"     } }  resource "null_resource" "start_stack" {      provisioner "local-exec" {       command = "docker stack deploy -c ./docker-stack.yml demostack"     }      provisioner "local-exec" {       command = "docker stack rm demostack"       when = "destroy"     }      depends_on = ["null_resource.docker_swarm"] } 

In that simple example above you see how you'd manage lifecycle. And here's the cool part: that's exactly how you'd start up a supported Docker Swarm in AWS, Azure, etc., though it'll be a bit more complicated and take a bit longer.

If you don't have Docker, I'm sure you can think of some other create/destroy lifecycle you may have on your workstation.

Good luck! IMHO Terraform is one of the most profound things to come across our keyboards (Docker ranks there too).

like image 42
Flacito Avatar answered Sep 23 '22 18:09

Flacito