Skip to content

Commit

Permalink
Merge pull request #829 from pulumi/julienp/dict-literals
Browse files Browse the repository at this point in the history
Update more python templates to use dictionary literals
  • Loading branch information
julienp authored Sep 6, 2024
2 parents 170e2b3 + 5b8b332 commit d192647
Show file tree
Hide file tree
Showing 7 changed files with 263 additions and 237 deletions.
16 changes: 13 additions & 3 deletions .github/workflows/test-templates.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ jobs:
id-token: write

steps:
- name: Free Disk Space (Ubuntu)
- if: contains(matrix.platform, 'ubuntu')
name: Free Disk Space (Ubuntu)
uses: jlumbroso/[email protected]
with:
tool-cache: false
Expand Down Expand Up @@ -167,12 +168,21 @@ jobs:
TESTPARALLELISM: 3
SKIPPED_TESTS: "alicloud,digitalocean,kubernetes,openstack,equinix-metal,civo,aiven,auth0,github,oci,java-jbang,java-gradle,azuredevops,container,vm-azure,fsharp,gcp-visualbasic,azure-classic-visualbasic"

- if: contains(matrix.platform, 'macOS') || contains(matrix.platform, 'ubuntu')
name: Run non-Windows tests
- if: contains(matrix.platform, 'ubuntu')
name: Run Linux tests
run: |
set -euo pipefail
cd tests && go test -v -json -count=1 -cover -timeout 6h -parallel ${{ env.TESTPARALLELISM }} . 2>&1 | gotestfmt
- if: contains(matrix.platform, 'macOS')
name: Run macOS tests
run: |
set -euo pipefail
cd tests && go test -v -json -count=1 -cover -timeout 6h -parallel ${{ env.TESTPARALLELISM }} . 2>&1 | gotestfmt
env:
TESTPARALLELISM: 6


- if: 'failure()'
name: Notify Slack
uses: 8398a7/action-slack@v3
Expand Down
95 changes: 46 additions & 49 deletions static-website-aws-python/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@
# Create an S3 bucket and configure it as a website.
bucket = aws.s3.Bucket(
"bucket",
website=aws.s3.BucketWebsiteArgs(
index_document=index_document,
error_document=error_document,
),
website={
"index_document": index_document,
"error_document": error_document,
},
)

# Set ownership controls for the new bucket
ownership_controls = aws.s3.BucketOwnershipControls(
"ownership-controls",
bucket=bucket.bucket,
rule=aws.s3.BucketOwnershipControlsRuleArgs(
object_ownership="ObjectWriter",
)
rule={
"object_ownership": "ObjectWriter",
},
)

# Configure public ACL block on the new bucket
Expand All @@ -39,67 +39,64 @@
acl="public-read",
bucket_name=bucket.bucket,
path=path,
opts=pulumi.ResourceOptions(depends_on=[
ownership_controls,
public_access_block
])
opts=pulumi.ResourceOptions(depends_on=[ownership_controls, public_access_block]),
)

# Create a CloudFront CDN to distribute and cache the website.
cdn = aws.cloudfront.Distribution(
"cdn",
enabled=True,
origins=[
aws.cloudfront.DistributionOriginArgs(
origin_id=bucket.arn,
domain_name=bucket.website_endpoint,
custom_origin_config=aws.cloudfront.DistributionOriginCustomOriginConfigArgs(
origin_protocol_policy="http-only",
http_port=80,
https_port=443,
origin_ssl_protocols=["TLSv1.2"],
),
)
{
"origin_id": bucket.arn,
"domain_name": bucket.website_endpoint,
"custom_origin_config": {
"origin_protocol_policy": "http-only",
"http_port": 80,
"https_port": 443,
"origin_ssl_protocols": ["TLSv1.2"],
},
}
],
default_cache_behavior=aws.cloudfront.DistributionDefaultCacheBehaviorArgs(
target_origin_id=bucket.arn,
viewer_protocol_policy="redirect-to-https",
allowed_methods=[
default_cache_behavior={
"target_origin_id": bucket.arn,
"viewer_protocol_policy": "redirect-to-https",
"allowed_methods": [
"GET",
"HEAD",
"OPTIONS",
],
cached_methods=[
"cached_methods": [
"GET",
"HEAD",
"OPTIONS",
],
default_ttl=600,
max_ttl=600,
min_ttl=600,
forwarded_values=aws.cloudfront.DistributionDefaultCacheBehaviorForwardedValuesArgs(
query_string=True,
cookies=aws.cloudfront.DistributionDefaultCacheBehaviorForwardedValuesCookiesArgs(
forward="all",
),
),
),
"default_ttl": 600,
"max_ttl": 600,
"min_ttl": 600,
"forwarded_values": {
"query_string": True,
"cookies": {
"forward": "all",
},
},
},
price_class="PriceClass_100",
custom_error_responses=[
aws.cloudfront.DistributionCustomErrorResponseArgs(
error_code=404,
response_code=404,
response_page_path=f"/{error_document}",
)
{
"error_code": 404,
"response_code": 404,
"response_page_path": f"/{error_document}",
}
],
restrictions=aws.cloudfront.DistributionRestrictionsArgs(
geo_restriction=aws.cloudfront.DistributionRestrictionsGeoRestrictionArgs(
restriction_type="none",
),
),
viewer_certificate=aws.cloudfront.DistributionViewerCertificateArgs(
cloudfront_default_certificate=True,
),
restrictions={
"geo_restriction": {
"restriction_type": "none",
},
},
viewer_certificate={
"cloudfront_default_certificate": True,
},
)

# Export the URLs and hostnames of the bucket and distribution.
Expand Down
20 changes: 10 additions & 10 deletions static-website-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="StorageV2",
sku=azure_native.storage.SkuArgs(
name="Standard_LRS",
),
sku={
"name": "Standard_LRS",
},
)

# Configure the storage account as a website.
Expand All @@ -44,9 +44,9 @@
profile = azure_native.cdn.Profile(
"profile",
resource_group_name=resource_group.name,
sku=azure_native.cdn.SkuArgs(
name="Standard_Microsoft",
),
sku={
"name": "Standard_Microsoft",
},
)

# Pull the hostname out of the storage-account endpoint.
Expand All @@ -73,10 +73,10 @@
],
origin_host_header=origin_hostname,
origins=[
azure_native.cdn.DeepCreatedOriginArgs(
name=account.name,
host_name=origin_hostname,
)
{
"name": account.name,
"host_name": origin_hostname,
}
],
)

Expand Down
8 changes: 4 additions & 4 deletions static-website-gcp-python/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
bucket = gcp.storage.Bucket(
"bucket",
location="US",
website=gcp.storage.BucketWebsiteArgs(
main_page_suffix=index_document,
not_found_page=error_document,
),
website={
"main_page_suffix": index_document,
"not_found_page": error_document,
},
)

# Create an IAM binding to allow public read access to the bucket.
Expand Down
85 changes: 51 additions & 34 deletions vm-aws-python/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,16 @@
vpc_network_cidr = "10.0.0.0/16"

# Look up the latest Amazon Linux 2 AMI.
ami = aws.ec2.get_ami(filters=[aws.ec2.GetAmiFilterArgs(
name="name",
values=["amzn2-ami-hvm-*"],
)],
ami = aws.ec2.get_ami(
filters=[
{
"name": "name",
"values": ["amzn2-ami-hvm-*"],
}
],
owners=["amazon"],
most_recent=True).id
most_recent=True,
).id

# User data to start a HTTP server in the EC2 instance
user_data = """#!/bin/bash
Expand All @@ -25,61 +29,74 @@
"""

# Create VPC.
vpc = aws.ec2.Vpc("vpc",
vpc = aws.ec2.Vpc(
"vpc",
cidr_block=vpc_network_cidr,
enable_dns_hostnames=True,
enable_dns_support=True)
enable_dns_support=True,
)

# Create an internet gateway.
gateway = aws.ec2.InternetGateway("gateway", vpc_id=vpc.id)

# Create a subnet that automatically assigns new instances a public IP address.
subnet = aws.ec2.Subnet("subnet",
vpc_id=vpc.id,
cidr_block="10.0.1.0/24",
map_public_ip_on_launch=True)
subnet = aws.ec2.Subnet(
"subnet", vpc_id=vpc.id, cidr_block="10.0.1.0/24", map_public_ip_on_launch=True
)

# Create a route table.
route_table = aws.ec2.RouteTable("routeTable",
route_table = aws.ec2.RouteTable(
"routeTable",
vpc_id=vpc.id,
routes=[aws.ec2.RouteTableRouteArgs(
cidr_block="0.0.0.0/0",
gateway_id=gateway.id,
)])
routes=[
{
"cidr_block": "0.0.0.0/0",
"gateway_id": gateway.id,
}
],
)

# Associate the route table with the public subnet.
route_table_association = aws.ec2.RouteTableAssociation("routeTableAssociation",
subnet_id=subnet.id,
route_table_id=route_table.id)
route_table_association = aws.ec2.RouteTableAssociation(
"routeTableAssociation", subnet_id=subnet.id, route_table_id=route_table.id
)

# Create a security group allowing inbound access over port 80 and outbound
# access to anywhere.
sec_group = aws.ec2.SecurityGroup("secGroup",
sec_group = aws.ec2.SecurityGroup(
"secGroup",
description="Enable HTTP access",
vpc_id=vpc.id,
ingress=[aws.ec2.SecurityGroupIngressArgs(
from_port=80,
to_port=80,
protocol="tcp",
cidr_blocks=["0.0.0.0/0"],
)],
egress=[aws.ec2.SecurityGroupEgressArgs(
from_port=0,
to_port=0,
protocol="-1",
cidr_blocks=["0.0.0.0/0"],
)])
ingress=[
{
"from_port": 80,
"to_port": 80,
"protocol": "tcp",
"cidr_blocks": ["0.0.0.0/0"],
}
],
egress=[
{
"from_port": 0,
"to_port": 0,
"protocol": "-1",
"cidr_blocks": ["0.0.0.0/0"],
}
],
)

# Create and launch an EC2 instance into the public subnet.
server = aws.ec2.Instance("server",
server = aws.ec2.Instance(
"server",
instance_type=instance_type,
subnet_id=subnet.id,
vpc_security_group_ids=[sec_group.id],
user_data=user_data,
ami=ami,
tags={
"Name": "webserver",
})
},
)

# Export the instance's publicly accessible IP address and hostname.
pulumi.export("ip", server.public_ip)
Expand Down
Loading

0 comments on commit d192647

Please sign in to comment.