Organization policies in GCP - Time & Space Complexity
Start learning this pattern below
Jump into concepts and practice - no test required
When applying organization policies in GCP, it's important to understand how the time to enforce these policies changes as you add more projects or resources.
We want to know how the number of policy checks or API calls grows when managing many resources.
Analyze the time complexity of the following operation sequence.
# Apply an organization policy to multiple projects
for project in projects_list:
gcloud org-policies set-policy \
--project=$project \
--policy=policy.yaml
This sequence applies the same organization policy to each project in a list one by one.
Identify the API calls, resource provisioning, data transfers that repeat.
- Primary operation: Setting the organization policy on each project via API call.
- How many times: Once per project in the list.
Each additional project requires one more API call to set the policy.
| Input Size (n) | Approx. Api Calls/Operations |
|---|---|
| 10 | 10 |
| 100 | 100 |
| 1000 | 1000 |
Pattern observation: The number of API calls grows directly with the number of projects.
Time Complexity: O(n)
This means the time to apply policies increases linearly as you add more projects.
[X] Wrong: "Applying one policy automatically updates all projects instantly without extra calls."
[OK] Correct: Each project requires its own API call to apply the policy, so time grows with the number of projects.
Understanding how operations scale with resource count helps you design efficient cloud management strategies and shows you can think about system behavior as it grows.
"What if we applied the policy at the organization level instead of per project? How would the time complexity change?"
Practice
Organization Policy in Google Cloud?Solution
Step 1: Understand the role of organization policies
Organization policies define rules that apply across all projects and resources in a company to keep them safe and compliant.Step 2: Compare options with the purpose
Only To set rules that apply to all projects in a company describes setting rules across all projects, which matches the purpose of organization policies.Final Answer:
To set rules that apply to all projects in a company -> Option AQuick Check:
Organization policies control rules = A [OK]
- Confusing organization policies with billing or monitoring
- Thinking policies create resources automatically
- Assuming policies manage user accounts directly
Solution
Step 1: Recall YAML syntax for key-value pairs
YAML uses colon (:) to assign values to keys, likekey: value.Step 2: Identify correct constraint syntax
constraint: gcp.resourceLocations usesconstraint: gcp.resourceLocations, which is valid YAML syntax for specifying a constraint.Final Answer:
constraint: gcp.resourceLocations -> Option CQuick Check:
YAML key-value uses colon = C [OK]
- Using equals sign (=) instead of colon (:)
- Using arrows (->) or parentheses incorrectly
- Confusing YAML with programming language syntax
constraint: constraints/compute.disableSerialPortAccess listPolicy: deniedValues: - "true"
What is the effect of this policy?
Solution
Step 1: Understand the constraint meaning
The constraintconstraints/compute.disableSerialPortAccesscontrols serial port access on compute instances ("true" disables access, "false" allows it).Step 2: Interpret the deniedValues list
SettingdeniedValues: ["true"]denies the value "true", which disables serial port access on compute instances.Final Answer:
It denies serial port access on compute instances -> Option DQuick Check:
deny "true" disables access = A [OK]
- Thinking deniedValues means allowed values
- Confusing serial port access with instance shutdown
- Assuming the policy enables the feature
constraint: constraints/compute.disableSerialPortAccess
listPolicy:
deniedValues:
- trueBut it does not work as expected. What is the likely error?
Solution
Step 1: Check the deniedValues data type
Organization policies expect deniedValues as strings, so"true"must be quoted.Step 2: Identify the error cause
Using unquotedtrueis boolean in YAML, causing the policy to fail or behave unexpectedly.Final Answer:
The denied value should be a string "true", not boolean true -> Option BQuick Check:
Denied values must be strings in YAML [OK]
- Not quoting boolean values in YAML
- Assuming constraint names are wrong without checking
- Thinking lists are not allowed under deniedValues
us-central1 and europe-west1. Which organization policy configuration achieves this?Solution
Step 1: Understand the constraint for resource locations
Theconstraints/gcp.resourceLocationscontrols allowed regions for resource creation.Step 2: Identify correct allowedValues format
Allowed values should list region names as strings without prefixes like "in:"; constraint: constraints/gcp.resourceLocations listPolicy: allowedValues: - "us-central1" - "europe-west1" correctly lists"us-central1"and"europe-west1".Step 3: Eliminate incorrect options
The configuration with"in:us-central1"uses invalid prefixes. Configurations usingdeniedValuesdo not restrict to only those regions: one attempts to deny outside the regions (wrong syntax and logic), the other denies the desired regions (allowing others).Final Answer:
constraint: constraints/gcp.resourceLocations listPolicy: allowedValues: - "us-central1" - "europe-west1" -> Option AQuick Check:
AllowedValues list regions as strings without prefixes = D [OK]
- Using prefixes like 'in:' in allowedValues
- Using deniedValues instead of allowedValues
- Misunderstanding constraint syntax for regions
