Skip to content

Commit aed0e7a

Browse files
author
Luke Hoban
authored
Update provisioners examples to use Command package (#1141)
1 parent 856a8f2 commit aed0e7a

File tree

22 files changed

+112
-1005
lines changed

22 files changed

+112
-1005
lines changed

aws-py-ec2-provisioners/README.md

+2-11
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
# AWS WebServer with Manual Provisioning (in Python)
22

3-
This demonstrates using Pulumi dynamic providers to accomplish post-provisioning configuration steps.
3+
This demonstrates using the [`pulumi_command`](https://www.pulumi.com/registry/packages/command/) package to accomplish post-provisioning configuration steps.
44

55
Using these building blocks, one can accomplish much of the same as Terraform provisioners.
66

7-
https://github.com/pulumi/pulumi/issues/1691 tracks designing and developing a complete replacement for provisioners.
8-
97
## Running the Example
108

119
First, create a stack, using `pulumi stack init`.
@@ -26,14 +24,7 @@ $ cat rsa.pub | pulumi config set publicKey --
2624
$ cat rsa | pulumi config set privateKey --secret --
2725
```
2826

29-
If your key is protected by a passphrase, add that too:
30-
31-
```
32-
$ pulumi config set privateKeyPassphrase --secret [yourPassphraseHere]
33-
```
34-
35-
Notice that we've used `--secret` for both `privateKey` and `privateKeyPassphrase`. This ensures their are
36-
stored in encrypted form in the Pulumi secrets system.
27+
Notice that we've used `--secret` for `privateKey`. This ensures their are stored in encrypted form in the Pulumi secrets system.
3728

3829
Also set your desired AWS region:
3930

aws-py-ec2-provisioners/__main__.py

+12-20
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import pulumi
44
import pulumi_aws as aws
5-
import provisioners
5+
import pulumi_command as command
66
import base64
77

88
# Get the config ready to go.
@@ -13,24 +13,17 @@
1313
key_name = config.get('keyName')
1414
public_key = config.get('publicKey')
1515

16-
17-
# The privateKey associated with the selected key must be provided (either directly or base64 encoded),
18-
# along with an optional passphrase if needed.
16+
# The privateKey associated with the selected key must be provided (either directly or base64 encoded)
1917
def decode_key(key):
20-
2118
try:
2219
key = base64.b64decode(key.encode('ascii')).decode('ascii')
2320
except:
2421
pass
25-
2622
if key.startswith('-----BEGIN RSA PRIVATE KEY-----'):
2723
return key
28-
2924
return key.encode('ascii')
3025

31-
3226
private_key = config.require_secret('privateKey').apply(decode_key)
33-
private_key_passphrase = config.get_secret('privateKeyPassphrase')
3427

3528
# Create a new security group that permits SSH and web access.
3629
secgrp = aws.ec2.SecurityGroup('secgrp',
@@ -62,29 +55,28 @@ def decode_key(key):
6255
key_name=key_name,
6356
vpc_security_group_ids=[ secgrp.id ],
6457
)
65-
conn = provisioners.ConnectionArgs(
58+
connection = command.remote.ConnectionArgs(
6659
host=server.public_ip,
67-
username='ec2-user',
60+
user='ec2-user',
6861
private_key=private_key,
69-
private_key_passphrase=private_key_passphrase,
7062
)
7163

7264
# Copy a config file to our server.
73-
cp_config = provisioners.CopyFile('config',
74-
conn=conn,
75-
src='myapp.conf',
76-
dest='myapp.conf',
65+
cp_config = command.remote.CopyFile('config',
66+
connection=connection,
67+
local_path='myapp.conf',
68+
remote_path='myapp.conf',
7769
opts=pulumi.ResourceOptions(depends_on=[server]),
7870
)
7971

8072
# Execute a basic command on our server.
81-
cat_config = provisioners.RemoteExec('cat-config',
82-
conn=conn,
83-
commands=['cat myapp.conf'],
73+
cat_config = command.remote.Command('cat-config',
74+
connection=connection,
75+
create='cat myapp.conf',
8476
opts=pulumi.ResourceOptions(depends_on=[cp_config]),
8577
)
8678

8779
# Export the server's IP/host and stdout from the command.
8880
pulumi.export('publicIp', server.public_ip)
8981
pulumi.export('publicHostName', server.public_dns)
90-
pulumi.export('catConfigStdout', cat_config.results[0]['stdout'])
82+
pulumi.export('catConfigStdout', cat_config.stdout)

aws-py-ec2-provisioners/provisioners.py

-188
This file was deleted.
+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
pulumi>=3.5.1,<4.0.0
22
pulumi-aws>=4.0.0,<5.0.0
3-
paramiko>=2.7.1
4-
typing_extensions>=3.7.4
3+
pulumi-command>=0.0.3

aws-ts-ec2-provisioners/README.md

+2-11
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
# AWS WebServer with Manual Provisioning
22

3-
This demonstrates using Pulumi dynamic providers to accomplish post-provisioning configuration steps.
3+
This demonstrates using the [`@pulumi/command`](https://www.pulumi.com/registry/packages/command/) package to accomplish post-provisioning configuration steps.
44

55
Using these building blocks, one can accomplish much of the same as Terraform provisioners.
66

7-
https://github.com/pulumi/pulumi/issues/1691 tracks designing and developing a complete replacement for provisioners.
8-
97
## Running the Example
108

119
First, create a stack, using `pulumi stack init`.
@@ -32,14 +30,7 @@ $ cat rsa.pub | pulumi config set publicKey --
3230
$ cat rsa | pulumi config set privateKey --secret --
3331
```
3432

35-
If your key is protected by a passphrase, add that too:
36-
37-
```
38-
$ pulumi config set privateKeyPassphrase --secret [yourPassphraseHere]
39-
```
40-
41-
Notice that we've used `--secret` for both `privateKey` and `privateKeyPassphrase`. This ensures their are
42-
stored in encrypted form in the Pulumi secrets system.
33+
Notice that we've used `--secret` for `privateKey`. This ensures their are stored in encrypted form in the Pulumi secrets system.
4334

4435
Also set your desired AWS region:
4536

0 commit comments

Comments
 (0)