Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding option to setup where org-policies will be applied #50

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions modules/secure-cloud-run-security/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,16 @@ module "cloud_run_security" {
|------|-------------|------|---------|:--------:|
| decrypters | List of comma-separated owners for each key declared in set\_decrypters\_for. | `list(string)` | `[]` | no |
| encrypters | List of comma-separated owners for each key declared in set\_encrypters\_for. | `list(string)` | `[]` | no |
| folder\_id | The folder ID to apply the policy to. | `string` | `""` | no |
| key\_name | Key name. | `string` | n/a | yes |
| key\_protection\_level | The protection level to use when creating a version based on this template. Possible values: ["SOFTWARE", "HSM"] | `string` | `"HSM"` | no |
| key\_rotation\_period | Period of key rotation in seconds. | `string` | `"2592000s"` | no |
| keyring\_name | Keyring name. | `string` | n/a | yes |
| kms\_project\_id | The project where KMS will be created. | `string` | n/a | yes |
| location | The location where resources are going to be deployed. | `string` | n/a | yes |
| organization\_id | The organization ID to apply the policy to. | `string` | `""` | no |
| owners | List of comma-separated owners for each key declared in set\_owners\_for. | `list(string)` | `[]` | no |
| policy\_for | Policy Root: set one of the following values to determine where the policy is applied. Possible values: ["project", "folder", "organization"]. | `string` | `"project"` | no |
| prevent\_destroy | Set the prevent\_destroy lifecycle attribute on keys.. | `bool` | `true` | no |
| serverless\_project\_id | The project where Cloud Run is going to be deployed. | `string` | n/a | yes |

Expand Down
18 changes: 14 additions & 4 deletions modules/secure-cloud-run-security/org_policies.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,21 @@
* limitations under the License.
*/

locals {
project = var.policy_for == "project" ? var.serverless_project_id : ""
folder = var.policy_for == "folder" ? var.folder_id : ""
organization = var.policy_for == "organization" ? var.organization_id : ""
}

module "cloudrun_allowed_ingress" {
source = "terraform-google-modules/org-policy/google"
version = "~> 5.1"

policy_for = var.policy_for
project_id = local.project
folder_id = local.folder
organization_id = local.organization
constraint = "constraints/run.allowedIngress"
policy_for = "project"
project_id = var.serverless_project_id
policy_type = "list"
allow = ["is:internal-and-cloud-load-balancing"]
allow_list_length = 1
Expand All @@ -30,8 +38,10 @@ module "cloudrun_allowed_vpc_egress" {
source = "terraform-google-modules/org-policy/google"
version = "~> 5.1"

policy_for = "project"
project_id = var.serverless_project_id
policy_for = var.policy_for
project_id = local.project
folder_id = local.folder
organization_id = local.organization
constraint = "constraints/run.allowedVPCEgress"
policy_type = "list"
allow = ["private-ranges-only"]
Expand Down
18 changes: 18 additions & 0 deletions modules/secure-cloud-run-security/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,21 @@ variable "decrypters" {
type = list(string)
default = []
}

variable "policy_for" {
description = "Policy Root: set one of the following values to determine where the policy is applied. Possible values: [\"project\", \"folder\", \"organization\"]."
type = string
default = "project"
}

variable "folder_id" {
description = "The folder ID to apply the policy to."
type = string
default = ""
}

variable "organization_id" {
description = "The organization ID to apply the policy to."
type = string
default = ""
}