|
2 | 2 |
|
3 | 3 | import pulumi
|
4 | 4 | import pulumi_aws as aws
|
5 |
| -import provisioners |
| 5 | +import pulumi_command as command |
6 | 6 | import base64
|
7 | 7 |
|
8 | 8 | # Get the config ready to go.
|
|
13 | 13 | key_name = config.get('keyName')
|
14 | 14 | public_key = config.get('publicKey')
|
15 | 15 |
|
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) |
19 | 17 | def decode_key(key):
|
20 |
| - |
21 | 18 | try:
|
22 | 19 | key = base64.b64decode(key.encode('ascii')).decode('ascii')
|
23 | 20 | except:
|
24 | 21 | pass
|
25 |
| - |
26 | 22 | if key.startswith('-----BEGIN RSA PRIVATE KEY-----'):
|
27 | 23 | return key
|
28 |
| - |
29 | 24 | return key.encode('ascii')
|
30 | 25 |
|
31 |
| - |
32 | 26 | private_key = config.require_secret('privateKey').apply(decode_key)
|
33 |
| -private_key_passphrase = config.get_secret('privateKeyPassphrase') |
34 | 27 |
|
35 | 28 | # Create a new security group that permits SSH and web access.
|
36 | 29 | secgrp = aws.ec2.SecurityGroup('secgrp',
|
@@ -62,29 +55,28 @@ def decode_key(key):
|
62 | 55 | key_name=key_name,
|
63 | 56 | vpc_security_group_ids=[ secgrp.id ],
|
64 | 57 | )
|
65 |
| -conn = provisioners.ConnectionArgs( |
| 58 | +connection = command.remote.ConnectionArgs( |
66 | 59 | host=server.public_ip,
|
67 |
| - username='ec2-user', |
| 60 | + user='ec2-user', |
68 | 61 | private_key=private_key,
|
69 |
| - private_key_passphrase=private_key_passphrase, |
70 | 62 | )
|
71 | 63 |
|
72 | 64 | # 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', |
77 | 69 | opts=pulumi.ResourceOptions(depends_on=[server]),
|
78 | 70 | )
|
79 | 71 |
|
80 | 72 | # 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', |
84 | 76 | opts=pulumi.ResourceOptions(depends_on=[cp_config]),
|
85 | 77 | )
|
86 | 78 |
|
87 | 79 | # Export the server's IP/host and stdout from the command.
|
88 | 80 | pulumi.export('publicIp', server.public_ip)
|
89 | 81 | pulumi.export('publicHostName', server.public_dns)
|
90 |
| -pulumi.export('catConfigStdout', cat_config.results[0]['stdout']) |
| 82 | +pulumi.export('catConfigStdout', cat_config.stdout) |
0 commit comments