Skip to content

Commit f1be84b

Browse files
committed
Merge branch 'custom-gcr-project' of github.com:mmontan/terraform-google-kubernetes-engine into custom-gcr-project
2 parents ec9d46b + d791335 commit f1be84b

File tree

5 files changed

+30
-6
lines changed

5 files changed

+30
-6
lines changed

examples/workload_metadata_config/main.tf

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@ module "gke" {
4040
subnetwork = var.subnetwork
4141
ip_range_pods = var.ip_range_pods
4242
ip_range_services = var.ip_range_services
43-
create_service_account = false
44-
service_account = var.compute_engine_service_account
43+
create_service_account = true
44+
grant_registry_access = true
45+
registry_project_id = var.registry_project_id
4546
enable_private_endpoint = true
4647
enable_private_nodes = true
4748
master_ipv4_cidr_block = "172.16.0.0/28"

examples/workload_metadata_config/variables.tf

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ variable "ip_range_services" {
4848
description = "The secondary ip range to use for pods"
4949
}
5050

51-
variable "compute_engine_service_account" {
52-
description = "Service account to associate to the nodes in the cluster"
51+
variable "registry_project_id" {
52+
description = "Project name for the GCR registry"
5353
}
54-

test/fixtures/workload_metadata_config/example.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ module "example" {
2525
subnetwork = google_compute_subnetwork.main.name
2626
ip_range_pods = google_compute_subnetwork.main.secondary_ip_range[0].range_name
2727
ip_range_services = google_compute_subnetwork.main.secondary_ip_range[1].range_name
28-
compute_engine_service_account = var.compute_engine_service_account
28+
registry_project_id = var.registry_project_id
2929
}

test/integration/workload_metadata_config/controls/gcloud.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313
# limitations under the License.
1414

1515
project_id = attribute('project_id')
16+
registry_project_id = attribute('registry_project_id')
1617
location = attribute('location')
1718
cluster_name = attribute('cluster_name')
19+
service_account = attribute('service_account')
1820

1921
control "gcloud" do
2022
title "Google Compute Engine GKE configuration"
@@ -55,4 +57,20 @@
5557
end
5658
end
5759
end
60+
61+
describe command("gcloud projects get-iam-policy #{registry_project_id} --format=json") do
62+
its(:exit_status) { should eq 0 }
63+
its(:stderr) { should eq '' }
64+
65+
let!(:iam) do
66+
if subject.exit_status == 0
67+
JSON.parse(subject.stdout)
68+
else
69+
{}
70+
end
71+
end
72+
it "has expected registry roles" do
73+
expect(iam['bindings']).to include("members" => ["serviceAccount:#{service_account}"], "role" => "roles/storage.objectViewer")
74+
end
75+
end
5876
end

test/integration/workload_metadata_config/inspec.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,9 @@ attributes:
99
- name: project_id
1010
required: true
1111
type: string
12+
- name: service_account
13+
required: true
14+
type: string
15+
- name: registry_project_id
16+
required: false
17+
type: string

0 commit comments

Comments
 (0)