forked from terraform-google-modules/terraform-google-iam
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Kunal Kumar Gupta
committed
Feb 10, 2020
1 parent
e14ae96
commit c710204
Showing
9 changed files
with
225 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/** | ||
* Copyright 2019 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
locals { | ||
billing_roles = ["roles/billing.admin", "roles/billing.viewer"] | ||
members = [var.member1, var.member2] | ||
|
||
member_group_0 = [ | ||
"serviceAccount:${var.member1}", | ||
"serviceAccount:${var.member2}", | ||
] | ||
|
||
member_group_1 = [ | ||
"serviceAccount:${var.member2}", | ||
] | ||
|
||
member_groups = [local.member_group_0, local.member_group_1] | ||
|
||
# 1 or 2 roles amount can be specified to generate that amount of bindings. | ||
# This variability is used to test how the module behaves on configuration updates. | ||
|
||
billing_bindings = zipmap( | ||
slice(local.billing_roles, 0, var.roles), | ||
slice(local.member_groups, 0, var.roles) | ||
) | ||
} | ||
|
||
provider "google" { | ||
version = "~> 2.7" | ||
} | ||
|
||
provider "google-beta" { | ||
version = "~> 2.7" | ||
} | ||
|
||
#additive | ||
|
||
module "iam_binding_billing_accounts_additive" { | ||
source = "../../../modules/billing_accounts_iam" | ||
mode = "additive" | ||
bindings = local.billing_bindings | ||
billing_account_ids = [var.billing_iam_test_account] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/** | ||
* Copyright 2019 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
# Resources | ||
|
||
#Additive | ||
|
||
output "billing_iam_test_account" { | ||
value = module.iam_binding_billing_accounts_additive.billing_account_ids | ||
description = "Billing Accounts which received bindings." | ||
} | ||
|
||
output "roles" { | ||
value = module.iam_binding_billing_accounts_additive.roles | ||
description = "Roles which were assigned to members." | ||
} | ||
|
||
output "members" { | ||
value = module.iam_binding_billing_accounts_additive.members | ||
description = "Members which were bound to the billing accounts." | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/** | ||
* Copyright 2019 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
variable "member1" { | ||
type = string | ||
description = "Member created for binding with roles." | ||
} | ||
|
||
variable "member2" { | ||
type = string | ||
description = "Member created for binding with roles." | ||
} | ||
|
||
variable "roles" { | ||
type = number | ||
default = 2 | ||
description = "Amount of roles to assign. Useful for testing how the module behaves on updates." | ||
} | ||
|
||
variable "billing_iam_test_account" { | ||
type = string | ||
description = "Billing Accounts IDs list to add the IAM policies/bindings." | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# Copyright 2019 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# Billing Bindings | ||
|
||
billing_iam_test_account = attribute('billing_iam_test_account') | ||
members = attribute('members') | ||
|
||
control "GCP Billing IAM" do | ||
title "GCP Billing Bindings" | ||
billing_iam_test_account.each do |billing_iam_test_account| | ||
describe command ("gcloud beta billing accounts get-iam-policy #{billing_iam_test_account} --format=json") do | ||
its(:exit_status) { should eq 0 } | ||
its(:stderr) { should eq '' } | ||
|
||
let!(:data) do | ||
if subject.exit_status == 0 | ||
JSON.parse(subject.stdout) | ||
else | ||
{} | ||
end | ||
end | ||
|
||
describe "members" do | ||
it "are bound" do | ||
members.each do |member| | ||
expect(data['bindings'][0]['members']).to include(member) | ||
end | ||
end | ||
|
||
it "are admin" do | ||
expect(data['bindings'][0]['role']).to eq 'roles/billing.admin' | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Copyright 2019 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
name: billing-iam | ||
attributes: | ||
- name: billing_iam_test_account | ||
required: true | ||
type: array | ||
- name: roles | ||
required: true | ||
type: array | ||
- name: members | ||
required: true | ||
type: array |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters