Skip to content

ichundu/terraform-google-compute-instance-public

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

terraform-google-compute-instance-public

Create public virtual machines on Google Cloud. The instance has an external IP address associated. Published in the Terraform registry.

Usage example:

Create VMs with public IP addresses and DNS A record alias. Machine type can be changed without destroying the boot disk.

  1. Create a new directory for this terraform configuration
  2. Create a main.tf, for example:
# Configure the Google Cloud provider
provider "google" {
  credentials = "${file("king-of-my-google-cloud-castle.json")}"
  project     = "smashing-dash-1992"
}

module "vm1" {
  source          = "github.com/ichundu/terraform-gce-instance-public"
  amount          = 1
  region          = "europe-west4"
  zone            = "europe-west4-c"
  # hostname format: name_prefix-amount
  name_prefix     = "vm"
  machine_type    = "n1-standard-2"
  disk_type       = "pd-ssd"
  disk_size       = "15"
  disk_image      = "centos-cloud/centos-7"

  dns_record_name = "tower-dev"

  user_data       = "firestone-lab"
  username        = "eimert"
  public_key_path = "~/.ssh/id_rsa.pub"
}

# module "gc2" {}
  1. terraform init
  2. terraform plan Boom! Credentials file missing.
  3. Add your google cloud credentials in a .json file. Getting started guide

Keep the Google Cloud credentials in a safe place. Don't push them to Git.

  1. Adapt the Terraform variables in main.tf to match your Google cloud project name, and VM requirements. All optional parameters can be found in variables.tf.
  2. Let terraform fire up the VM's:
terraform apply
  1. Wait a few minutes seconds.
  2. Connect using SSH (private key auth): ssh -i <private key> <username>@<ip from output>. Or: ssh eimert@ansible-dev.cloud.eimertvink.nl.
  3. Break down the resources:
terraform destroy

machine_type

Overview of choices for variable machine_type.

f1-micro
g1-small

n1-standard-1
n1-standard-2
n1-standard-4
n1-standard-8

n1-highmem-2
n1-highmem-4
n1-highmem-8

n1-highcpu-2
n1-highcpu-4
n1-highcpu-8

Values are derived from Google cloud console REST API call examples. Click for CPU and memory details.

About

Provision gce instance with external IP address associated

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages