rename iam variable in source repo module

This commit is contained in:
Ludovico Magnocavallo 2020-11-05 08:58:05 +01:00
parent 7e96e899d5
commit 462a7023cd
7 changed files with 114 additions and 8 deletions

View File

@ -12,7 +12,7 @@ module "repo" {
source e = "./modules/source-repository"
project_id = "my-project"
name = "my-repo"
iam_members = {
iam = {
"roles/source.reader" = ["user:foo@example.com"]
}
}
@ -23,9 +23,9 @@ module "repo" {
| name | description | type | required | default |
|---|---|:---: |:---:|:---:|
| name | Repository topic name. | <code title="">string</code> | ✓ | |
| name | Repository name. | <code title="">string</code> | ✓ | |
| project_id | Project used for resources. | <code title="">string</code> | ✓ | |
| *iam_members* | IAM members for each topic role. | <code title="map&#40;set&#40;string&#41;&#41;">map(set(string))</code> | | <code title="">{}</code> |
| *iam* | IAM bindings in {ROLE => [MEMBERS]} format. | <code title="map&#40;list&#40;string&#41;&#41;">map(list(string))</code> | | <code title="">{}</code> |
## Outputs

View File

@ -20,7 +20,7 @@ resource "google_sourcerepo_repository" "default" {
}
resource "google_sourcerepo_repository_iam_binding" "default" {
for_each = var.iam_members
for_each = var.iam
project = var.project_id
repository = google_sourcerepo_repository.default.name
role = each.key

View File

@ -19,13 +19,13 @@ variable "project_id" {
type = string
}
variable "iam_members" {
description = "IAM members for each topic role."
type = map(set(string))
variable "iam" {
description = "IAM bindings in {ROLE => [MEMBERS]} format."
type = map(list(string))
default = {}
}
variable "name" {
description = "Repository topic name."
description = "Repository name."
type = string
}

View File

@ -0,0 +1,13 @@
# Copyright 2020 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.

View File

@ -0,0 +1,22 @@
/**
* Copyright 2020 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.
*/
module "test" {
source = "../../../../modules/source-repository"
project_id = var.project_id
name = var.name
iam = var.iam
}

View File

@ -0,0 +1,32 @@
/**
* Copyright 2020 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 "project_id" {
type = string
default = "test-project"
}
variable "iam" {
type = map(list(string))
default = {
"roles/source.reader" = ["foo@example.org"]
}
}
variable "name" {
type = string
default = "test"
}

View File

@ -0,0 +1,39 @@
# Copyright 2020 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.
import os
import pytest
FIXTURES_DIR = os.path.join(os.path.dirname(__file__), 'fixture')
@pytest.fixture
def resources(plan_runner):
_, resources = plan_runner(FIXTURES_DIR)
return resources
def test_resource_count(resources):
"Test number of resources created."
assert len(resources) == 2
def test_iam(resources):
"Test IAM binding resources."
bindings = [r['values'] for r in resources if r['type']
== 'google_sourcerepo_repository_iam_binding']
assert len(bindings) == 1
assert bindings[0]['role'] == 'roles/source.reader'