Skip to content

Commit 23bfac9

Browse files
committed
Get tests for private_zonal_with_network to function correctly
1 parent c3d6536 commit 23bfac9

File tree

7 files changed

+41
-116
lines changed

7 files changed

+41
-116
lines changed

.kitchen.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ suites:
7777
backend: local
7878
controls:
7979
- gcloud
80-
- name: subnet
80+
- name: private_zonal_with_networking
8181
backend: local
8282
controls:
8383
- subnet

examples/private_zonal_with_networking/outputs.tf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,3 @@ output "subnet_secondary_ranges" {
5757
}
5858

5959

60-

examples/private_zonal_with_networking/test_outputs.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@ output "project_id" {
2121
value = var.project_id
2222
}
2323

24-
output "region" {
25-
value = module.gke.region
26-
}
27-
2824
output "network" {
2925
value = var.network
3026
}
@@ -37,6 +33,10 @@ output "location" {
3733
value = module.gke.location
3834
}
3935

36+
output "region" {
37+
value = var.region
38+
}
39+
4040
output "ip_range_pods_name" {
4141
description = "The secondary IP range used for pods"
4242
value = var.ip_range_pods_name

examples/private_zonal_with_networking/variables.tf

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ variable "cluster_name" {
2525

2626
variable "region" {
2727
description = "The region to host the cluster in"
28-
default = "us-central1"
28+
}
29+
30+
variable "zones" {
31+
type = list(string)
32+
description = "The zone to host the cluster in (required if is a zonal cluster)"
2933
}
3034

3135
variable "network" {
@@ -48,7 +52,3 @@ variable "ip_range_services_name" {
4852
default = "ip-range-scv"
4953
}
5054

51-
variable "zones" {
52-
default = []
53-
}
54-

test/integration/private_zonal_with_networking/controls/gcloud.rb

Lines changed: 3 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -75,53 +75,19 @@
7575
)
7676
)
7777
end
78-
end
79-
80-
describe "node pool" do
81-
let(:node_pools) { data['nodePools'].reject { |p| p['name'] == "default-pool" } }
82-
83-
it "has autoscaling enabled" do
84-
expect(node_pools).to include(
85-
including(
86-
"autoscaling" => including(
87-
"enabled" => true,
88-
),
89-
)
90-
)
91-
end
92-
93-
it "has the expected minimum node count" do
94-
expect(node_pools).to include(
95-
including(
96-
"autoscaling" => including(
97-
"minNodeCount" => 1,
98-
),
99-
)
100-
)
101-
end
102-
103-
it "has the expected maximum node count" do
104-
expect(node_pools).to include(
105-
including(
106-
"autoscaling" => including(
107-
"maxNodeCount" => 100,
108-
),
109-
)
110-
)
111-
end
11278

11379
it "is the expected machine type" do
114-
expect(node_pools).to include(
80+
expect(data['nodePools']).to include(
11581
including(
11682
"config" => including(
117-
"machineType" => "n1-standard-2",
83+
"machineType" => "n1-standard-1",
11884
),
11985
)
12086
)
12187
end
12288

12389
it "has the expected disk size" do
124-
expect(node_pools).to include(
90+
expect(data['nodePools']).to include(
12591
including(
12692
"config" => including(
12793
"diskSizeGb" => 100,
@@ -130,51 +96,6 @@
13096
)
13197
end
13298

133-
it "has the expected labels" do
134-
expect(node_pools).to include(
135-
including(
136-
"config" => including(
137-
"labels" => including(
138-
"cluster_name" => cluster_name,
139-
"node_pool" => "default-node-pool",
140-
),
141-
),
142-
)
143-
)
144-
end
145-
146-
it "has the expected network tags" do
147-
expect(node_pools).to include(
148-
including(
149-
"config" => including(
150-
"tags" => match_array([
151-
"gke-#{cluster_name}",
152-
"gke-#{cluster_name}-default-node-pool",
153-
]),
154-
),
155-
)
156-
)
157-
end
158-
159-
it "has autorepair enabled" do
160-
expect(node_pools).to include(
161-
including(
162-
"management" => including(
163-
"autoRepair" => true,
164-
),
165-
)
166-
)
167-
end
168-
169-
it "has autoupgrade enabled" do
170-
expect(node_pools).to include(
171-
including(
172-
"management" => including(
173-
"autoUpgrade" => true,
174-
),
175-
)
176-
)
177-
end
17899
end
179100
end
180101
end

test/integration/private_zonal_with_networking/controls/subnet.rb

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,34 @@
1818
region = attribute('region')
1919
ip_range_pods_name = attribute('ip_range_pods_name')
2020
ip_range_services_name = attribute('ip_range_services_name')
21+
2122
control "subnet" do
22-
title "gcp subnetwork configuration"
23-
describe command("gcloud compute networks subnets describe #{subnet_name} --project=#{project_id} --region=#{region} --format=json") do
24-
its(:exit_status) { should eq 0 }
25-
its(:stderr) { should eq '' }
26-
let(:data) do
27-
if subject.exit_status == 0
28-
JSON.parse(subject.stdout)
29-
else
30-
{}
31-
end
32-
end
33-
it "#should have the correct secondaryIpRanges configuration for #{ip_range_pods_name}" do
34-
expect(data["secondaryIpRanges"][0]).to include(
35-
"rangeName" => ip_range_pods_name,
36-
"ipCidrRange" => "192.168.0.0/18"
37-
)
38-
end
39-
it "#should have the correct secondaryIpRanges configuration for #{ip_range_services_name}" do
40-
expect(data["secondaryIpRanges"][1]).to include(
41-
"rangeName" => ip_range_services_name,
42-
"ipCidrRange" => "192.168.64.0/18"
43-
)
23+
title "gcp subnetwork configuration"
24+
describe command("gcloud compute networks subnets describe #{subnet_name} --project=#{project_id} --region=#{region} --format=json") do
25+
its(:exit_status) { should eq 0 }
26+
its(:stderr) { should eq '' }
27+
28+
let!(:data) do
29+
if subject.exit_status == 0
30+
JSON.parse(subject.stdout)
31+
else
32+
{}
4433
end
4534
end
35+
36+
it "#should have the correct secondaryIpRanges configuration for #{ip_range_pods_name}" do
37+
expect(data["secondaryIpRanges"][0]).to include(
38+
"rangeName" => ip_range_pods_name,
39+
"ipCidrRange" => "192.168.0.0/18"
40+
)
41+
end
42+
43+
it "#should have the correct secondaryIpRanges configuration for #{ip_range_services_name}" do
44+
expect(data["secondaryIpRanges"][1]).to include(
45+
"rangeName" => ip_range_services_name,
46+
"ipCidrRange" => "192.168.64.0/18"
47+
)
48+
end
49+
4650
end
51+
end

test/integration/private_zonal_with_networking/inspec.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: simple_regional_with_networking
1+
name: private_zonal_with_networking
22
depends:
33
- name: inspec-gcp
44
git: https://github.com/inspec/inspec-gcp.git

0 commit comments

Comments
 (0)