updated terraform

pull/1/head
Thomas Martin 2024-11-26 08:36:54 +01:00
parent d06b164e5e
commit 6d4eff5f1d
3 changed files with 31 additions and 3 deletions

View File

@ -1,15 +1,28 @@
import os
from google.cloud import storage
def handle_webhook(request):
request_json = request.get_json()
request_json.get_json('repository').get('clone_url')
repo_url = request_json.get('repo_url')
# Check if the required fields are in the request
if not request_json or "repository" not in request_json:
return "Invalid request: 'repository' field missing", 400
# Extract the 'clone_url' field from the 'repository' object
repo_url = request_json.get("repository", {}).get("clone_url")
if not repo_url:
return "Invalid request: 'clone_url' field missing", 400
if not repo_url:
return "Repository URL not provided", 400
file_path = "/tmp/repo"
if os.path.exists(file_path):
os.remove(file_path)
# Clone the repository
os.system(f"git clone {repo_url} /tmp/repo")
os.system(f"git clone {repo_url} {file_path}")
# Upload to Google Cloud Storage
bucket_name = os.environ.get('BUCKET_NAME')

View File

@ -89,6 +89,20 @@ resource "null_resource" "upload_function_code" {
}
data "google_iam_policy" "admin" {
binding {
role = "roles/cloudfunctions.invoker"
members = [
"allUsers"
]
}
}
resource "google_cloudfunctions_function_iam_policy" "member" {
project = google_cloudfunctions_function.webhook_handler.project
region = google_cloudfunctions_function.webhook_handler.region
cloud_function = google_cloudfunctions_function.webhook_handler.name
policy_data = data.google_iam_policy.admin.policy_data
}
resource "google_cloudfunctions_function" "webhook_handler" {

View File

@ -0,0 +1 @@
google-cloud-storage==2.18.2