Skip to content

Commit b81ff73

Browse files
authored
fix: deprecates the usage of gcp-inspec and replaces integration tests with gcloud (#216)
1 parent 51bb8ba commit b81ff73

File tree

18 files changed

+857
-349
lines changed

18 files changed

+857
-349
lines changed

kitchen.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ verifier:
2727
name: terraform
2828
systems:
2929
- name: system
30-
backend: gcp
31-
shell: true
30+
backend: local
3231

3332
suites:
3433
- name: mysql-public

modules/postgresql/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ Note: CloudSQL provides [disk autoresize](https://cloud.google.com/sql/docs/mysq
1212
| additional\_users | A list of users to be created in your cluster | <pre>list(object({<br> name = string<br> password = string<br> }))</pre> | `[]` | no |
1313
| availability\_type | The availability type for the master instance.This is only used to set up high availability for the PostgreSQL instance. Can be either `ZONAL` or `REGIONAL`. | `string` | `"ZONAL"` | no |
1414
| backup\_configuration | The backup\_configuration settings subblock for the database setings | <pre>object({<br> enabled = bool<br> start_time = string<br> location = string<br> point_in_time_recovery_enabled = bool<br> })</pre> | <pre>{<br> "enabled": false,<br> "location": null,<br> "point_in_time_recovery_enabled": false,<br> "start_time": null<br>}</pre> | no |
15-
| create\_timeout | The optional timout that is applied to limit long database creates. | `string` | `"10m"` | no |
15+
| create\_timeout | The optional timout that is applied to limit long database creates. | `string` | `"15m"` | no |
1616
| database\_flags | The database flags for the master instance. See [more details](https://cloud.google.com/sql/docs/postgres/flags) | <pre>list(object({<br> name = string<br> value = string<br> }))</pre> | `[]` | no |
1717
| database\_version | The database version to use | `string` | n/a | yes |
1818
| db\_charset | The charset for the default database | `string` | `""` | no |
1919
| db\_collation | The collation for the default database. Example: 'en\_US.UTF8' | `string` | `""` | no |
2020
| db\_name | The name of the default database to create | `string` | `"default"` | no |
21-
| delete\_timeout | The optional timout that is applied to limit long database deletes. | `string` | `"10m"` | no |
21+
| delete\_timeout | The optional timout that is applied to limit long database deletes. | `string` | `"15m"` | no |
2222
| deletion\_protection | Used to block Terraform from deleting a SQL Instance. | `bool` | `true` | no |
2323
| disk\_autoresize | Configuration to increase storage size. | `bool` | `true` | no |
2424
| disk\_size | The disk size for the master instance. | `number` | `10` | no |
@@ -41,7 +41,7 @@ Note: CloudSQL provides [disk autoresize](https://cloud.google.com/sql/docs/mysq
4141
| read\_replicas | List of read replicas to create | <pre>list(object({<br> name = string<br> tier = string<br> zone = string<br> disk_type = string<br> disk_autoresize = bool<br> disk_size = string<br> user_labels = map(string)<br> database_flags = list(object({<br> name = string<br> value = string<br> }))<br> ip_configuration = object({<br> authorized_networks = list(map(string))<br> ipv4_enabled = bool<br> private_network = string<br> require_ssl = bool<br> })<br> }))</pre> | `[]` | no |
4242
| region | The region of the Cloud SQL resources | `string` | `"us-central1"` | no |
4343
| tier | The tier for the master instance. | `string` | `"db-f1-micro"` | no |
44-
| update\_timeout | The optional timout that is applied to limit long database updates. | `string` | `"10m"` | no |
44+
| update\_timeout | The optional timout that is applied to limit long database updates. | `string` | `"15m"` | no |
4545
| user\_labels | The key/value labels for the master instances. | `map(string)` | `{}` | no |
4646
| user\_name | The name of the default user | `string` | `"default"` | no |
4747
| user\_password | The password for the default user. If not set, a random one will be generated and available in the generated\_user\_password output variable. | `string` | `""` | no |

modules/postgresql/variables.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,19 +247,19 @@ variable "additional_users" {
247247
variable "create_timeout" {
248248
description = "The optional timout that is applied to limit long database creates."
249249
type = string
250-
default = "10m"
250+
default = "15m"
251251
}
252252

253253
variable "update_timeout" {
254254
description = "The optional timout that is applied to limit long database updates."
255255
type = string
256-
default = "10m"
256+
default = "15m"
257257
}
258258

259259
variable "delete_timeout" {
260260
description = "The optional timout that is applied to limit long database deletes."
261261
type = string
262-
default = "10m"
262+
default = "15m"
263263
}
264264

265265
variable "encryption_key_name" {

test/integration/mssql-ha/controls/mssql.rb

Lines changed: 108 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -12,46 +12,118 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
require 'json'
16+
1517
project_id = attribute('project_id')
1618
basename = attribute('name')
1719
authorized_network = attribute('authorized_network')
20+
region = "us-central1"
21+
22+
activation_policy = "ALWAYS"
23+
availability_type = "REGIONAL"
24+
data_disk_size_gb = 10
25+
data_disk_type = "PD_SSD"
26+
kind = "sql#settings"
27+
pricing_plan = "PER_USE"
28+
replication_type = "SYNCHRONOUS"
29+
storage_auto_resize = true
30+
storage_auto_resize_limit = 0
31+
tier = "db-custom-2-13312"
32+
33+
describe command("gcloud --project='#{project_id}' sql instances describe #{basename} --format=json") do
34+
its(:exit_status) { should eq 0 }
35+
its(:stderr) { should eq '' }
36+
37+
let!(:data) do
38+
if subject.exit_status == 0
39+
JSON.parse(subject.stdout)
40+
else
41+
{}
42+
end
43+
end
44+
45+
describe "mssql_ha_database" do
46+
it "global settings are valid" do
47+
expect(data['settings']['activationPolicy']).to eq "#{activation_policy}"
48+
expect(data['settings']['availabilityType']).to eq "#{availability_type}"
49+
expect(data['settings']['dataDiskSizeGb']).to eq "#{data_disk_size_gb}"
50+
expect(data['settings']['dataDiskType']).to eq "#{data_disk_type}"
51+
expect(data['settings']['kind']).to eq "#{kind}"
52+
expect(data['settings']['pricingPlan']).to eq "#{pricing_plan}"
53+
expect(data['settings']['replicationType']).to eq "#{replication_type}"
54+
expect(data['settings']['storageAutoResize']).to eq storage_auto_resize
55+
expect(data['settings']['storageAutoResizeLimit']).to eq "#{storage_auto_resize_limit}"
56+
expect(data['settings']['tier']).to eq "#{tier}"
57+
end
58+
59+
it "backend type is valid" do
60+
expect(data['backendType']).to eq 'SECOND_GEN'
61+
end
62+
63+
it "database versions is valid" do
64+
expect(data['databaseVersion']).to eq 'SQLSERVER_2017_STANDARD'
65+
end
66+
67+
it "state is valid" do
68+
expect(data['state']).to eq 'RUNNABLE'
69+
end
1870

19-
describe google_sql_database_instance(project: project_id, database: basename) do
20-
let(:expected_settings) {
21-
{
22-
activation_policy: "ALWAYS",
23-
availability_type: "REGIONAL",
24-
data_disk_size_gb: 10,
25-
data_disk_type: "PD_SSD",
26-
kind: "sql#settings",
27-
pricing_plan: "PER_USE",
28-
replication_type: "SYNCHRONOUS",
29-
storage_auto_resize: true,
30-
storage_auto_resize_limit: 0,
31-
tier: "db-custom-2-13312",
32-
}
33-
}
34-
let(:settings) { subject.settings.item }
35-
let(:backup_configuration) { settings[:backup_configuration] }
36-
let(:ip_configuration) { settings[:ip_configuration] }
37-
let(:location_preference) { settings[:location_preference] }
38-
let(:maintenance_window) { settings[:maintenance_window] }
39-
let(:user_labels) { settings[:user_labels] }
40-
41-
its(:backend_type) { should eq 'SECOND_GEN' }
42-
its(:database_version) { should eq 'SQLSERVER_2017_STANDARD' }
43-
its(:state) { should eq 'RUNNABLE' }
44-
its(:region) { should eq 'us-central1' }
45-
its(:gce_zone) { should eq 'us-central1-a' }
46-
47-
it { expect(settings).to include(expected_settings) }
48-
it { expect(ip_configuration).to include(authorized_networks: [{kind: 'sql#aclEntry', name: "#{project_id}-cidr", value: authorized_network}], ipv4_enabled: true, require_ssl: true) }
49-
it { expect(location_preference).to include(kind: "sql#locationPreference", zone: "us-central1-a") }
50-
it { expect(maintenance_window).to include(kind: "sql#maintenanceWindow", day: 7, hour: 12, update_track: "stable") }
51-
it { expect(user_labels).to include(foo: "bar") }
71+
it "region is valid" do
72+
expect(data['region']).to eq region
73+
end
74+
75+
it "gce zone is valid" do
76+
expect(data['gceZone']).to eq "#{region}-a"
77+
end
78+
79+
it "location preference is valid" do
80+
expect(data['settings']['locationPreference']).to include(
81+
"kind" => "sql#locationPreference",
82+
"zone" => "#{region}-a")
83+
end
84+
85+
it "maintenance window is valid" do
86+
expect(data['settings']['maintenanceWindow']).to include(
87+
"kind" => "sql#maintenanceWindow",
88+
"day" => 7,
89+
"hour" => 12,
90+
"updateTrack" => "stable")
91+
end
92+
93+
it "ip configuration and authorized networks are valid" do
94+
expect(data['settings']['ipConfiguration']).to include(
95+
["authorizedNetworks"][0] => [{
96+
"kind" => "sql#aclEntry",
97+
"name" => "#{project_id}-cidr",
98+
"value" => authorized_network
99+
}],
100+
"ipv4Enabled" => true,
101+
"requireSsl" => true,
102+
)
103+
end
104+
105+
it "user labels are set" do
106+
expect(data['settings']['userLabels']).to include(
107+
"foo" => "bar")
108+
end
109+
end
52110
end
53111

54-
describe google_sql_users(project: project_id, database: basename).where(user_name: /\Atftest/) do
55-
its(:count) { should be 3 }
56-
it { should exist }
112+
describe command("gcloud --project='#{project_id}' sql users list --instance #{basename} --format=json") do
113+
its(:exit_status) { should eq 0 }
114+
its(:stderr) { should eq '' }
115+
116+
let!(:data) do
117+
if subject.exit_status == 0
118+
JSON.parse(subject.stdout)
119+
else
120+
{}
121+
end
122+
end
123+
124+
describe "mssql_ha_database" do
125+
it "has 3 users" do
126+
expect(data.select {|k,v| k['name'].start_with?("tftest")}.size).to eq 3
127+
end
128+
end
57129
end

test/integration/mssql-ha/inspec.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@
1515
name: cloud-sql
1616
title: Google Cloud SQL
1717
version: 0.1.0
18-
depends:
19-
- name: inspec-gcp
20-
url: https://github.com/inspec/inspec-gcp/archive/v0.21.4.tar.gz
2118
attributes:
2219
- name: project_id
2320
type: string

test/integration/mssql-public/controls/mssql.rb

Lines changed: 72 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,33 +12,79 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
require 'json'
16+
1517
project_id = attribute('project_id')
1618
basename = attribute('name')
19+
region = "us-central1"
20+
21+
activation_policy = "ALWAYS"
22+
data_disk_size_gb = 10
23+
data_disk_type = "PD_SSD"
24+
kind = "sql#settings"
25+
pricing_plan = "PER_USE"
26+
replication_type = "SYNCHRONOUS"
27+
storage_auto_resize = true
28+
storage_auto_resize_limit = 0
29+
tier = "db-custom-2-3840"
30+
31+
describe command("gcloud --project='#{project_id}' sql instances describe #{basename} --format=json") do
32+
its(:exit_status) { should eq 0 }
33+
its(:stderr) { should eq '' }
34+
35+
let!(:data) do
36+
if subject.exit_status == 0
37+
JSON.parse(subject.stdout)
38+
else
39+
{}
40+
end
41+
end
42+
43+
describe "mssql_public_database" do
44+
it "global settings are valid" do
45+
expect(data['settings']['activationPolicy']).to eq "#{activation_policy}"
46+
expect(data['settings']['dataDiskSizeGb']).to eq "#{data_disk_size_gb}"
47+
expect(data['settings']['dataDiskType']).to eq "#{data_disk_type}"
48+
expect(data['settings']['kind']).to eq "#{kind}"
49+
expect(data['settings']['pricingPlan']).to eq "#{pricing_plan}"
50+
expect(data['settings']['replicationType']).to eq "#{replication_type}"
51+
expect(data['settings']['storageAutoResize']).to eq storage_auto_resize
52+
expect(data['settings']['storageAutoResizeLimit']).to eq "#{storage_auto_resize_limit}"
53+
expect(data['settings']['tier']).to eq "#{tier}"
54+
end
55+
56+
it "backend type is valid" do
57+
expect(data['backendType']).to eq 'SECOND_GEN'
58+
end
59+
60+
it "database versions is valid" do
61+
expect(data['databaseVersion']).to eq 'SQLSERVER_2017_STANDARD'
62+
end
63+
64+
it "state is valid" do
65+
expect(data['state']).to eq 'RUNNABLE'
66+
end
67+
68+
it "region is valid" do
69+
expect(data['region']).to eq region
70+
end
71+
72+
it "gce zone is valid" do
73+
expect(data['gceZone']).to eq "#{region}-a"
74+
end
75+
76+
it "location preference is valid" do
77+
expect(data['settings']['locationPreference']).to include(
78+
"kind" => "sql#locationPreference",
79+
"zone" => "#{region}-a")
80+
end
1781

18-
describe google_sql_database_instance(project: project_id, database: basename) do
19-
let(:expected_settings) {
20-
{
21-
activation_policy: "ALWAYS",
22-
data_disk_size_gb: 10,
23-
data_disk_type: "PD_SSD",
24-
kind: "sql#settings",
25-
pricing_plan: "PER_USE",
26-
replication_type: "SYNCHRONOUS",
27-
storage_auto_resize: true,
28-
storage_auto_resize_limit: 0,
29-
tier: "db-custom-2-3840",
30-
}
31-
}
32-
let(:settings) { subject.settings.item }
33-
let(:location_preference) { settings[:location_preference] }
34-
let(:maintenance_window) { settings[:maintenance_window] }
35-
36-
its(:backend_type) { should eq 'SECOND_GEN' }
37-
its(:database_version) { should eq 'SQLSERVER_2017_STANDARD' }
38-
its(:state) { should eq 'RUNNABLE' }
39-
its(:region) { should eq 'us-central1' }
40-
its(:gce_zone) { should eq 'us-central1-a' }
41-
it { expect(settings).to include(expected_settings) }
42-
it { expect(location_preference).to include(kind: "sql#locationPreference", zone: "us-central1-a") }
43-
it { expect(maintenance_window).to include(kind: "sql#maintenanceWindow", day: 1, hour: 23, update_track: "canary") }
82+
it "maintenance window is valid" do
83+
expect(data['settings']['maintenanceWindow']).to include(
84+
"kind" => "sql#maintenanceWindow",
85+
"day" => 1,
86+
"hour" => 23,
87+
"updateTrack" => "canary")
88+
end
89+
end
4490
end

test/integration/mssql-public/inspec.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@
1515
name: cloud-sql
1616
title: Google Cloud SQL
1717
version: 0.1.0
18-
depends:
19-
- name: inspec-gcp
20-
url: https://github.com/inspec/inspec-gcp/archive/v0.21.4.tar.gz
2118
attributes:
2219
- name: project_id
2320
type: string

0 commit comments

Comments
 (0)