Skip to content

Commit

Permalink
Merge pull request #828 from pulumi/julienp/typeddicts-more
Browse files Browse the repository at this point in the history
Update more python templates to use dictionary literals
  • Loading branch information
julienp authored Aug 28, 2024
2 parents 3faa2b5 + 30b2c7f commit e5bd1c3
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 97 deletions.
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

0 comments on commit e5bd1c3

Please sign in to comment.