Skip to content

Commit 1ca1422

Browse files
committed
Basic GCP example
1 parent 96d0046 commit 1ca1422

File tree

3 files changed

+56
-6
lines changed

3 files changed

+56
-6
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# First Tutorial
2+
3+
## First step
4+
5+
Hello World
6+
7+
### Part 1
8+
9+
Part One Instructions.
10+
11+
```
12+
terraform init
13+
```
14+
15+
```
16+
terraform plan
17+
```
18+
19+
```
20+
terraform apply
21+
```
22+
23+
### Part 2
24+
25+
Part Two Instructions.
26+
27+
## Conclusion
28+
29+
Done!

getting-started/gcp/main.tf

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
provider "google" {
2-
# project = "{{YOUR GCP PROJECT}}"
2+
project = "my-google-cloud-project"
33
region = "us-central1"
44
zone = "us-central1-c"
55
}
@@ -8,7 +8,7 @@ resource "google_compute_instance" "vm_instance" {
88
name = "terraform-instance"
99
machine_type = "f1-micro"
1010

11-
labels {
11+
labels = {
1212
billing_department = "education"
1313
}
1414

@@ -20,17 +20,34 @@ resource "google_compute_instance" "vm_instance" {
2020

2121
network_interface {
2222
# A default network is created for all GCP projects
23-
network = "${google_compute_network.vpc_network.self_link}"
24-
access_config = {
23+
network = google_compute_network.vpc_network.self_link
24+
access_config {
2525
}
2626
}
27+
28+
metadata_startup_script = "echo 'Hello Terraform on GCP!' > index.html; python -m SimpleHTTPServer 9000 &"
2729
}
2830

2931
resource "google_compute_network" "vpc_network" {
3032
name = "terraform-network"
3133
auto_create_subnetworks = "true"
3234
}
3335

34-
output "network_ip" {
35-
value = "${google_compute_instance.vm_instance.network_interface.0.network_ip}"
36+
resource "google_compute_firewall" "default" {
37+
name = "terraform-firewall"
38+
network = google_compute_network.vpc_network.self_link
39+
40+
allow {
41+
protocol = "tcp"
42+
ports = ["9000"]
43+
}
44+
}
45+
46+
output "private_ip" {
47+
value = google_compute_instance.vm_instance.network_interface[0].network_ip
48+
}
49+
50+
output "website_url" {
51+
value = "http://${google_compute_instance.vm_instance.network_interface[0].access_config[0].nat_ip}:9000"
3652
}
53+

getting-started/gcp/versions.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
terraform {
3+
required_version = ">= 0.12"
4+
}

0 commit comments

Comments
 (0)