diff --git a/aws-py-s3-folder/__main__.py b/aws-py-s3-folder/__main__.py index c2703f955..9a124ccdb 100644 --- a/aws-py-s3-folder/__main__.py +++ b/aws-py-s3-folder/__main__.py @@ -5,46 +5,52 @@ from pulumi import FileAsset, Output, export, ResourceOptions from pulumi_aws import s3 -web_bucket = s3.Bucket('s3-website-bucket', - website=s3.BucketWebsiteArgs( - index_document="index.html", - )) +web_bucket = s3.Bucket( + "s3-website-bucket", + website={ + "index_document": "index.html", + }, +) public_access_block = s3.BucketPublicAccessBlock( - 'public-access-block', - bucket=web_bucket.id, - block_public_acls=False) + "public-access-block", bucket=web_bucket.id, block_public_acls=False +) content_dir = "www" for file in os.listdir(content_dir): filepath = os.path.join(content_dir, file) mime_type, _ = mimetypes.guess_type(filepath) - obj = s3.BucketObject(file, - bucket=web_bucket.id, - source=FileAsset(filepath), - content_type=mime_type) + obj = s3.BucketObject( + file, bucket=web_bucket.id, source=FileAsset(filepath), content_type=mime_type + ) + def public_read_policy_for_bucket(bucket_name): - return Output.json_dumps({ - "Version": "2012-10-17", - "Statement": [{ - "Effect": "Allow", - "Principal": "*", - "Action": [ - "s3:GetObject" + return Output.json_dumps( + { + "Version": "2012-10-17", + "Statement": [ + { + "Effect": "Allow", + "Principal": "*", + "Action": ["s3:GetObject"], + "Resource": [ + Output.format("arn:aws:s3:::{0}/*", bucket_name), + ], + } ], - "Resource": [ - Output.format("arn:aws:s3:::{0}/*", bucket_name), - ] - }] - }) + } + ) + bucket_name = web_bucket.id -bucket_policy = s3.BucketPolicy("bucket-policy", +bucket_policy = s3.BucketPolicy( + "bucket-policy", bucket=bucket_name, - policy=public_read_policy_for_bucket(bucket_name), - opts=ResourceOptions(depends_on=[public_access_block])) + policy=public_read_policy_for_bucket(bucket_name), + opts=ResourceOptions(depends_on=[public_access_block]), +) # Export the name of the bucket -export('bucket_name', web_bucket.id) -export('website_url', web_bucket.website_endpoint) +export("bucket_name", web_bucket.id) +export("website_url", web_bucket.website_endpoint) diff --git a/aws-py-webserver/__main__.py b/aws-py-webserver/__main__.py index 37fc44082..e5cb0f5d0 100644 --- a/aws-py-webserver/__main__.py +++ b/aws-py-webserver/__main__.py @@ -8,19 +8,19 @@ ami = aws.ec2.get_ami( most_recent=True, owners=["amazon"], - filters=[aws.ec2.GetAmiFilterArgs(name="name", values=["amzn2-ami-hvm-*"])], + filters=[{"name": "name", "values": ["amzn2-ami-hvm-*"]}], ) group = aws.ec2.SecurityGroup( "web-secgrp", description="Enable HTTP access", ingress=[ - aws.ec2.SecurityGroupIngressArgs( - protocol="tcp", - from_port=80, - to_port=80, - cidr_blocks=["0.0.0.0/0"], - ) + { + "protocol": "tcp", + "from_port": 80, + "to_port": 80, + "cidr_blocks": ["0.0.0.0/0"], + } ], ) diff --git a/kubernetes-py-exposed-deployment/README.md b/kubernetes-py-exposed-deployment/README.md index 03761557a..a7ed24444 100644 --- a/kubernetes-py-exposed-deployment/README.md +++ b/kubernetes-py-exposed-deployment/README.md @@ -74,7 +74,7 @@ case `35.226.79.225`. It is exported with a stack output variable, `frontend_ip` and `grep` to retrieve the `` of the site the proxy points at. > _Note_: minikube does not support type `LoadBalancer`; if you are deploying to minikube, make sure -> to run `kubectl port-forward service/frontend 8080:80` to forward the cluster port to the local +> to run `kubectl port-forward $(kubectl get service -l app=nginx -o name) 8080:80` to forward the cluster port to the local > machine and access the service via `localhost:8080`. ```sh diff --git a/kubernetes-py-exposed-deployment/__main__.py b/kubernetes-py-exposed-deployment/__main__.py index 97d93e6d8..63c348b7d 100644 --- a/kubernetes-py-exposed-deployment/__main__.py +++ b/kubernetes-py-exposed-deployment/__main__.py @@ -1,4 +1,4 @@ -"""Copyright 2016-2019, Pulumi Corporation. All rights reserved.""" +"""Copyright 2016-2024, Pulumi Corporation. All rights reserved.""" import pulumi import pulumi_kubernetes as k8s @@ -9,48 +9,49 @@ """nginx container, replicated 1 time.""" app_name = "nginx" -app_labels = { "app": app_name } +app_labels = {"app": app_name} nginx = k8s.apps.v1.Deployment( - app_name, - spec=k8s.apps.v1.DeploymentSpecArgs( - replicas=1, - selector=k8s.meta.v1.LabelSelectorArgs(match_labels=app_labels), - template=k8s.core.v1.PodTemplateSpecArgs( - metadata=k8s.meta.v1.ObjectMetaArgs(labels=app_labels), - spec=k8s.core.v1.PodSpecArgs( - containers=[ - k8s.core.v1.ContainerArgs( - name=app_name, - image="nginx:1.15-alpine", - ) - ] - ), - ), - ) - ) + app_name, + spec={ + "replicas": 1, + "selector": {"match_labels": app_labels}, + "template": { + "metadata": {"labels": app_labels}, + "spec": { + "containers": [ + { + "name": app_name, + "image": "nginx:1.16-alpine", + } + ] + }, + }, + }, +) """Allocate an IP to the nginx Deployment.""" frontend = k8s.core.v1.Service( - app_name, - metadata=k8s.meta.v1.ObjectMetaArgs( - labels=app_labels), - spec=k8s.core.v1.ServiceSpecArgs( - selector=app_labels, - ports=[ - k8s.core.v1.ServicePortArgs( - port=80, - target_port=80, - protocol="TCP" - ) - ], - type="ClusterIP" if is_minikube == "true" else "LoadBalancer", - ), - ) + app_name, + metadata={"labels": app_labels}, + spec={ + "selector": app_labels, + "ports": [{"port": 80, "target_port": 80, "protocol": "TCP"}], + "type": "ClusterIP" if is_minikube == "true" else "LoadBalancer", + }, +) # """When "done", this will print the public IP.""" if is_minikube == "true": - pulumi.export("frontend_IP", frontend.spec.apply(lambda s: s.cluster_ip)) + pulumi.export("frontend_IP", frontend.spec.apply(lambda s: s.cluster_ip)) else: - pulumi.export("frontend_IP", frontend.status.apply(lambda s: s.load_balancer.ingress[0].ip)) + pulumi.export( + "frontend_IP", + frontend.status.apply( + lambda s: s + and s.load_balancer + and s.load_balancer.ingress + and s.load_balancer.ingress[0].ip + ), + ) diff --git a/kubernetes-py-exposed-deployment/requirements.txt b/kubernetes-py-exposed-deployment/requirements.txt index b408ae4f4..372fc114d 100644 --- a/kubernetes-py-exposed-deployment/requirements.txt +++ b/kubernetes-py-exposed-deployment/requirements.txt @@ -1,2 +1,2 @@ -pulumi>=3.5.1,<4.0.0 -pulumi-kubernetes>=3.4.0,<4.0.0 +pulumi>=3.124.0,<4.0.0 +pulumi-kubernetes>=4.15.0,<5.0.0 diff --git a/kubernetes-py-guestbook/simple/__main__.py b/kubernetes-py-guestbook/simple/__main__.py index 24cffab38..85bc5f776 100644 --- a/kubernetes-py-guestbook/simple/__main__.py +++ b/kubernetes-py-guestbook/simple/__main__.py @@ -1,4 +1,4 @@ -# Copyright 2016-2020, Pulumi Corporation. +# Copyright 2016-2024, Pulumi Corporation. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,15 +15,15 @@ import pulumi from pulumi_kubernetes.apps.v1 import Deployment, DeploymentSpecArgs from pulumi_kubernetes.core.v1 import ( - ContainerArgs, - ContainerPortArgs, - EnvVarArgs, - PodSpecArgs, - PodTemplateSpecArgs, - ResourceRequirementsArgs, - Service, - ServicePortArgs, - ServiceSpecArgs, + ContainerArgs, + ContainerPortArgs, + EnvVarArgs, + PodSpecArgs, + PodTemplateSpecArgs, + ResourceRequirementsArgs, + Service, + ServicePortArgs, + ServiceSpecArgs, ) from pulumi_kubernetes.meta.v1 import LabelSelectorArgs, ObjectMetaArgs @@ -33,167 +33,191 @@ isMinikube = config.get_bool("isMinikube") redis_leader_labels = { - "app": "redis-leader", + "app": "redis-leader", } redis_leader_deployment = Deployment( - "redis-leader", - spec=DeploymentSpecArgs( - selector=LabelSelectorArgs( - match_labels=redis_leader_labels, - ), - replicas=1, - template=PodTemplateSpecArgs( - metadata=ObjectMetaArgs( - labels=redis_leader_labels, - ), - spec=PodSpecArgs( - containers=[ContainerArgs( - name="redis-leader", - image="redis", - resources=ResourceRequirementsArgs( - requests={ - "cpu": "100m", - "memory": "100Mi", - }, - ), - ports=[ContainerPortArgs( - container_port=6379, - )], - )], - ), - ), - )) + "redis-leader", + spec={ + "selector": { + "match_labels": redis_leader_labels, + }, + "replicas": 1, + "template": { + "metadata": { + "labels": redis_leader_labels, + }, + "spec": { + "containers": [ + { + "name": "redis-leader", + "image": "redis", + "resources": { + "requests": { + "cpu": "100m", + "memory": "100Mi", + }, + }, + "ports": [ + { + "container_port": 6379, + } + ], + } + ], + }, + }, + }, +) redis_leader_service = Service( - "redis-leader", - metadata=ObjectMetaArgs( - name="redis-leader", - labels=redis_leader_labels - ), - spec=ServiceSpecArgs( - ports=[ServicePortArgs( - port=6379, - target_port=6379, - )], - selector=redis_leader_labels - )) + "redis-leader", + metadata={"name": "redis-leader", "labels": redis_leader_labels}, + spec={ + "ports": [ + { + "port": 6379, + "target_port": 6379, + } + ], + "selector": redis_leader_labels, + }, +) redis_replica_labels = { - "app": "redis-replica", + "app": "redis-replica", } redis_replica_deployment = Deployment( - "redis-replica", - spec=DeploymentSpecArgs( - selector=LabelSelectorArgs( - match_labels=redis_replica_labels - ), - replicas=1, - template=PodTemplateSpecArgs( - metadata=ObjectMetaArgs( - labels=redis_replica_labels, - ), - spec=PodSpecArgs( - containers=[ContainerArgs( - name="redis-replica", - image="pulumi/guestbook-redis-replica", - resources=ResourceRequirementsArgs( - requests={ - "cpu": "100m", - "memory": "100Mi", - }, - ), - env=[EnvVarArgs( - name="GET_HOSTS_FROM", - value="dns", - # If your cluster config does not include a dns service, then to instead access an environment - # variable to find the leader's host, comment out the 'value: dns' line above, and - # uncomment the line below: - # value: "env" - )], - ports=[ContainerPortArgs( - container_port=6379, - )], - )], - ), - ), - )) + "redis-replica", + spec={ + "selector": {"match_labels": redis_replica_labels}, + "replicas": 1, + "template": { + "metadata": { + "labels": redis_replica_labels, + }, + "spec": { + "containers": [ + { + "name": "redis-replica", + "image": "pulumi/guestbook-redis-replica", + "resources": { + "requests": { + "cpu": "100m", + "memory": "100Mi", + }, + }, + "env": [ + { + "name": "GET_HOSTS_FROM", + "value": "dns", + # If your cluster config does not include a dns service, then to instead access an environment + # variable to find the leader's host, comment out the 'value: dns' line above, and + # uncomment the line below: + # value: "env" + } + ], + "ports": [ + { + "container_port": 6379, + } + ], + } + ], + }, + }, + }, +) redis_replica_service = Service( - "redis-replica", - metadata=ObjectMetaArgs( - name="redis-replica", - labels=redis_replica_labels - ), - spec=ServiceSpecArgs( - ports=[ServicePortArgs( - port=6379, - target_port=6379, - )], - selector=redis_replica_labels - )) + "redis-replica", + metadata=ObjectMetaArgs(name="redis-replica", labels=redis_replica_labels), + spec=ServiceSpecArgs( + ports=[ + ServicePortArgs( + port=6379, + target_port=6379, + ) + ], + selector=redis_replica_labels, + ), +) # Frontend frontend_labels = { - "app": "frontend", + "app": "frontend", } frontend_deployment = Deployment( - "frontend", - spec=DeploymentSpecArgs( - selector=LabelSelectorArgs( - match_labels=frontend_labels, - ), - replicas=3, - template=PodTemplateSpecArgs( - metadata=ObjectMetaArgs( - labels=frontend_labels, - ), - spec=PodSpecArgs( - containers=[ContainerArgs( - name="php-redis", - image="pulumi/guestbook-php-redis", - resources=ResourceRequirementsArgs( - requests={ - "cpu": "100m", - "memory": "100Mi", - }, - ), - env=[EnvVarArgs( - name="GET_HOSTS_FROM", - value="dns", - # If your cluster config does not include a dns service, then to instead access an environment - # variable to find the leader's host, comment out the 'value: dns' line above, and - # uncomment the line below: - # "value": "env" - )], - ports=[ContainerPortArgs( - container_port=80, - )], - )], - ), - ), - )) + "frontend", + spec=DeploymentSpecArgs( + selector=LabelSelectorArgs( + match_labels=frontend_labels, + ), + replicas=3, + template=PodTemplateSpecArgs( + metadata=ObjectMetaArgs( + labels=frontend_labels, + ), + spec=PodSpecArgs( + containers=[ + ContainerArgs( + name="php-redis", + image="pulumi/guestbook-php-redis", + resources=ResourceRequirementsArgs( + requests={ + "cpu": "100m", + "memory": "100Mi", + }, + ), + env=[ + EnvVarArgs( + name="GET_HOSTS_FROM", + value="dns", + # If your cluster config does not include a dns service, then to instead access an environment + # variable to find the leader's host, comment out the 'value: dns' line above, and + # uncomment the line below: + # "value": "env" + ) + ], + ports=[ + ContainerPortArgs( + container_port=80, + ) + ], + ) + ], + ), + ), + ), +) frontend_service = Service( - "frontend", - metadata=ObjectMetaArgs( - name="frontend", - labels=frontend_labels, - ), - spec=ServiceSpecArgs( - type="ClusterIP" if isMinikube else "LoadBalancer", - ports=[ServicePortArgs( - port=80 - )], - selector=frontend_labels, - )) + "frontend", + metadata={ + "name": "frontend", + "labels": frontend_labels, + }, + spec={ + "type": "ClusterIP" if isMinikube else "LoadBalancer", + "ports": [{"port": 80}], + "selector": frontend_labels, + }, +) frontend_ip = "" if isMinikube: - frontend_ip = frontend_service.spec.apply(lambda spec: spec.cluster_ip or "") + frontend_ip = frontend_service.spec.apply(lambda spec: spec.cluster_ip or "") else: - ingress = frontend_service.status.apply(lambda status: status.load_balancer.ingress[0]) - frontend_ip = ingress.apply(lambda ingress: ingress.ip or ingress.hostname or "") + ingress = frontend_service.status.apply( + lambda status: ( + status.load_balancer.ingress[0] + if status and status.load_balancer and status.load_balancer.ingress + else None + ) + ) + frontend_ip = ingress.apply( + lambda ingress: ingress and (ingress.ip or ingress.hostname) or "" + ) pulumi.export("frontend_ip", frontend_ip) diff --git a/kubernetes-py-guestbook/simple/requirements.txt b/kubernetes-py-guestbook/simple/requirements.txt index b408ae4f4..372fc114d 100644 --- a/kubernetes-py-guestbook/simple/requirements.txt +++ b/kubernetes-py-guestbook/simple/requirements.txt @@ -1,2 +1,2 @@ -pulumi>=3.5.1,<4.0.0 -pulumi-kubernetes>=3.4.0,<4.0.0 +pulumi>=3.124.0,<4.0.0 +pulumi-kubernetes>=4.15.0,<5.0.0