Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update more python templates to use dictionary literals #828

Merged
merged 1 commit into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions pinecone-python/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
import pulumi
import pinecone_pulumi as pinecone

my_pinecone_index = pinecone.PineconeIndex("myPineconeIndex",
name="example-index-python",
metric=pinecone.IndexMetric.COSINE,
spec=pinecone.PineconeSpecArgs(
serverless=pinecone.PineconeServerlessSpecArgs(
cloud=pinecone.ServerlessSpecCloud.AWS,
region="us-west-2",
),
))
my_pinecone_index = pinecone.PineconeIndex(
"myPineconeIndex",
name="example-index-python",
metric=pinecone.IndexMetric.COSINE,
spec={
"serverless": {
"cloud": pinecone.ServerlessSpecCloud.AWS,
"region": "us-west-2",
},
},
)

pulumi.export("host", my_pinecone_index.host)
42 changes: 21 additions & 21 deletions rediscloud-python/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,25 @@
name="my-subscription",
payment_method="credit-card",
payment_method_id=card.id,
cloud_provider=pulumi_rediscloud.SubscriptionCloudProviderArgs(
regions=[
pulumi_rediscloud.SubscriptionCloudProviderRegionArgs(
region="us-east-1",
multiple_availability_zones=True,
networking_deployment_cidr="10.0.0.0/24",
preferred_availability_zones=["use1-az1", "use1-az2", "use1-az5"],
)
cloud_provider={
"regions": [
{
"region": "us-east-1",
"multiple_availability_zones": True,
"networking_deployment_cidr": "10.0.0.0/24",
"preferred_availability_zones": ["use1-az1", "use1-az2", "use1-az5"],
}
]
),
creation_plan=pulumi_rediscloud.SubscriptionCreationPlanArgs(
memory_limit_in_gb=10,
quantity=1,
replication=True,
support_oss_cluster_api=False,
throughput_measurement_by="operations-per-second",
throughput_measurement_value=20000,
modules=["RedisJSON"],
),
},
creation_plan={
"memory_limit_in_gb": 10,
"quantity": 1,
"replication": True,
"support_oss_cluster_api": False,
"throughput_measurement_by": "operations-per-second",
"throughput_measurement_value": 20000,
"modules": ["RedisJSON"],
},
)

database = pulumi_rediscloud.SubscriptionDatabase(
Expand All @@ -45,8 +45,8 @@
throughput_measurement_value=20000,
replication=True,
modules=[
pulumi_rediscloud.SubscriptionDatabaseModuleArgs(
name="RedisJSON",
)
{
"name": "RedisJSON",
}
],
)
50 changes: 25 additions & 25 deletions serverless-azure-python/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
"account",
resource_group_name=resource_group.name,
kind=azure.storage.Kind.STORAGE_V2,
sku=azure.storage.SkuArgs(
name=azure.storage.SkuName.STANDARD_LRS,
),
sku={
"name": azure.storage.SkuName.STANDARD_LRS,
},
)

# Create a storage container for the pages of the website.
Expand Down Expand Up @@ -85,10 +85,10 @@
resource_group_name=resource_group.name,
kind="Linux",
reserved=True,
sku=azure.web.SkuDescriptionArgs(
name="Y1",
tier="Dynamic",
),
sku={
"name": "Y1",
"tier": "Dynamic",
},
)

# Create the Function App.
Expand All @@ -97,29 +97,29 @@
resource_group_name=resource_group.name,
server_farm_id=plan.id,
kind="FunctionApp",
site_config=azure.web.SiteConfigArgs(
app_settings=[
azure.web.NameValuePairArgs(
name="FUNCTIONS_WORKER_RUNTIME",
value="python",
),
azure.web.NameValuePairArgs(
name="FUNCTIONS_EXTENSION_VERSION",
value="~3",
),
azure.web.NameValuePairArgs(
name="WEBSITE_RUN_FROM_PACKAGE",
value=pulumi.Output.all(
site_config={
"app_settings": [
{
"name": "FUNCTIONS_WORKER_RUNTIME",
"value": "python",
},
{
"name": "FUNCTIONS_EXTENSION_VERSION",
"value": "~3",
},
{
"name": "WEBSITE_RUN_FROM_PACKAGE",
"value": pulumi.Output.all(
account.name, app_container.name, app_blob.name, signature
).apply(
lambda args: f"https://{args[0]}.blob.core.windows.net/{args[1]}/{args[2]}?{args[3]}"
),
),
},
],
cors=azure.web.CorsSettingsArgs(
allowed_origins=["*"],
),
),
"cors": {
"allowed_origins": ["*"],
},
},
)

# Create a JSON configuration file for the website.
Expand Down
70 changes: 28 additions & 42 deletions serverless-gcp-python/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,83 +14,69 @@
# Create a storage bucket and configure it as a website.
site_bucket = gcp.storage.Bucket(
"site-bucket",
gcp.storage.BucketArgs(
location="US",
website=gcp.storage.BucketWebsiteArgs(
main_page_suffix=index_document,
not_found_page=error_document,
),
),
location="US",
website={
"main_page_suffix": index_document,
"not_found_page": error_document,
},
)

# Create an IAM binding to allow public read access to the bucket.
site_bucket_iam_binding = gcp.storage.BucketIAMBinding(
"site-bucket-iam-binding",
gcp.storage.BucketIAMBindingArgs(
bucket=site_bucket.name, role="roles/storage.objectViewer", members=["allUsers"]
),
bucket=site_bucket.name,
role="roles/storage.objectViewer",
members=["allUsers"],
)

# Use a synced folder to manage the files of the website.
synced_folder = synced.GoogleCloudFolder(
"synced-folder",
synced.GoogleCloudFolderArgs(
path=site_path,
bucket_name=site_bucket.name,
),
path=site_path,
bucket_name=site_bucket.name,
)

# Create another storage bucket for the serverless app.
app_bucket = gcp.storage.Bucket(
"app-bucket",
gcp.storage.BucketArgs(
location="US",
),
location="US",
)

# Upload the serverless app to the storage bucket.
app_archive = gcp.storage.BucketObject(
"app-archive",
gcp.storage.BucketObjectArgs(
bucket=app_bucket.name,
source=pulumi.asset.FileArchive(app_path),
),
bucket=app_bucket.name,
source=pulumi.asset.FileArchive(app_path),
)

# Create a Cloud Function that returns some data.
data_function = gcp.cloudfunctions.Function(
"data-function",
gcp.cloudfunctions.FunctionArgs(
source_archive_bucket=app_bucket.name,
source_archive_object=app_archive.name,
runtime="python310",
entry_point="data",
trigger_http=True,
),
source_archive_bucket=app_bucket.name,
source_archive_object=app_archive.name,
runtime="python310",
entry_point="data",
trigger_http=True,
)

# Create an IAM member to invoke the function.
invoker = gcp.cloudfunctions.FunctionIamMember(
"data-function-invoker",
gcp.cloudfunctions.FunctionIamMemberArgs(
project=data_function.project,
region=data_function.region,
cloud_function=data_function.name,
role="roles/cloudfunctions.invoker",
member="allUsers",
),
project=data_function.project,
region=data_function.region,
cloud_function=data_function.name,
role="roles/cloudfunctions.invoker",
member="allUsers",
)

# Create a JSON configuration file for the website.
site_config = gcp.storage.BucketObject(
"site-config",
gcp.storage.BucketObjectArgs(
name="config.json",
bucket=site_bucket.name,
content_type="application/json",
source=data_function.https_trigger_url.apply(
lambda url: pulumi.StringAsset('{ "api": "' + url + '" }')
),
name="config.json",
bucket=site_bucket.name,
content_type="application/json",
source=data_function.https_trigger_url.apply(
lambda url: pulumi.StringAsset('{ "api": "' + url + '" }')
),
)

Expand Down
Loading