Skip to content

Commit aa3aab1

Browse files
committed
single service account test
1 parent 11d117b commit aa3aab1

File tree

10 files changed

+33
-32
lines changed

10 files changed

+33
-32
lines changed

examples/single_service_account/main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ provider "google" {
2121
module "service_accounts" {
2222
source = "../.."
2323
project_id = "${var.project_id}"
24-
prefix = "single-test"
25-
names = ["first"]
24+
prefix = "${var.prefix}"
25+
names = ["single-account"]
2626
project_roles = ["${var.project_id}=>roles/viewer"]
2727
}

examples/single_service_account/variables.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,8 @@ variable "project_id" {
1818
description = "The ID of the project in which to provision resources."
1919
type = "string"
2020
}
21+
22+
variable "prefix" {
23+
description = "Prefix applied to service account names."
24+
default = ""
25+
}

kitchen.yml

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,13 @@ platforms:
2626
- name: default
2727

2828
suites:
29-
- name: simple_example
29+
- name: single_service_account
3030
driver:
31-
root_module_directory: test/fixtures/simple_example/
31+
root_module_directory: test/fixtures/single_service_account/
3232
verifier:
3333
color: false
3434
systems:
35-
- name: simple_example local
36-
backend: local
37-
controls:
38-
- gcloud
39-
- gsutil
40-
- name: simple_example gcp
35+
- name: single_service_account gcp
4136
backend: gcp
4237
controls:
4338
- gcp

test/fixtures/simple_example/main.tf renamed to test/fixtures/single_service_account/main.tf

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
provider "random" {
18-
version = "~> 2.0"
19-
}
20-
21-
resource "random_pet" "main" {
22-
length = 1
23-
prefix = "simple-example"
24-
separator = "-"
25-
}
26-
2717
module "example" {
28-
source = "../../../examples/simple_example"
29-
30-
project_id = "${var.project_id}"
31-
bucket_name = "${random_pet.main.id}"
18+
source = "../../../examples/single_service_account"
19+
project_id = "${var.project_id}"
3220
}

test/fixtures/simple_example/outputs.tf renamed to test/fixtures/single_service_account/outputs.tf

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,17 @@
1414
* limitations under the License.
1515
*/
1616

17-
output "bucket_name" {
18-
description = "The name of the bucket."
19-
value = "${module.example.bucket_name}"
17+
output "email" {
18+
description = "The service account email."
19+
value = "${module.example.email}"
20+
}
21+
22+
output "iam_email" {
23+
description = "The service account IAM-format email."
24+
value = "${module.example.iam_email}"
2025
}
2126

2227
output "project_id" {
23-
description = "The ID of the project in which resources are provisioned."
28+
description = "Project id variable."
2429
value = "${var.project_id}"
2530
}

test/integration/simple_example/controls/gcp.rb renamed to test/integration/single_service_account/controls/gcp.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@
1515
control "gcp" do
1616
title "GCP Resources"
1717

18-
describe google_storage_bucket(name: attribute("bucket_name")) do
19-
it { should exist }
18+
describe google_service_account(name: "projects/#{attribute("project_id")}/serviceAccounts/#{attribute("email")}") do
19+
its('project_id') { should eq attribute('project_id') }
2020
end
21+
22+
describe google_project_iam_binding(project: "#{attribute("project_id")}", role: 'roles/viewer') do
23+
its('members') {should include attribute('iam_email') }
24+
end
25+
2126
end
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: simple_example
1+
name: single_service_account
22
depends:
33
- name: inspec-gcp
44
git: https://github.com/inspec/inspec-gcp.git
@@ -7,6 +7,9 @@ attributes:
77
- name: project_id
88
required: true
99
type: string
10-
- name: bucket_name
10+
- name: email
11+
required: true
12+
type: string
13+
- name: iam_email
1114
required: true
1215
type: string

0 commit comments

Comments
 (0)