Skip to content

Commit 5fd2a31

Browse files
authored
Merge pull request #88 from terraform-google-modules/feature/default-to-creating-new-service-account-for-cluster
Change service account default to create a new SA per cluster
2 parents 4424b49 + 2d56e83 commit 5fd2a31

File tree

10 files changed

+95
-9
lines changed

10 files changed

+95
-9
lines changed

.kitchen.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,14 @@ suites:
9898
name: terraform
9999
color: false
100100
systems:
101-
- name: simple_zonal
101+
- name: gcloud
102102
backend: local
103+
controls:
104+
- gcloud
105+
- name: gcp
106+
backend: gcp
107+
controls:
108+
- gcp
103109
provisioner:
104110
name: terraform
105111
- name: "simple_zonal_private"

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ Extending the adopted spec, each change should have a link to its corresponding
1010

1111
## [v2.0.0] - 2019-YY-ZZ
1212

13+
### Changed
14+
15+
* The `service_account` variable defaults to `"create"` which causes a
16+
cluster-specific service account to be created.
17+
1318
## [v1.0.1] - 2019-04-04
1419

1520
### Added

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ In either case, upgrading to module version `v1.0.0` will trigger a recreation o
135135
| region | The region to host the cluster in (required) | string | n/a | yes |
136136
| regional | Whether is a regional cluster (zonal cluster if set false. WARNING: changing this after cluster creation is destructive!) | string | `"true"` | no |
137137
| remove\_default\_node\_pool | Remove default node pool while setting up the cluster | string | `"false"` | no |
138-
| service\_account | The service account to default running nodes as if not overridden in `node_pools`. Defaults to the compute engine default service account. May also specify `create` to automatically create a cluster-specific service account | string | `""` | no |
138+
| service\_account | The service account to run nodes as if not overridden in `node_pools`. The default value will cause a cluster-specific service account to be created. | string | `"create"` | no |
139139
| stub\_domains | Map of stub domains and their resolvers to forward DNS queries for a certain domain to an external DNS server | map | `<map>` | no |
140140
| subnetwork | The subnetwork to host the cluster in (required) | string | n/a | yes |
141141
| zones | The zones to host the cluster in (optional if regional cluster / required if zonal) | list | `<list>` | no |

autogen/variables.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,8 @@ variable "monitoring_service" {
214214
}
215215

216216
variable "service_account" {
217-
description = "The service account to default running nodes as if not overridden in `node_pools`. Defaults to the compute engine default service account. May also specify `create` to automatically create a cluster-specific service account"
218-
default = ""
217+
description = "The service account to run nodes as if not overridden in `node_pools`. The default value will cause a cluster-specific service account to be created."
218+
default = "create"
219219
}
220220
{% if private_cluster %}
221221
variable "enable_private_endpoint" {

docs/upgrading_to_v2.0.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,40 @@ The v2.0 release of *kubernetes-engine* is a backwards incompatible
44
release.
55

66
## Migration Instructions
7+
8+
### Using Default Service Account
9+
10+
In previous versions of *kubernetes-engine*, the default service
11+
account of the hosting project was used by the Node VMs if no other
12+
service account was explicitly configured. A dedicated service account
13+
is now created for the Node VMs if no other service account is
14+
explicitly configured.
15+
16+
The default service account of the hosting project can still be used if
17+
desired, as shown in the following example:
18+
19+
```hcl
20+
module "project_factory" {
21+
source = "terraform-google-modules/project-factory/google"
22+
version = "~> 2.1"
23+
24+
billing_account = "XXXXXX-YYYYYY-ZZZZZZ"
25+
name = "example"
26+
org_id = "XXXXXXXXXXXX"
27+
}
28+
29+
module "kubernetes_engine" {
30+
source = "terraform-google-modules/kubernetes-engine/google"
31+
version = "~> 2.0"
32+
33+
ip_range_pods = "secondary-subnet-ip-range-pods"
34+
ip_range_services = "secondary-subnet-ip-range-services"
35+
name = "example"
36+
network = "cluster-network"
37+
project_id = "${module.project_factory.project_id}"
38+
region = "northamerica-northeast"
39+
subnetwork = "cluster-subnetwork"
40+
41+
service_account = "${module.project_factory.service_account_email}"
42+
}
43+
```

modules/private-cluster/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ In either case, upgrading to module version `v1.0.0` will trigger a recreation o
143143
| region | The region to host the cluster in (required) | string | n/a | yes |
144144
| regional | Whether is a regional cluster (zonal cluster if set false. WARNING: changing this after cluster creation is destructive!) | string | `"true"` | no |
145145
| remove\_default\_node\_pool | Remove default node pool while setting up the cluster | string | `"false"` | no |
146-
| service\_account | The service account to default running nodes as if not overridden in `node_pools`. Defaults to the compute engine default service account. May also specify `create` to automatically create a cluster-specific service account | string | `""` | no |
146+
| service\_account | The service account to run nodes as if not overridden in `node_pools`. The default value will cause a cluster-specific service account to be created. | string | `"create"` | no |
147147
| stub\_domains | Map of stub domains and their resolvers to forward DNS queries for a certain domain to an external DNS server | map | `<map>` | no |
148148
| subnetwork | The subnetwork to host the cluster in (required) | string | n/a | yes |
149149
| zones | The zones to host the cluster in (optional if regional cluster / required if zonal) | list | `<list>` | no |

modules/private-cluster/variables.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,8 @@ variable "monitoring_service" {
214214
}
215215

216216
variable "service_account" {
217-
description = "The service account to default running nodes as if not overridden in `node_pools`. Defaults to the compute engine default service account. May also specify `create` to automatically create a cluster-specific service account"
218-
default = ""
217+
description = "The service account to run nodes as if not overridden in `node_pools`. The default value will cause a cluster-specific service account to be created."
218+
default = "create"
219219
}
220220
variable "enable_private_endpoint" {
221221
description = "(Beta) Whether the master's internal IP address is used as the cluster endpoint"
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Copyright 2018 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
control "gcp" do
16+
title "Native InSpec Resources"
17+
18+
service_account = attribute("service_account")
19+
project_id = attribute("project_id")
20+
21+
if service_account.start_with? "projects/"
22+
service_account_name = service_account
23+
else
24+
service_account_name = "projects/#{project_id}/serviceAccounts/#{service_account}"
25+
end
26+
27+
describe google_service_account name: service_account_name do
28+
its("display_name") { should eq "Terraform-managed service account for cluster #{attribute("cluster_name")}" }
29+
its("project_id") { should eq project_id }
30+
end
31+
end

test/integration/simple_zonal/inspec.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
name: simple_zonal
2+
depends:
3+
- name: inspec-gcp
4+
git: https://github.com/inspec/inspec-gcp.git
5+
tag: v0.10.0
26
attributes:
37
- name: project_id
48
required: true
@@ -21,3 +25,6 @@ attributes:
2125
- name: service_account
2226
required: true
2327
type: string
28+
- name: service_account
29+
required: true
30+
type: string

variables.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,6 @@ variable "monitoring_service" {
214214
}
215215

216216
variable "service_account" {
217-
description = "The service account to default running nodes as if not overridden in `node_pools`. Defaults to the compute engine default service account. May also specify `create` to automatically create a cluster-specific service account"
218-
default = ""
217+
description = "The service account to run nodes as if not overridden in `node_pools`. The default value will cause a cluster-specific service account to be created."
218+
default = "create"
219219
}

0 commit comments

Comments
 (0)