Skip to content

Commit f94dc0c

Browse files
authored
Merge pull request #85 from ranyodh/gcp-cloud-provider-support
Add service account, access scopes and instance prefix tags to instances
2 parents 0cd835c + 1d6b5d5 commit f94dc0c

File tree

11 files changed

+85
-33
lines changed

11 files changed

+85
-33
lines changed

examples/terraform/gcp/main.tf

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,16 @@ module "common" {
4040
}
4141

4242
module "managers" {
43-
source = "./modules/manager"
44-
manager_count = var.manager_count
45-
gcp_region = var.gcp_region
46-
gcp_zone = local.zone
47-
cluster_name = var.cluster_name
48-
image_name = module.common.image_name
49-
vpc_name = module.vpc.vpc_name
50-
subnetwork_name = module.vpc.subnet_name
51-
ssh_key = module.common.ssh_key
43+
source = "./modules/manager"
44+
manager_count = var.manager_count
45+
gcp_region = var.gcp_region
46+
gcp_zone = local.zone
47+
cluster_name = var.cluster_name
48+
image_name = module.common.image_name
49+
vpc_name = module.vpc.vpc_name
50+
subnetwork_name = module.vpc.subnet_name
51+
ssh_key = module.common.ssh_key
52+
service_account_email = module.common.service_account_email
5253
}
5354

5455
module "msrs" {
@@ -64,30 +65,32 @@ module "msrs" {
6465
}
6566

6667
module "workers" {
67-
source = "./modules/worker"
68-
worker_count = var.worker_count
69-
gcp_region = var.gcp_region
70-
gcp_zone = local.zone
71-
cluster_name = var.cluster_name
72-
vpc_name = module.vpc.vpc_name
73-
subnetwork_name = module.vpc.subnet_name
74-
image_name = module.common.image_name
75-
ssh_key = module.common.ssh_key
76-
worker_type = var.worker_type
68+
source = "./modules/worker"
69+
worker_count = var.worker_count
70+
gcp_region = var.gcp_region
71+
gcp_zone = local.zone
72+
cluster_name = var.cluster_name
73+
vpc_name = module.vpc.vpc_name
74+
subnetwork_name = module.vpc.subnet_name
75+
image_name = module.common.image_name
76+
ssh_key = module.common.ssh_key
77+
worker_type = var.worker_type
78+
service_account_email = module.common.service_account_email
7779
}
7880

7981
module "windows_workers" {
80-
source = "./modules/windows_worker"
81-
worker_count = var.windows_worker_count
82-
gcp_zone = local.zone
83-
cluster_name = var.cluster_name
84-
vpc_name = module.vpc.vpc_name
85-
subnetwork_name = module.vpc.subnet_name
86-
image_name = module.common.windows_2019_image_name
87-
ssh_key = module.common.ssh_key
88-
worker_type = var.worker_type
89-
windows_user = var.windows_user
90-
windows_password = var.windows_password
82+
source = "./modules/windows_worker"
83+
worker_count = var.windows_worker_count
84+
gcp_zone = local.zone
85+
cluster_name = var.cluster_name
86+
vpc_name = module.vpc.vpc_name
87+
subnetwork_name = module.vpc.subnet_name
88+
image_name = module.common.windows_2019_image_name
89+
ssh_key = module.common.ssh_key
90+
worker_type = var.worker_type
91+
windows_user = var.windows_user
92+
windows_password = var.windows_password
93+
service_account_email = module.common.service_account_email
9194
}
9295

9396
locals {

examples/terraform/gcp/modules/common/main.tf

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,28 @@ resource "local_file" "ssh_public_key" {
1111
}
1212
}
1313

14+
1415
data "google_compute_image" "ubuntu" {
15-
family = "ubuntu-1804-lts"
16+
family = "ubuntu-2004-lts"
1617
project = "ubuntu-os-cloud"
1718
}
1819

1920
data "google_compute_image" "windows_2019" {
20-
family = "windows-2019-core-for-containers"
21+
family = "windows-2019-core"
2122
project = "windows-cloud"
2223
}
2324

25+
resource "google_service_account" "default" {
26+
account_id = "${var.cluster_name}-service-account-id"
27+
display_name = "Service Account"
28+
}
29+
30+
resource "google_project_iam_member" "default" {
31+
project = var.project_id
32+
member = "serviceAccount:${google_service_account.default.email}"
33+
role = "roles/compute.admin"
34+
}
35+
2436
resource "google_compute_firewall" "common_internal" {
2537
name = "${var.cluster_name}-internal"
2638
description = "mke cluster common rule to allow all internal traffic"

examples/terraform/gcp/modules/common/outputs.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,7 @@ output "windows_2019_image_name" {
99
output "ssh_key" {
1010
value = tls_private_key.ssh_key
1111
}
12+
13+
output "service_account_email" {
14+
value = google_service_account.default.email
15+
}

examples/terraform/gcp/modules/manager/main.tf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,20 @@ resource "google_compute_instance" "mke_manager" {
5353
access_config {
5454
}
5555
}
56+
5657
tags = [
58+
var.cluster_name,
5759
"allow-ssh",
5860
"allow-manager",
5961
"allow-internal"
6062
]
63+
64+
service_account {
65+
email = var.service_account_email
66+
scopes = [
67+
"https://www.googleapis.com/auth/cloud-platform"
68+
]
69+
}
6170
}
6271

6372
resource "google_compute_instance_group" "default" {

examples/terraform/gcp/modules/manager/variables.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ variable "image_name" {}
1212

1313
variable "ssh_key" {}
1414

15+
variable "service_account_email" {}
16+
1517
variable "manager_count" {
1618
default = 3
1719
}

examples/terraform/gcp/modules/msr/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ resource "google_compute_instance" "mke_msr" {
3737
}
3838
}
3939
tags = [
40+
var.cluster_name,
4041
"allow-ssh",
4142
"allow-msr",
4243
"allow-internal"

examples/terraform/gcp/modules/windows_worker/main.tf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,20 @@ EOF
104104
}
105105

106106
tags = [
107+
var.cluster_name,
107108
"allow-rdp",
108109
"allow-winrm",
109110
"allow-worker",
110111
"allow-internal"
111112
]
112113

114+
service_account {
115+
email = var.service_account_email
116+
scopes = [
117+
"https://www.googleapis.com/auth/cloud-platform"
118+
]
119+
}
120+
113121
provisioner "remote-exec" {
114122
connection {
115123
host = self.network_interface.0.access_config.0.nat_ip

examples/terraform/gcp/modules/windows_worker/variables.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ variable "image_name" {}
1010

1111
variable "ssh_key" {}
1212

13+
variable "service_account_email" {}
14+
1315
variable "worker_count" {
1416
default = 0
1517
}

examples/terraform/gcp/modules/worker/main.tf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,18 @@ resource "google_compute_instance" "mke_worker" {
2424
access_config {
2525
}
2626
}
27+
2728
tags = [
29+
var.cluster_name,
2830
"allow-ssh",
2931
"allow-worker",
3032
"allow-internal"
3133
]
34+
35+
service_account {
36+
email = var.service_account_email
37+
scopes = [
38+
"https://www.googleapis.com/auth/cloud-platform"
39+
]
40+
}
3241
}

examples/terraform/gcp/modules/worker/variables.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ variable "image_name" {}
1212

1313
variable "ssh_key" {}
1414

15+
variable "service_account_email" {}
16+
1517
variable "worker_count" {
1618
default = 3
1719
}

0 commit comments

Comments
 (0)