Skip to content

Commit 716fb12

Browse files
committed
fix example README files, add simple tests
1 parent aa3aab1 commit 716fb12

File tree

9 files changed

+104
-33
lines changed

9 files changed

+104
-33
lines changed

examples/multiple_service_accounts/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Simple Example
1+
# Multiple Service Accounts
22

3-
This example illustrates how to use the `service-accounts` module.
3+
This example illustrates how to use the `service-accounts` module to generate multiple service accounts.
44

55
[^]: (autogen_docs_start)
66

examples/single_service_account/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Simple Example
1+
# Single Service Account
22

3-
This example illustrates how to use the `service-accounts` module.
3+
This example illustrates how to use the `service-accounts` module to generate a single service account.
44

55
[^]: (autogen_docs_start)
66

kitchen.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,13 @@ suites:
3636
backend: gcp
3737
controls:
3838
- gcp
39+
- name: multiple_service_accounts
40+
driver:
41+
root_module_directory: test/fixtures/multiple_service_accounts/
42+
verifier:
43+
color: false
44+
systems:
45+
- name: multiple_service_accounts gcp
46+
backend: gcp
47+
controls:
48+
- gcp
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* Copyright 2018 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
module "example" {
18+
source = "../../../examples/multiple_service_accounts"
19+
project_id = "${var.project_id}"
20+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* Copyright 2018 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
output "emails" {
18+
description = "The service account emails."
19+
value = "${module.example.emails}"
20+
}
21+
22+
output "project_id" {
23+
description = "Project id variable."
24+
value = "${var.project_id}"
25+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* Copyright 2018 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
variable "project_id" {
18+
description = "The ID of the project in which to provision resources."
19+
type = "string"
20+
}

test/integration/single_service_account/controls/gsutil.rb renamed to test/integration/multiple_service_accounts/controls/gcp.rb

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

15-
control "gsutil" do
16-
title "gsutil"
15+
control "gcp" do
16+
title "GCP Resources"
1717

18-
describe command("gsutil ls -p #{attribute("project_id")}") do
19-
its(:exit_status) { should eq 0 }
20-
its(:stderr) { should eq "" }
21-
its(:stdout) { should match "gs://#{attribute("bucket_name")}" }
18+
attribute('emails').each do |email|
19+
describe google_service_accounts(project: 'ludo-tf-playground') do
20+
its('service_account_emails'){ should include email }
21+
end
22+
describe google_project_iam_binding(project: "#{attribute("project_id")}", role: 'roles/viewer') do
23+
its('members') {should include "serviceAccount:#{email}" }
24+
end
25+
describe google_project_iam_binding(project: "#{attribute("project_id")}", role: 'roles/storage.objectViewer') do
26+
its('members') {should include "serviceAccount:#{email}" }
27+
end
2228
end
29+
2330
end
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: multiple_service_accounts
2+
depends:
3+
- name: inspec-gcp
4+
git: https://github.com/inspec/inspec-gcp.git
5+
tag: v0.10.0
6+
attributes:
7+
- name: project_id
8+
required: true
9+
type: string
10+
- name: emails
11+
required: true
12+
type: array

test/integration/single_service_account/controls/gcloud.rb

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)