Skip to content

Instantly share code, notes, and snippets.

@anhnguyen1618
Created September 23, 2020 11:22
Show Gist options
  • Save anhnguyen1618/907da2534a8dd34174d0ed963cbb6bad to your computer and use it in GitHub Desktop.
Save anhnguyen1618/907da2534a8dd34174d0ed963cbb6bad to your computer and use it in GitHub Desktop.
terraform {
required_providers {
google = {
source = "hashicorp/google"
}
}
}
variable "instance_name_input" {
type = string
}
provider "google" {
version = "3.5.0"
credentials = file("credentials.json")
project = "gothic-module-289816"
region = "us-central1"
zone = "us-central1-c"
}
resource "google_compute_network" "vpc_network" {
name = "terraform-network"
}
resource "google_compute_firewall" "ssh-rule" {
name = "demo-ssh"
network = google_compute_network.vpc_network.name
allow {
protocol = "tcp"
ports = ["22"]
}
source_ranges = ["0.0.0.0/0"]
}
resource "google_compute_instance" "vm_instance" {
name = var.instance_name_input
machine_type = "f1-micro"
tags = ["web", "dev"]
boot_disk {
initialize_params {
image = "ubuntu-1804-lts"
}
}
network_interface {
network = google_compute_network.vpc_network.name
access_config {
}
}
}
output "public_ip" {
value = "${google_compute_instance.vm_instance.network_interface.0.access_config.0.nat_ip}"
description = "The private IP address of the main server instance."
}
output "instance_name" {
value = var.instance_name_input
description = "Name of the instance"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment