-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.tf
78 lines (63 loc) · 1.93 KB
/
main.tf
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
provider "google" {
credentials = "${file("~/.gce/gce-key.json")}"
project = "${var.project}"
region = "${var.region}"
version = "~> 1.12"
}
provider "random" {
version = "~> 1.3"
}
provider "template" {
version = "~> 1.0"
}
resource "random_id" "instance-prefix" {
byte_length = 6
keepers = {
instance_basename = "test"
}
}
data "google_compute_zones" "available" {}
resource "google_compute_address" "test-address" {
count = "${var.create_static_ip == "true" ? 1 : 0}"
name = "${random_id.instance-prefix.keepers.instance_basename}-${random_id.instance-prefix.hex}"
}
data "template_file" "metadata_startup_script" {
template = "${file("${path.module}/files/bootstrap.sh")}"
vars {
jfrog_cli_version = "${var.jfrog_cli_version}"
tf_download_script = "${data.template_file.download_terraform_script.rendered}"
}
}
data "template_file" "download_terraform_script" {
template = "${file("${path.module}/files/download_terraform.sh")}"
vars {
tf_version = "${var.tf_version}"
}
}
resource "google_compute_instance" "test" {
name = "${random_id.instance-prefix.keepers.instance_basename}-${random_id.instance-prefix.hex}"
machine_type = "${var.gce_type}"
zone = "${var.gce_zone}"
metadata {
startup-script = "${data.template_file.metadata_startup_script.rendered}"
}
labels = {
environment = "test"
}
boot_disk {
initialize_params {
image = "ubuntu-os-cloud/ubuntu-1804-lts"
size = 10
type = "pd-standard"
}
}
network_interface {
subnetwork = "${var.gce_subnetwork}"
access_config {
nat_ip = "${var.create_static_ip == false ? "" : "${join("", google_compute_address.test-address.*.address)}" }"
}
}
service_account {
scopes = ["userinfo-email", "compute-ro", "storage-ro"]
}
}