๐Ÿ“ฆ veggiemonk / basic-terraform-example

๐Ÿ“„ main.tf ยท 51 lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51provider "google" {
	region      = "europe-west1"
	# credentials = "${file("~/path/to/creds.json")}"
}

resource "google_storage_bucket" "mybucket" {
    name          = "${var.bucket_name}"
    project       = "${var.project_id}"
    location      = "EU"
}

resource "google_service_account" "bucket-sa" {
  account_id   = "bucket-vm"
  display_name = "VM service account"
  project      = "${var.project_id}"
}

resource "google_storage_bucket_iam_member" "myvm" {
    count  = "${length(var.storage_bucket_roles)}"
    role   = "${element(var.storage_bucket_roles, count.index)}"
    bucket = "${google_storage_bucket.mybucket.name}"
    member = "serviceAccount:${google_service_account.bucket-sa.email}"
}


resource "google_compute_instance" "vm" {
	project      = "${var.project_id}"
	name         = "${var.vm_name}"
	machine_type = "f1-micro"
	zone         = "europe-west1-b"
  
	boot_disk {
	  initialize_params {
		image = "debian-cloud/debian-9"
	  }
	}
  
	network_interface {
	  network = "default"
  
	  access_config {} # Ephemeral IP
	}
  
	metadata_startup_script = "echo hi > /terraform_workshop.txt"
  
	service_account {
        email = "${google_service_account.bucket-sa.email}"
	    scopes = ["https://www.googleapis.com/auth/cloud-platform"]
	}

}