Source repository module (#76)

* Source repository module

* Fix typos
This commit is contained in:
Julio Castillo 2020-05-14 20:48:29 +02:00 committed by GitHub
parent dd365f6bb0
commit 2946d28727
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 151 additions and 0 deletions

View File

@ -0,0 +1,38 @@
# Google Cloud Source Repository Module
This module allows managing a single Cloud Source Repository, including IAM bindings.
## Examples
### Simple repository with IAM
```hcl
module "repo" {
source e = "./modules/source-repository"
project_id = "my-project"
name = "my-repo"
iam_roles = ["roles/source.reader"]
iam_members = {
"roles/source.reader" = ["user:foo@example.com"]
}
}
```
<!-- BEGIN TFDOC -->
## Variables
| name | description | type | required | default |
|---|---|:---: |:---:|:---:|
| name | Repository topic 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;list&#40;string&#41;&#41;">map(list(string))</code> | | <code title="">{}</code> |
| *iam_roles* | IAM roles for topic. | <code title="list&#40;string&#41;">list(string)</code> | | <code title="">[]</code> |
## Outputs
| name | description | sensitive |
|---|---|:---:|
| id | Repository id. | |
| url | Repository URL. | |
<!-- END TFDOC -->

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.
*/
resource "google_sourcerepo_repository" "default" {
project = var.project_id
name = var.name
}
resource "google_sourcerepo_repository_iam_binding" "default" {
for_each = toset(var.iam_roles)
project = var.project_id
repository = google_sourcerepo_repository.default.name
role = each.value
members = lookup(var.iam_members, each.value, [])
depends_on = [
google_sourcerepo_repository.default
]
}

View File

@ -0,0 +1,25 @@
/**
* 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.
*/
output "id" {
description = "Repository id."
value = google_sourcerepo_repository.default.id
}
output "url" {
description = "Repository URL."
value = google_sourcerepo_repository.default.url
}

View File

@ -0,0 +1,37 @@
/**
* 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" {
description = "Project used for resources."
type = string
}
variable "iam_members" {
description = "IAM members for each topic role."
type = map(list(string))
default = {}
}
variable "iam_roles" {
description = "IAM roles for topic."
type = list(string)
default = []
}
variable "name" {
description = "Repository topic name."
type = string
}

View File

@ -0,0 +1,19 @@
/**
* 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.
*/
terraform {
required_version = ">= 0.12.6"
}