Skip to content
This repository has been archived by the owner on Nov 14, 2024. It is now read-only.

Commit

Permalink
Add test for key types, fix service account keys resource (#3452) (#393)
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician authored May 5, 2020
1 parent b93553e commit 3195fbb
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docs/resources/google_service_account_key.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ A `google_service_account_key` is used to test a Google ServiceAccountKey resour
## Examples
```
google_service_account_keys(project: 'chef-gcp-inspec', service_account: "display-name@project-id.iam.gserviceaccount.com").key_names.each do |sa_key_name|
describe google_service_account_key(project: 'chef-gcp-inspec', service_account: "display-name@project-id.iam.gserviceaccount.com", name: sa_key_name) do
describe google_service_account_key(project: 'chef-gcp-inspec', service_account: "display-name@project-id.iam.gserviceaccount.com", name: sa_key_name.split('/').last) do
it { should exist }
its('key_type') { should_not cmp 'USER_MANAGED' }
end
Expand Down
1 change: 1 addition & 0 deletions docs/resources/google_service_account_keys.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ A `google_service_account_keys` is used to test a Google ServiceAccountKey resou
```
describe google_service_account_keys(project: 'chef-gcp-inspec', service_account: "display-name@project-id.iam.gserviceaccount.com") do
its('count') { should be <= 1000 }
its('key_types') { should_not include 'USER_MANAGED' }
end
```

Expand Down
2 changes: 1 addition & 1 deletion libraries/google_service_account_keys.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class IAMServiceAccountKeys < GcpResourceBase
def initialize(params = {})
super(params.merge({ use_http_transport: true }))
@params = params
@table = fetch_wrapped_resource('serviceAccountKeys')
@table = fetch_wrapped_resource('keys')
end

def fetch_wrapped_resource(wrap_path)
Expand Down
5 changes: 5 additions & 0 deletions test/integration/build/gcp-mm.tf
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,11 @@ resource "google_service_account" "spanner_service_account" {
display_name = "${var.gcp_service_account_display_name}-sp"
}

resource "google_service_account_key" "userkey" {
service_account_id = google_service_account.spanner_service_account.name
public_key_type = "TYPE_X509_PEM_FILE"
}

resource "google_spanner_instance" "spanner_instance" {
project = var.gcp_project_id
config = var.spannerinstance["config"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

only_if { gcp_enable_privileged_resources.to_i == 1 && gcp_organization_id != '' }
google_service_account_keys(project: gcp_project_id, service_account: "#{gcp_service_account_display_name}@#{gcp_project_id}.iam.gserviceaccount.com").key_names.each do |sa_key_name|
describe google_service_account_key(project: gcp_project_id, service_account: "#{gcp_service_account_display_name}@#{gcp_project_id}.iam.gserviceaccount.com", name: sa_key_name) do
describe google_service_account_key(project: gcp_project_id, service_account: "#{gcp_service_account_display_name}@#{gcp_project_id}.iam.gserviceaccount.com", name: sa_key_name.split('/').last) do
it { should exist }
its('key_type') { should_not cmp 'USER_MANAGED' }
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@
only_if { gcp_enable_privileged_resources.to_i == 1 && gcp_organization_id != '' }
describe google_service_account_keys(project: gcp_project_id, service_account: "#{gcp_service_account_display_name}@#{gcp_project_id}.iam.gserviceaccount.com") do
its('count') { should be <= 1000 }
its('key_types') { should_not include 'USER_MANAGED' }
end
end

0 comments on commit 3195fbb

Please sign in to comment.