---
title: Simple GCE setup with Terraform
description: We found out the easiest and quickest possible way to bring a virtual machine in the Google Compute Engine (GCE) using Terraform.
image: http://cdn2.hubspot.net/hubfs/2668666/All-InOne-2016/Image/bg-img.jpg
---

Check out our **[Cloud Native Services](https://www.container-solutions.com/services) **and** **book a call with one of our experts today! 

[![Container Solutions](https://blog.container-solutions.com/hubfs/CS_blog/logo-main.svg "Container Solutions")](http://container-solutions.com)

- share:
- [**](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fblog.container-solutions.com%2Fsimple-gce-setup-terraform)
- [**](https://www.twitter.com/share?url=https%3A%2F%2Fblog.container-solutions.com%2Fsimple-gce-setup-terraform)
- [**](http://www.linkedin.com/shareArticle?mini=true&url=https://blog.container-solutions.com/simple-gce-setup-terraform)
- [**](https://blog.container-solutions.com/simple-gce-setup-terraform#)

[![](http://cdn2.hubspot.net/hubfs/2668666/All-InOne-2016/Image/bg-img.jpg) ](https://blog.container-solutions.com/simple-gce-setup-terraform)

# Simple GCE setup with Terraform

[Carlos Leon](https://blog.container-solutions.com/author/carlos-leon)

 July 28, 2016

 3 minutes Read

# Simple GCE setup with Terraform

Here you will find a Terraform configuration file that will create a single virtual machine in the Google Cloud Engine (GCE) platform using Terraform.

I wanted to run a straightforward experiment in a virtual machine in Google Cloud and I couldn't find a Terraform snippet to get me up & running. The truth is that I had never created a GCE environment myself, so I was not familiar whatsoever with the concepts or how everything was glued together. After some head banging against [my keyboard](https://i.imgur.com/mpHgjYL.jpg) and experimenting with different approaches for the Terraform config file, this is what finally got me in the game:

```

variable "region" {
  default = "europe-west1-d" // We're going to need it in several places in this config
}
 
provider "google" {
  credentials = "${file("account.json")}"
  project     = "my-project"
  region      = "${var.region}"
}
 
resource "google_compute_instance" "test" {
  count        = 1 // Adjust as desired
  name         = "test${count.index + 1}" // yields "test1", "test2", etc. It's also the machine's name and hostname
  machine_type = "f1-micro" // smallest (CPU & RAM) available instance
  zone         = "${var.region}" // yields "europe-west1-d" as setup previously. Places your VM in Europe
 
  disk {
    image = "debian-7-wheezy-v20160301" // the operative system (and Linux flavour) that your machine will run
  }
 
  network_interface {
    network = "default"
    access_config {
      // Ephemeral IP - leaving this block empty will generate a new external IP and assign it to the machine
    }
  }
}
	
```

For this to work you're going to need:

1. **Service Account Key** file.  
    This contains your authentication required for Terraform to talk to the Google API.  
    You can get it under *Google Cloud Platform* -> *API Manager* -> *Credentials* -> *Create Credentials* -> *Service account key*.  
    For the *Key type* field chose **JSON**. Put the downloaded file right were your Terraform config file is and name it `account.json`.
2. Make sure that you have an SSH key setup for your project: *Compute Engine* -> *Metadata* -> *SSH Keys*
3. Chose a valid machine image and machine type for your VM. Find an up-to-date list of available images [here](https://cloud.google.com/compute/docs/images) and available types [here](https://cloud.google.com/compute/docs/machine-types).  
   **<rant>***This is where I have seen Terraform (or its providers) falling short: they expect you to know what are the valid types for their base image names (already had this issue with not only GCE but also with DigitalOcean, Packet, Triton) so you have to basically create developer accounts all over to get an API token, read through the documentation, get familiar with the concepts, curl all over until you find that name that could be easily listed somewhere else ~_~* **</rant>**
4. `terraform plan` to make sure everything is looking good
5. `terraform apply`
6. Find the IP of the box with `terraform show | grep assigned_nat_ip`

You're good to go!

[### The Release and New Features of Mesos 1.0.0

](https://blog.container-solutions.com/release-new-features-mesos-1-0-0)

[![prev-arrow](https://cdn2.hubspot.net/hubfs/3842749/Wow%202019/Images/left-arrow.png) Previous article](https://blog.container-solutions.com/release-new-features-mesos-1-0-0)

[ Next article ![next-arrow](https://cdn2.hubspot.net/hubfs/3842749/Wow%202019/Images/right-arrow.png) ](https://blog.container-solutions.com/minimesos-0-10-1-support-for-mesos-1-0-0-and-docker-1-12)

[

### minimesos 0.10.1 - Support for Mesos 1.0.0 and Docker 1.12

](https://blog.container-solutions.com/minimesos-0-10-1-support-for-mesos-1-0-0-and-docker-1-12)

Comments

Leave your Comment

![cs-logo-white](https://blog.container-solutions.com/hs-fs/hubfs/cs-logo-white.png?width=150&height=61&name=cs-logo-white.png "cs-logo-white")

#### **Talk to sales**

[info@container-solutions.com](mailto:info@container-Solutions.com)

#### Stay In Touch

- [**](https://www.linkedin.com/company/container-solutions/)
- [**](https://twitter.com/containersoluti)

© 2024 Container Solutions