Skip to content

Commit

Permalink
Add virtualenv option to Python examples (pulumi#885)
Browse files Browse the repository at this point in the history
Use the automatically managed `virtualenv: venv` support in all Python examples.

See https://www.pulumi.com/docs/intro/languages/python/#virtual-environments.

Also update the READMEs to no longer mention needing to manually create the virtual environment. The Pulumi CLI, as of v2.15.1, will automatically create & install dependencies in a virtual environment if the `virtualenv` runtime option is set in `Pulumi.yaml` and the configured directory is empty or doesn't exist.
  • Loading branch information
lukehoban committed Feb 16, 2021
1 parent 327afe3 commit 4343550
Show file tree
Hide file tree
Showing 95 changed files with 237 additions and 579 deletions.
5 changes: 4 additions & 1 deletion aws-django-voting-app/Pulumi.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
name: voting-app
runtime: python
runtime:
name: python
options:
virtualenv: venv
description: Voting app that uses containers
template:
config:
Expand Down
10 changes: 0 additions & 10 deletions aws-django-voting-app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,6 @@ The example shows how easy it is to deploy containers into production and to con
$ pulumi config set django-secret-key <VALUE> --secret
```

1. Create a Python virtualenv, activate it, and install dependencies:

This installs the dependent packages [needed](https://www.pulumi.com/docs/intro/concepts/how-pulumi-works/) for our Pulumi program.

```bash
$ python3 -m venv venv
$ source venv/bin/activate
$ pip3 install -r requirements.txt
```

1. Run `pulumi up -y` to deploy changes:

```bash
Expand Down
5 changes: 4 additions & 1 deletion aws-py-appsync/Pulumi.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
name: aws-py-appsync
runtime: python
runtime:
name: python
options:
virtualenv: venv
description: Basic example of defining an AWS AppSync endpoint from Pulumi in Python
template:
config:
Expand Down
11 changes: 0 additions & 11 deletions aws-py-appsync/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,6 @@ This example shows how to setup a basic GraphQL endpoint in AWS AppSync. The end
$ pulumi config set aws:region us-east-2
```

1. Create a Python virtualenv, activate it, and install dependencies:

This installs the dependent packages [needed](https://www.pulumi.com/docs/intro/concepts/how-pulumi-works/) for our Pulumi program.


```bash
$ python3 -m venv venv
$ source venv/bin/activate
$ pip3 install -r requirements.txt
```

1. Run `pulumi up` to preview and deploy changes:

```bash
Expand Down
14 changes: 2 additions & 12 deletions aws-py-assume-role/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,10 @@ resources.
You'll need to set the `create-role:unprivilegedUsername` configuration variable to the name of the unprivilged user, as
well as the AWS region in which to operate.

First, you need install dependencies. In this example we will install them in
a virtual environment named `venv`.
First, you need to create a new stack:

```bash
$ cd create-role
$ python3 -m venv venv
$ source venv/bin/activate
$ pip install -r requirements.txt
```

Now create a new stack:

```bash
$ pulumi stack init assume-role-create
$ pulumi config set create-role:unprivilegedUsername [email protected]
$ pulumi config set aws:region us-east-1
Expand Down Expand Up @@ -70,8 +61,7 @@ with the unprivileged user credentials created in Part 1. This can be configured
directory, replacing `{YOUR_STACK_PATH/assume-role-create}` with the full name of your stack from Part 1. Full name of your stack is available at [`app.pulumi.com`][app]

```bash
$ cd assume-role
$ npm install
$ cd ../assume-role
$ export AWS_ACCESS_KEY_ID="$(pulumi stack output --stack {YOUR_STACK_PATH/assume-role-create} accessKeyId)"
$ export AWS_SECRET_ACCESS_KEY="$(pulumi stack output --stack {YOUR_STACK_PATH/assume-role-create} --show-secrets secretAccessKey)"
```
Expand Down
5 changes: 4 additions & 1 deletion aws-py-assume-role/assume-role/Pulumi.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
name: assume-role
runtime: python
runtime:
name: python
options:
virtualenv: venv
description: Demonstrate use of AWS AssumeRole Functionality
5 changes: 4 additions & 1 deletion aws-py-assume-role/create-role/Pulumi.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
name: create-role
runtime: python
runtime:
name: python
options:
virtualenv: venv
description: Demonstrate use of AWS AssumeRole Functionality
10 changes: 0 additions & 10 deletions aws-py-dynamicresource/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,6 @@ A simple example demonstrating how to write Dynamic Providers using Pulumi.
$ pulumi config set sql-user-password <PASSWORD> --secret
```

1. Create a Python virtualenv, activate it, and install dependencies:

This installs the dependent packages [needed](https://www.pulumi.com/docs/intro/concepts/how-pulumi-works/) for our Pulumi program.

```bash
$ python3 -m venv venv
$ source venv/bin/activate
$ pip3 install -r requirements.txt
```

1. Run `pulumi up -y` to deploy changes:

```bash
Expand Down
5 changes: 4 additions & 1 deletion aws-py-ec2-provisioners/Pulumi.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
name: aws-py-ec2-provisioners
runtime: python
runtime:
name: python
options:
virtualenv: venv
description: An example of manually configuring an AWS EC2 virtual machine
8 changes: 0 additions & 8 deletions aws-py-ec2-provisioners/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,6 @@ https://github.com/pulumi/pulumi/issues/1691 tracks designing and developing a c

First, create a stack, using `pulumi stack init`.

Now, we need to ensure that our dependencies are installed:

```
$ python3 -m venv venv
$ source venv/bin/activate
$ pip3 install -r requirements.txt
```

Next, generate an OpenSSH keypair for use with your server - as per the AWS [Requirements][1]

```
Expand Down
5 changes: 4 additions & 1 deletion aws-py-eks/Pulumi.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
name: aws-py-eks
runtime: python
runtime:
name: python
options:
virtualenv: venv
description: A minimal AWS Python EKS example cluster
template:
config:
Expand Down
8 changes: 0 additions & 8 deletions aws-py-eks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,6 @@ To deploy your infrastructure, follow the below steps.

## Deploying and running the program

1. Install dependencies (a `virtualenv` is recommended - see [Pulumi Python docs](https://www.pulumi.com/docs/intro/languages/python/)):

```
$ virtualenv -p python3 venv
$ source venv/bin/activate
$ pip3 install -r requirements.txt
```

1. Create a new stack:

```
Expand Down
6 changes: 5 additions & 1 deletion aws-py-fargate/Pulumi.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
name: aws-py-fargate
description: A container running in AWS ECS Fargate, using Python infrastructure as code
runtime: python
runtime:
name: python
options:
virtualenv: venv

20 changes: 5 additions & 15 deletions aws-py-fargate/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,13 @@ Next, to deploy the application and its infrastructure, follow these steps:
$ pulumi stack init dev
```

2. Set your desired AWS region:
1. Set your desired AWS region:

```bash
$ pulumi config set aws:region us-east-1 # any valid AWS region will work
```

3. Create a Python virtualenv, activate it, and install dependencies:

This installs the dependent packages [needed](https://www.pulumi.com/docs/intro/concepts/how-pulumi-works/) for our Pulumi program.

```bash
$ python3 -m venv venv
$ source venv/bin/activate
$ pip3 install -r requirements.txt
```

4. Deploy everything with a single `pulumi up` command. This will show you a preview of changes first, which
1. Deploy everything with a single `pulumi up` command. This will show you a preview of changes first, which
includes all of the required AWS resources (clusters, services, and the like). Don't worry if it's more than
you expected -- this is one of the benefits of Pulumi, it configures everything so that so you don't need to!

Expand Down Expand Up @@ -77,7 +67,7 @@ Next, to deploy the application and its infrastructure, follow these steps:

Notice that the automatically assigned load-balancer URL is printed as a stack output.

5. At this point, your app is running -- let's curl it. The CLI makes it easy to grab the URL:
1. At this point, your app is running -- let's curl it. The CLI makes it easy to grab the URL:

```bash
$ curl http:https://$(pulumi stack output url)
Expand Down Expand Up @@ -110,7 +100,7 @@ Next, to deploy the application and its infrastructure, follow these steps:

**Please Note**: It may take a few minutes for the app to start up. Until that point, you may receive a 503 error response code.

6. Try making some changes, and rerunning `pulumi up`. For example, let's scale up to 3 instances:
1. Try making some changes, and rerunning `pulumi up`. For example, let's scale up to 3 instances:

Running `pulumi up` will show you the delta and then, after confirming, will deploy just those changes:

Expand Down Expand Up @@ -139,7 +129,7 @@ Next, to deploy the application and its infrastructure, follow these steps:
Permalink: https://app.pulumi.com/acmecorp/aws-python-fargate/dev/updates/2
```

7. Once you are done, you can destroy all of the resources, and the stack:
1. Once you are done, you can destroy all of the resources, and the stack:

```bash
$ pulumi destroy
Expand Down
7 changes: 5 additions & 2 deletions aws-py-resources/Pulumi.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
name: aws-py-resources
description: A Pulumi program that demonstrates creating various AWS resources in PYthon
runtime: python
description: A Pulumi program that demonstrates creating various AWS resources in Python
runtime:
name: python
options:
virtualenv: venv
template:
config:
aws:region:
Expand Down
5 changes: 0 additions & 5 deletions aws-py-resources/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ A Pulumi program that demonstrates creating various AWS resources in Python
$ pulumi stack init dev
$ pulumi config set aws:region us-east-2

# Install dependencies
$ python3 -m venv venv
$ source venv/bin/activate
$ pip3 install -r requirements.txt

# Preview and run the deployment
$ pulumi up

Expand Down
5 changes: 4 additions & 1 deletion aws-py-s3-folder/Pulumi.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
name: aws-py-s3-folder
runtime: python
runtime:
name: python
options:
virtualenv: venv
description: A minimal AWS Python Pulumi program
10 changes: 0 additions & 10 deletions aws-py-s3-folder/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,6 @@ with `***`.
$ pulumi config set aws:region us-west-2
```

1. Create a Python virtualenv, activate it, and install dependencies:

This installs the dependent packages [needed](https://www.pulumi.com/docs/intro/concepts/how-pulumi-works/) for our Pulumi program.

```bash
$ python3 -m venv venv
$ source venv/bin/activate
$ pip3 install -r requirements.txt
```

1. Run `pulumi up` to preview and deploy changes. After the preview is shown you will be
prompted if you want to continue or not.

Expand Down
5 changes: 4 additions & 1 deletion aws-py-serverless-raw/Pulumi.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
name: serverless-raw
runtime: python
runtime:
name: python
options:
virtualenv: venv
description: Basic example of a serverless AWS application
template:
config:
Expand Down
7 changes: 0 additions & 7 deletions aws-py-serverless-raw/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,6 @@ The Lambda function is a C# application using .NET Core 3.1 (a similar approach
AWS Lambda).

## Deploying and running the Pulumi App
1. Install dependencies. In this example we will install them in a virtual environment named `venv`.

```bash
$ python3 -m venv venv
$ source venv/bin/activate
$ pip install -r requirements.txt
```

1. Create a new stack:

Expand Down
44 changes: 0 additions & 44 deletions aws-py-stackreference/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,6 @@ stacks via [StackReference](https://www.pulumi.com/docs/intro/concepts/organizin
$ cd company
````

1. Create a Python virtualenv, activate it, and install dependencies:

This installs the dependent packages [needed](https://www.pulumi.com/docs/intro/concepts/how-pulumi-works/) for our Pulumi program.

```bash
$ python3 -m venv venv
$ source venv/bin/activate
$ pip3 install -r requirements.txt
```

1. Create a new stack:

```bash
Expand Down Expand Up @@ -70,26 +60,12 @@ stacks via [StackReference](https://www.pulumi.com/docs/intro/concepts/organizin
Permalink: https://app.pulumi.com/clstokes/aws-py-stackreference-company/dev/updates/1
```

1. Deactivate the virtual environment

```bash
$ deactivate
```

1. Change directory to `department` and install dependencies.

```bash
$ cd ../department
````

1. Create a Python virtualenv, activate it, and install dependencies:

```bash
$ python3 -m venv venv
$ source venv/bin/activate
$ pip3 install -r requirements.txt
```

1. Create a new stack:

```bash
Expand Down Expand Up @@ -131,26 +107,12 @@ stacks via [StackReference](https://www.pulumi.com/docs/intro/concepts/organizin
Permalink: https://app.pulumi.com/clstokes/aws-py-stackreference-department/dev/updates/1
```

1. Deactivate the virtual environment

```bash
$ deactivate
```

1. Change directory to `team` and install dependencies.

```bash
$ cd ../team
````

1. Create a Python virtualenv, activate it, and install dependencies:

```
$ python3 -m venv venv
$ source venv/bin/activate
$ pip3 install -r requirements.txt
```
1. Create a new stack:

```bash
Expand Down Expand Up @@ -207,12 +169,6 @@ stacks via [StackReference](https://www.pulumi.com/docs/intro/concepts/organizin
Permalink: https://app.pulumi.com/clstokes/aws-py-stackreference-team/dev/updates/1
```

1. Deactivate the virtual environment

```bash
$ deactivate
```

## Clean Up

1. Once you are done, destroy all of the resources and the stack. Repeat this in each
Expand Down
5 changes: 4 additions & 1 deletion aws-py-stackreference/company/Pulumi.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
name: aws-py-stackreference-company
runtime: python
runtime:
name: python
options:
virtualenv: venv
description: An AWS Python Pulumi program demonstrating sharing configuration
via StackReference resources
template:
Expand Down
Loading

0 comments on commit 4343550

Please sign in to comment.