MENU
Contact
Contact

Cloud security policies in GCP: How to set them up using Terraform

Picture of Mateusz Borowski, Cloud Security Engineer

Mateusz Borowski

Cloud Security Engineer
Aug 23, 2023|10 min read
Image Alt
policy-concepts

TODO policy-concepts Source: https://cloud.google.com/resource-manager/img/org-policy-concepts.svg

1module "disableGlobalSerialPortAccess" {
2 source = "terraform-google-modules/org-policy/google"
3 version = "~> 5.2.2"
4 policy_for = "project"
5 project_id = "XXXXXXXXX"
6 constraint = "constraints/compute.disableGlobalSerialPortAccess"
7 policy_type = "boolean"
8 organisation_id = "XXXXXXXXX"
9 enforce = true
10}
1module "restrictTLSVersion" {
2 source = "terraform-google-modules/org-policy/google"
3 version = "~> 5.2.2"
4 policy_for = "project"
5 project_id = "XXXXXXXXX"
6 constraint = "constraints/gcp.restrictTLSVersion"
7 policy_type = "list"
8 organisation_id = "XXXXXXXXX"
9 deny = ["TLS_VERSION_1", "TLS_VERSION_1_1"]
10 deny_list_length = 2
11}
1module "publicAccessPrevention" {
2 source = "terraform-google-modules/org-policy/google"
3 version = "~> 5.2.2"
4 policy_for = "project"
5 project_id = "XXXXXXXXX"
6 constraint = "constraints/storage.publicAccessPrevention"
7 policy_type = "boolean"
8 organisation_id = "XXXXXXXXX"
9 enforce = true
10}
1module "shieldedvm" {
2 source = "terraform-google-modules/org-policy/google"
3 version = "~> 5.2.2"
4 policy_for = "project"
5 project_id = "XXXXXXXXX"
6 constraint = "constraints/compute.requireShieldedVm"
7 policy_type = "boolean"
8 organisation_id = "XXXXXXXXX"
9 enforce = true
10}
1module "serviceaccountskeyrotation"{
2 source = "terraform-google-modules/org-policy/google"
3 version = "~> 5.2.2"
4 policy_for = "project"
5 project_id = "XXXXXXXXX"
6 constraint = "constraints/iam.serviceAccountKeyExpiryHours"
7 policy_type = "list"
8 organisation_id = "XXXXXXXXX"
9 allow = ["2160h"] // 90 days
10 allow_list_length = 1
11}
1# Enable the organisation Policy API
2resource "google_project_service" "orgpolicy_api" {
3 service = "orgpolicy.googleapis.com"
4 project = "XXXXXXXXX"
5}

Curated by Sebastian Synowiec

Subscribe to our newsletter and never miss an article