-
Notifications
You must be signed in to change notification settings - Fork 910
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added secure-source-manager-instance module * Fixes after review
- Loading branch information
Showing
15 changed files
with
762 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,179 @@ | ||
# Secure Source Manager | ||
|
||
This module allows to create a Secure Source Manager instance and repositories in it. Additionally it allows creating instance IAM bindings and repository IAM bindings. | ||
|
||
## Examples | ||
|
||
<!-- BEGIN TOC --> | ||
- [Examples](#examples) | ||
- [Public instance](#public-instance) | ||
- [Public instance with CMEK](#public-instance-with-cmek) | ||
- [Private instance](#private-instance) | ||
- [IAM](#iam) | ||
- [Variables](#variables) | ||
- [Outputs](#outputs) | ||
<!-- END TOC --> | ||
|
||
### Public instance | ||
|
||
```hcl | ||
module "ssm_instance" { | ||
source = "./fabric/modules/secure-source-manager-instance" | ||
project_id = var.project_id | ||
instance_id = "my-instance" | ||
location = var.region | ||
repositories = { | ||
my-repository = { | ||
location = var.region | ||
} | ||
} | ||
} | ||
# tftest modules=1 resources=2 inventory=public-instance.yaml | ||
``` | ||
|
||
### Public instance with CMEK | ||
|
||
```hcl | ||
module "ssm_instance" { | ||
source = "./fabric/modules/secure-source-manager-instance" | ||
project_id = var.project_id | ||
instance_id = "my-instance" | ||
location = var.region | ||
kms_key = "projects/another-project-id/locations/${var.region}/keyRings/my-key-ring/cryptoKeys/my-key" | ||
repositories = { | ||
my-repository = { | ||
location = var.region | ||
} | ||
} | ||
} | ||
# tftest modules=1 resources=2 inventory=public-instance-with-cmek.yaml | ||
``` | ||
|
||
### Private instance | ||
|
||
```hcl | ||
module "ssm_instance" { | ||
source = "./fabric/modules/secure-source-manager-instance" | ||
project_id = var.project_id | ||
instance_id = "my-instance" | ||
location = var.region | ||
ca_pool = "projects/another-project/locations/${var.region}/caPools/my-ca-pool" | ||
repositories = { | ||
my-repository = { | ||
location = var.region | ||
} | ||
} | ||
} | ||
# tftest modules=1 resources=2 inventory=private-instance.yaml | ||
``` | ||
|
||
### IAM | ||
|
||
```hcl | ||
module "ssm_instance" { | ||
source = "./fabric/modules/secure-source-manager-instance" | ||
project_id = var.project_id | ||
instance_id = "my-instance" | ||
location = var.region | ||
iam = { | ||
"roles/securesourcemanager.instanceOwner" = [ | ||
"group:[email protected]" | ||
] | ||
} | ||
repositories = { | ||
my-repository = { | ||
location = var.region | ||
iam = { | ||
"roles/securesourcemanager.repoAdmin" = [ | ||
"group:[email protected]" | ||
] | ||
} | ||
} | ||
} | ||
} | ||
# tftest modules=1 resources=4 inventory=iam.yaml | ||
``` | ||
|
||
```hcl | ||
module "ssm_instance" { | ||
source = "./fabric/modules/secure-source-manager-instance" | ||
project_id = var.project_id | ||
instance_id = "my-instance" | ||
location = var.region | ||
iam_bindings_additive = { | ||
my-instance-admin = { | ||
role = "roles/securesourcemanager.instanceOwner" | ||
member = "group:[email protected]" | ||
} | ||
} | ||
repositories = { | ||
my-repository = { | ||
location = var.region | ||
iam_bindings_additive = { | ||
my-repository-admin = { | ||
role = "roles/securesourcemanager.repoAdmin" | ||
member = "group:[email protected]" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
# tftest modules=1 resources=4 inventory=iam-bindings.yaml | ||
``` | ||
|
||
```hcl | ||
module "ssm_instance" { | ||
source = "./fabric/modules/secure-source-manager-instance" | ||
project_id = var.project_id | ||
instance_id = "my-instance" | ||
location = var.region | ||
iam_bindings = { | ||
my-instance-admin = { | ||
role = "roles/securesourcemanager.instanceOwner" | ||
members = [ | ||
"group:[email protected]" | ||
] | ||
} | ||
} | ||
repositories = { | ||
my-repository = { | ||
location = var.region | ||
iam_bindings = { | ||
my-repository-admin = { | ||
role = "roles/securesourcemanager.repoAdmin" | ||
members = [ | ||
"group:[email protected]" | ||
] | ||
} | ||
} | ||
} | ||
} | ||
} | ||
# tftest modules=1 resources=4 inventory=iam-bindings-additive.yaml | ||
``` | ||
<!-- BEGIN TFDOC --> | ||
## Variables | ||
|
||
| name | description | type | required | default | | ||
|---|---|:---:|:---:|:---:| | ||
| [instance_id](variables.tf#L23) | Instance ID. | <code>string</code> | ✓ | | | ||
| [location](variables.tf#L40) | Location. | <code>string</code> | ✓ | | | ||
| [project_id](variables.tf#L45) | Project ID. | <code>string</code> | ✓ | | | ||
| [repositories](variables.tf#L50) | Repositories. | <code title="map(object({ description = optional(string) iam = optional(map(list(string)), {}) iam_bindings = optional(map(object({ role = string members = list(string) })), {}) iam_bindings_additive = optional(map(object({ role = string member = string })), {}) initial_config = optional(object({ default_branch = optional(string) gitignores = optional(string) license = optional(string) readme = optional(string) })) location = string }))">map(object({…}))</code> | ✓ | | | ||
| [ca_pool](variables.tf#L17) | CA pool. | <code>string</code> | | <code>null</code> | | ||
| [iam](variables-iam.tf#L17) | IAM bindings. | <code>map(list(string))</code> | | <code>{}</code> | | ||
| [iam_bindings](variables-iam.tf#L23) | IAM bindings. | <code title="map(object({ role = string members = list(string) }))">map(object({…}))</code> | | <code>{}</code> | | ||
| [iam_bindings_additive](variables-iam.tf#L32) | IAM bindings. | <code title="map(object({ role = string member = string }))">map(object({…}))</code> | | <code>{}</code> | | ||
| [kms_key](variables.tf#L28) | KMS key. | <code>string</code> | | <code>null</code> | | ||
| [labels](variables.tf#L34) | Instance labels. | <code>map(string)</code> | | <code>{}</code> | | ||
|
||
## Outputs | ||
|
||
| name | description | sensitive | | ||
|---|---|:---:| | ||
| [instance](outputs.tf#L17) | Instance. | | | ||
| [instance_id](outputs.tf#L22) | Instance id. | | | ||
| [repositories](outputs.tf#L27) | Repositories. | | | ||
| [repository_ids](outputs.tf#L32) | Repository ids. | | | ||
<!-- END TFDOC --> |
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,80 @@ | ||
/** | ||
* Copyright 2024 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 { | ||
repository_iam = merge([for k1, v1 in var.repositories : { for k2, v2 in v1.iam : | ||
"${k1}.${k2}" => { | ||
repository = k1 | ||
role = k2 | ||
members = v2 | ||
} }]...) | ||
repository_iam_bindings = merge([for k1, v1 in var.repositories : { for k2, v2 in v1.iam_bindings : | ||
"${k1}.${k2}" => merge(v2, { | ||
repository = k1 | ||
}) }]...) | ||
repository_iam_bindings_additive = merge([for k1, v1 in var.repositories : { for k2, v2 in v1.iam_bindings_additive : | ||
"${k1}.${k2}" => merge(v2, { | ||
repository = k1 | ||
}) }]...) | ||
} | ||
|
||
resource "google_secure_source_manager_instance_iam_binding" "authoritative" { | ||
for_each = var.iam | ||
project = google_secure_source_manager_instance.instance.project | ||
instance_id = google_secure_source_manager_instance.instance.instance_id | ||
role = each.key | ||
members = each.value | ||
} | ||
|
||
resource "google_secure_source_manager_instance_iam_binding" "bindings" { | ||
for_each = var.iam_bindings | ||
project = google_secure_source_manager_instance.instance.project | ||
instance_id = google_secure_source_manager_instance.instance.instance_id | ||
role = each.value.role | ||
members = each.value.members | ||
} | ||
|
||
resource "google_secure_source_manager_instance_iam_member" "bindings" { | ||
for_each = var.iam_bindings_additive | ||
project = google_secure_source_manager_instance.instance.project | ||
instance_id = google_secure_source_manager_instance.instance.instance_id | ||
role = each.value.role | ||
member = each.value.member | ||
} | ||
|
||
resource "google_secure_source_manager_repository_iam_binding" "authoritative" { | ||
for_each = local.repository_iam | ||
project = google_secure_source_manager_repository.repositories[each.value.repository].project | ||
repository_id = google_secure_source_manager_repository.repositories[each.value.repository].repository_id | ||
role = each.value.role | ||
members = each.value.members | ||
} | ||
|
||
resource "google_secure_source_manager_repository_iam_binding" "bindings" { | ||
for_each = local.repository_iam_bindings | ||
project = google_secure_source_manager_repository.repositories[each.value.repository].project | ||
repository_id = google_secure_source_manager_repository.repositories[each.value.repository].repository_id | ||
role = each.value.role | ||
members = each.value.members | ||
} | ||
|
||
resource "google_secure_source_manager_repository_iam_member" "bindings" { | ||
for_each = local.repository_iam_bindings_additive | ||
project = google_secure_source_manager_repository.repositories[each.value.repository].project | ||
repository_id = google_secure_source_manager_repository.repositories[each.value.repository].repository_id | ||
role = each.value.role | ||
member = each.value.member | ||
} |
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,47 @@ | ||
/** | ||
* Copyright 2024 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_secure_source_manager_instance" "instance" { | ||
instance_id = var.instance_id | ||
project = var.project_id | ||
location = var.location | ||
labels = var.labels | ||
kms_key = var.kms_key | ||
dynamic "private_config" { | ||
for_each = var.ca_pool == null ? [] : [""] | ||
content { | ||
is_private = true | ||
ca_pool = var.ca_pool | ||
} | ||
} | ||
} | ||
|
||
resource "google_secure_source_manager_repository" "repositories" { | ||
for_each = var.repositories | ||
repository_id = each.key | ||
instance = google_secure_source_manager_instance.instance.name | ||
project = var.project_id | ||
location = each.value.location | ||
dynamic "initial_config" { | ||
for_each = each.value.initial_config == null ? [] : [""] | ||
content { | ||
default_branch = each.value.initial_config.default_branch | ||
gitignores = each.value.initial_config.gitignores | ||
license = each.value.initial_config.license | ||
readme = each.value.initial_config.readme | ||
} | ||
} | ||
} |
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,35 @@ | ||
/** | ||
* Copyright 2024 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 "instance" { | ||
description = "Instance." | ||
value = google_secure_source_manager_instance.instance | ||
} | ||
|
||
output "instance_id" { | ||
description = "Instance id." | ||
value = google_secure_source_manager_instance.instance.id | ||
} | ||
|
||
output "repositories" { | ||
description = "Repositories." | ||
value = google_secure_source_manager_repository.repositories | ||
} | ||
|
||
output "repository_ids" { | ||
description = "Repository ids." | ||
value = { for k, v in google_secure_source_manager_repository.repositories : k => v.id } | ||
} |
Oops, something went wrong.