Skip to content Skip to sidebar Skip to footer

Working With Securitypolicies In The Compute Engine Api In Python

I want to use the securityPolicies API for the Google Cloud Platform in Linux in a script written in Python. To do this: I installed google-api-python-client: pip install google-a

Solution 1:

You're missing the .execute() at the end of your addRule method

So your code should look like this:

from googleapiclient import discovery
compute_service = discovery.build('compute', 'v1')
security_policies = compute_service.securityPolicies()
security_policies.addRule(
    project='existed_project_name',
    securityPolicy='existed_security_policy_name',
    body={
        'kind': 'compute#securityPolicyRule',
        'priority': 303,
        'action': 'deny(403)',
        'preview': False,
        'match': {
            'config': {
                'srcIpRanges': [
                    '192.0.2.0/24',
                    '198.51.100.0/24',
                    '203.0.113.0/24'
                ]
            },
            'versionedExpr': 'SRC_IPS_V1'
        }
    }
).execute()

Post a Comment for "Working With Securitypolicies In The Compute Engine Api In Python"