Last active
June 13, 2020 14:38
-
-
Save samsulmaarif/20633752c026c832472087e56b3607e2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
resource "google_compute_firewall" "vpc_firewall" { | |
name = "test-firewall" | |
network = google_compute_network.vpc_network.name | |
allow { | |
protocol = "icmp" | |
} | |
allow { | |
protocol = "tcp" | |
ports = ["22", "80", "8080", "1000-2000"] | |
} | |
source_ranges = ["0.0.0.0/0"] | |
target_tags = ["klim-web"] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
provider "google" { | |
version = "3.5.0" | |
credentials = file("../nacita-dev-terraform-demo.json") | |
project = var.project | |
region = var.region | |
zone = var.zone | |
} | |
# New resource for the storage bucket our application will use. | |
resource "google_storage_bucket" "example_bucket" { | |
name = "klim-terraform-demo" | |
location = "US" | |
website { | |
main_page_suffix = "index.html" | |
not_found_page = "404.html" | |
} | |
} | |
resource "google_compute_instance" "vm_instance" { | |
depends_on = [google_storage_bucket.example_bucket] | |
name = "terraform-instance" | |
machine_type = "f1-micro" | |
tags = ["klim-web"] | |
boot_disk { | |
initialize_params { | |
//image = "debian-cloud/debian-9" | |
image = "cos-cloud/cos-stable" | |
} | |
} | |
network_interface { | |
network = google_compute_network.vpc_network.name | |
subnetwork = google_compute_subnetwork.vpc_subnetwork.name | |
access_config { | |
nat_ip = google_compute_address.vm_ip_static.address | |
} | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
resource "google_compute_network" "vpc_network" { | |
name = "terraform-network" | |
auto_create_subnetworks = false | |
} | |
resource "google_compute_subnetwork" "vpc_subnetwork" { | |
ip_cidr_range = "10.4.4.0/24" | |
name = "terraform-subnet" | |
network = google_compute_network.vpc_network.name | |
private_ip_google_access = "false" | |
} | |
resource "google_compute_address" "vm_ip_static" { | |
name = "ip-static-terraform" | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- install terraform | |
wget https://releases.hashicorp.com/terraform/0.12.26/terraform_0.12.26_linux_amd64.zip | |
unzip terraform_0.12.26_linux_amd64.zip | |
- credential | |
export GOOGLE_APPLICATION_CREDENTIALS= | |
- file main.tf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
project = "nacita-dev" | |
region = "asia-souteast2" | |
zone = "asia-southeast2-b" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
variable "project" { | |
type = string | |
} | |
variable "region" { | |
default = "us-central1" | |
} | |
variable "zone" { | |
default = "us-central1-b" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment