in reference-architectures/automated-password-rotation/terraform/code/main.py [0:0]
def get_project_id():
"""Function to fetch project id.
Args:
None.
Returns:
project_id: Id of the project
"""
metadata_base_url = "http://metadata.google.internal/computeMetadata/v1/"
project_id_path = "project/project-id"
url = metadata_base_url + project_id_path
req = urllib.request.Request(url)
req.add_header("Metadata-Flavor", "Google")
project_id = urllib.request.urlopen(req).read().decode()
return project_id