Skip to content

Commit

Permalink
Migrate to Cloud Functions v2
Browse files Browse the repository at this point in the history
  • Loading branch information
ruchernchong committed Jul 6, 2024
1 parent 56ed8be commit 6d717c2
Showing 1 changed file with 38 additions and 17 deletions.
55 changes: 38 additions & 17 deletions __main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,31 +32,52 @@ def create_zip(files_to_zip):
"archive", bucket=bucket.name, source=pulumi.FileAsset(zip_path)
)

function = gcp.cloudfunctions.Function(

function = gcp.cloudfunctionsv2.Function(
"function",
name=f"{PROJECT_NAME}-function",
region="asia-southeast1",
name=f"{PROJECT_NAME}-function-v2",
location="asia-southeast1",
description="Telegram Bot for calculating the OLED black pixels percentage from images",
runtime="python312",
available_memory_mb=256,
source_archive_bucket=bucket.name,
source_archive_object=archive.name,
trigger_http=True,
https_trigger_security_level="SECURE_ALWAYS",
entry_point="main",
environment_variables={
"TELEGRAM_BOT_TOKEN": TELEGRAM_BOT_TOKEN,
},
build_config=gcp.cloudfunctionsv2.FunctionBuildConfigArgs(
runtime="python312",
entry_point="main",
environment_variables={
"TELEGRAM_BOT_TOKEN": TELEGRAM_BOT_TOKEN,
},
source=gcp.cloudfunctionsv2.FunctionBuildConfigSourceArgs(
storage_source=gcp.cloudfunctionsv2.FunctionBuildConfigSourceStorageSourceArgs(
bucket=bucket.name, object=archive.name
)
),
),
service_config=gcp.cloudfunctionsv2.FunctionServiceConfigArgs(
max_instance_count=1,
available_memory="256M",
timeout_seconds=60,
environment_variables={
"TELEGRAM_BOT_TOKEN": TELEGRAM_BOT_TOKEN,
},
),
)

invoker = gcp.cloudfunctions.FunctionIamMember(
"invoker",
function_invoker = gcp.cloudfunctionsv2.FunctionIamMember(
"function-invoker",
project=function.project,
region=function.region,
location=function.location,
cloud_function=function.name,
role="roles/cloudfunctions.invoker",
member="allUsers",
)

cloudrun_invoker = gcp.cloudrun.IamMember(
"cloudrun-invoker",
location=function.location,
project=function.project,
service=function.name,
role="roles/run.invoker",
member="allUsers",
)


pulumi.export("bucket_object_name", archive.output_name)
pulumi.export("function_url", function.https_trigger_url)
pulumi.export("function_url", function.service_config.uri)

0 comments on commit 6d717c2

Please sign in to comment.