Skip to content

Instantly share code, notes, and snippets.

@ibrezm1
Created September 29, 2022 05:23
Show Gist options
  • Save ibrezm1/e0818c0d8e0d2f0cbe9292dcc4c386c5 to your computer and use it in GitHub Desktop.
Save ibrezm1/e0818c0d8e0d2f0cbe9292dcc4c386c5 to your computer and use it in GitHub Desktop.
Teraform setup and learn
# install terraform steps and interactive web browser
# https://learn.hashicorp.com/tutorials/terraform/install-cli
provider "google" {
#version = "3.5.0"
# credentials = file("/downloads/compute-instance.json")
# OR
# use gcloud auth application-default login/revoke
project = "zeta-yen-319702"
region = "us-central1"
zone = "us-central1-c"
}
resource "google_compute_network" "vpc_network" {
name = "terraform-network"
}
resource "google_compute_instance" "vm_instance" {
name = "terraform-instance2"
machine_type = "f1-micro"
zone = "us-central1-c"
boot_disk {
initialize_params {
image = "centos-cloud/centos-7"
}
}
network_interface {
network = google_compute_network.vpc_network.name
# you can just omit the access_config section in network_interface block
# https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/compute_instance#access_config
access_config {
}
}
}
output "ip" {
value = google_compute_instance.vm_instance.network_interface.0.access_config.0.nat_ip
}
# How to import existing
# https://www.terraform.io/language/state/import
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment